Script/Tool predicate for ARM ELF compiled for Thumb OR Arm

前端 未结 2 818
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 10:25

I have rootfs and klibc file systems. I am creating make rules and some developers have an older compiler without inter-netwo

2条回答
  •  既然无缘
    2020-12-11 10:40

    The readelf -A output doesn't describe the elf contents. It just describes the capabilities of the processor and or system that is expected or feed to the compiler. As I have an ARM926 CPU which is an ARMV5TEJ processor, gcc/ld will always set Tag_THUMB_ISA_use: Thumb-1 as it just means that ARMV5TEJ is recognized as being Thumb-1 capable. It says nothing about the code itself.

    Examining the Linux arch/arm/kernel/elf.c routine elf_check_arch() shows a check for x->e_entry & 1. This leads to the following script,

    readelf -h $1 | grep -q Entry.*[13579bdf]$
    

    Ie, just look at the initial ELF entry value and see if the low bit is set. This is a fast check that fits the spirit of what I am looking for. unixsmurf has a good point that the code inside any ELF can mix and match ARM and Thumb. This maybe ok, if the program dynamically ids the CPU and selects an appropriate routine. Ie, just the presence of a Thumb instruction doesn't mean that code will execute.

    Just looking at the entry value does determine which gcc compiler flags were used, at least for gcc versions 4.6 to 4.7.

提交回复
热议问题