arm-linux-gnueabi编译器选项 [英] arm-linux-gnueabi compiler options
问题描述
我正在使用 arm-linux-gnueabi-gcc 来为Linux中的ARM处理器编译C程序。但是,我不确定它编译的默认ARM模式是什么。
例如,对于C代码:
test.c
unsigned int main()
{
return 0x1ffff;
}
arm-linux-gnueabi-gcc -o test test.c
现在,当我看着用objdump反汇编main()函数时,我可以看到:
arm -linux-gnueabi-objdump -d测试
< 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模式的反汇编(因为推送指令)。
如何显示反汇编如下:
.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
我在这里看到这个例子:
http://e2e.ti.com/support/development_tools/compiler/f/343/ t / 40580.aspx
然而,我无法查看反汇编的显示方式
谢谢。
push 并不一定告诉你它是在缩略模式下,实际上ARM是新的汇编语法,称为统一汇编语言
,这意味着在大多数情况下,您可以将相同的代码编译为 arm
或 thumb-2
指令集。
其他问题是,您正在编译 -O0
模式,它增加了一些额外的指令以方便调试。试试 -O2
,你应该得到你想要的指令流。
gcc code>>
-v
切换到 arm-linux-gnueabi-gcc -v
应该告诉你如何它是建立的,它也告诉你它在编译源代码时使用的整体默认选项。
最后一件事,你提到的目标装配顺序使用 ATPCS
注册命名方案(检查 objdump文档信息),例如,它使用 a1
而不是 r0
。您还可以通过在 objdump
中设置 disassembler-options
来获得 -M
开关。如下所示;
$ arm-linux-gnueabihf-gcc -c -O2 -o test test.c
$ arm-linux-gnueabihf-objdump -M reg -name-special-atpcs -d测试
测试:文件格式elf32-littlearm
反汇编段落。 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
本身获得程序集输出。如下所示;
$ arm-linux-gnueabihf-gcc -S test.c
那么你应该在同一个文件夹中得到一个叫做 test.s
的新文件。但是我不知道是否有一个选项可以设置寄存器命名。
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.
For example, for the C code:
test.c
unsigned int main()
{
return 0x1ffff;
}
arm-linux-gnueabi-gcc -o test test.c
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
it appears that this is disassembly for Thumb mode of ARM (because of the push instruction).
How can I display the disassembly as follows:
.sect ".text"
.global _fn
_fn: MOVW A1,#65535
MOVT A1,#1
BX LR
or this
.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.
Thanks.
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.
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
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.
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
Another option is to get assembly output from gcc
itself by using -S
switch. Like below;
$ arm-linux-gnueabihf-gcc -S test.c
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屋!