arm-linux-gnueabi 编译器选项 [英] arm-linux-gnueabi compiler options
问题描述
我正在使用 arm-linux-gnueabi-gcc 在 Linux 中为 ARM 处理器编译 C 程序.但是,我不确定它编译的默认 ARM 模式是什么.
I am using, arm-linux-gnueabi-gcc to compile C programs for ARM processor in Linux. However, I am not sure what is the default ARM mode for which it compiles.
例如,对于 C 代码:
For example, for the C code:
test.c
unsigned int main()
{
return 0x1ffff;
}
arm-linux-gnueabi-gcc -o test test.c
现在,当我用 objdump 查看 main() 函数的反汇编时,我可以看到:
now, when I look at the disassembly of main() function with objdump, I can see:
arm-linux-gnueabi-objdump -d test
<main>:
push {r7}
add r7, sp, #0
movw r3, #65535 ; 0xffff
movt r3, #1
mov r0, r3
mov sp, r7
pop {r7}
bx lr
看来这是ARM的Thumb模式的反汇编(因为push指令).
it appears that this is disassembly for Thumb mode of ARM (because of the push instruction).
如何显示反汇编如下:
.sect ".text"
.global _fn
_fn: MOVW A1,#65535
MOVT A1,#1
BX LR
或者这个
.sect ".text"
.global _fn
_fn: LDR A1, CON1
BX LR
.sect ".text"
.align 4
CON1: .word 0x1ffff
我在这里看到了这个例子:
I saw this example here:
http://e2e.ti.com/support/development_tools/compiler/f/343/t/40580.aspx
但是,我无法以那里显示的方式查看反汇编.
however, I am unable to view the disassembly the way it is displayed there.
谢谢.
推荐答案
push 不一定会告诉您它处于拇指模式,实际上 ARM 的新汇编语法称为 统一汇编语言
这意味着在大多数情况下您可以将相同的代码编译为 arm
或 thumb-2
指令集.
push doesn't necessarily tell you it is in thumb mode, in fact ARM's new assembly syntax called unified assembly language
which means in most of the cases you can compile same code to arm
or thumb-2
instruction sets.
另一个问题是,您在 -O0
模式下编译,这增加了一些额外的指令以方便调试.试试 -O2
,你应该得到你想要的指令流程.
Other problem is that, you are compiling in -O0
mode which adds some extra instructions for easy of debugability. Try -O2
and you should get the instruction flow you want.
gcc
和 -v
开关,如 arm-linux-gnueabi-gcc -v
应该向你展示它是如何构建的,这也告诉您编译源代码时它使用的总体默认选项.
gcc
with -v
switch as in arm-linux-gnueabi-gcc -v
should show you how it is built, which also tells you the overall default options it uses when compiling your source code.
最后一件事,您提到的目标汇编序列使用 ATPCS
寄存器命名方案(检查 objdump doc 信息),例如它使用 a1
而不是 r0
.您也可以通过使用 -M
开关在 objdump
中设置 disassembler-options
来获得它.如下图;
One last thing, targeted assembly sequence you mentioned uses ATPCS
register naming scheme (check objdump doc for information), it uses a1
instead of r0
for example. You can also get this by setting disassembler-options
in objdump
with -M
switch. Like below;
$ arm-linux-gnueabihf-gcc -c -O2 -o test test.c
$ arm-linux-gnueabihf-objdump -M reg-names-special-atpcs -d test
test: file format elf32-littlearm
Disassembly of section .text.startup:
00000000 <main>:
0: f64f 70ff movw a1, #65535 ; 0xffff
4: f2c0 0001 movt a1, #1
8: 4770 bx LR
a: bf00 nop
另一种选择是使用 -S
开关从 gcc
本身获取汇编输出.如下图;
Another option is to get assembly output from gcc
itself by using -S
switch. Like below;
$ arm-linux-gnueabihf-gcc -S test.c
那么你应该在同一个文件夹中得到一个名为 test.s
的新文件.不过不知道有没有设置寄存器命名的选项.
then you should get a new file called test.s
in the same folder. However I don't know if there is an option for you to set the register naming.
这篇关于arm-linux-gnueabi 编译器选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!