为 Thumb OR Arm 编译的 ARM ELF 的脚本/工具谓词 [英] Script/Tool predicate for ARM ELF compiled for Thumb OR Arm

查看:25
本文介绍了为 Thumb OR Arm 编译的 ARM ELF 的脚本/工具谓词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 rootfsklibc 文件系统.我正在创建 make 规则,并且一些开发人员的编译器较旧,没有网络间连接.note1 我正在尝试验证所有文件是否都是使用 arm 仅当检测到某个版本的编译器时.我已经多次重建这棵树.我正在使用 readelf -A 并寻找 Tag_THUMB_ISA_use: Thumb-1,但这似乎是 arm 唯一的代码(但它是用互通编译器)以及 thumb 代码.我可以手动运行 objdump -S 并检查汇编程序以确定正在使用的指令集.

但是,如果我有一个脚本/工具谓词,那么 find 等可以用来搜索 shadow 文件系统来查找,那就容易多了可能遗漏的二进制文件.我认为其中一些信息会在 ELF 标头中并可通过 objdumpreadelf 访问,但我没有找到任何可靠的信息.

特别是我正在寻找,

  1. 编译的C"如果没有 CONFIG_ARM_THUMB Linux 系统就无法运行.
  2. make 使用C"编译器标志的规则会阻塞非拇指编译器.

注意1:互通允许在thumbarm 模式之间轻松切换,编译器将自动生成代码以支持从任一模式调用.

解决方案

readelf -A 输出没有描述 elf 的内容.它只是描述了处理器 和/或系统 预期或提供给编译器的功能.由于我有一个 ARM926 CPU,它是一个 ARMV5TEJ 处理器,gcc/ld 将始终设置 Tag_THUMB_ISA_use: Thumb-1 因为它只是意味着 ARMV5TEJ 被认为具有 Thumb-1 能力.它没有说明代码本身.

检查 Linux arch/arm/kernel/elf.c 例程 elf_check_arch() 显示对 x->e_entry & 的检查1.这导致了以下脚本,

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

即,只需查看初始 ELF 条目值,看看是否设置了低位.这是一个符合我正在寻找的精神的快速检查.unixsmurf 有一个很好的观点,即任何 ELF 中的代码都可以混合搭配 ARM拇指.这可能没问题,如果程序动态ids CPU 并选择适当的例程.即,仅存在 Thumb 指令并不意味着代码会执行.

仅查看 entry 值就可以确定使用了哪些 gcc 编译器标志,至少对于 gcc 版本 4.6 到 4.7.

I have rootfs and klibc file systems. I am creating make rules and some developers have an older compiler without inter-networking.note1 I am trying to verify that all the files get built with arm only when a certain version of the compiler is detected. I have re-built the tree's several times. I was using readelf -A and looking for Tag_THUMB_ISA_use: Thumb-1, but this seem to be in arm only code (but was built with the interworking compiler) as well as thumb code. I can manually run objdump -S and examine the assembler to determine what instruction set is in use.

However, it would be much easier if I had a script/tool predicate so that find, etc can be used to search through the shadow file systems to look for binaries that may have been missed. I thought that some of this information would be in the ELF header and accessible via objdump or readelf, but I haven't found anything reliable.

Specifically I am looking for,

  1. Compiled 'C' that wouldn't run without a CONFIG_ARM_THUMB Linux system.
  2. make rules that use 'C' compiler flags that choke a non-thumb compilers.

note1: Interworking allow easy switching between thumb and arm modes, and the compiler will automatically generate code to support calling from either mode.

解决方案

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.

这篇关于为 Thumb OR Arm 编译的 ARM ELF 的脚本/工具谓词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆