链接描述文件中OUTPUT_ARCH(arm)和OUTPUT_ARCH(armv4)之间的区别

时间:2016-10-17 15:14:31

标签: c gcc arm embedded ld

除其他事项外,我试图了解 OUTPUT_ARCH(arm) OUTPUT_ARCH(armv4)之间的区别。

假设我们有下一个文件(我使用here中的链接描述文件作为基础):

main.c:

int main(void)
{
    test_1();
    test_2();
    return 0;
}


main.lds:

OUTPUT_ARCH(arm)
SECTIONS
{
    . = 0x10000;
    .text : { *(.text) }
    . = 0x8000000;
    .data : { *(.data) }
    .bss : { *(.bss) }
}


test_1.c:

void test_1(void)
{
    return;
}


test_2.c:

void test_2(void)
{
    return;
}

如果我们编译它并转储它的内容我们接下来:

c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe test_1.c -c

c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe test_2.c -c

c:\SysGCC\arm-elf\bin>arm-elf-objdump.exe -x test_1.o

test_1.o:     file format elf32-littlearm
test_1.o
architecture: arm, flags 0x00000010:
HAS_SYMS
start address 0x00000000
private flags = 200: [APCS-32] [FPA float format] [software FP]

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000014  00000000  00000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000048  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000048  2**0
                  ALLOC
  3 .comment      00000012  00000000  00000000  00000048  2**0
                  CONTENTS, READONLY
  4 .ARM.attributes 00000010  00000000  00000000  0000005a  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test_1.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .ARM.attributes        00000000 .ARM.attributes
00000000 g     F .text  00000014 test_1

c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe -static -nostartfiles -T main.lds -o main.elf test_1.o test_2.o

c:\SysGCC\arm-elf\bin>arm-elf-objdump.exe -x main.elf

main.elf:     file format elf32-littlearm
main.elf
architecture: arm, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00010000

Program Header:
    LOAD off    0x00008000 vaddr 0x00010000 paddr 0x00010000 align 2**15
         filesz 0x00000028 memsz 0x00000028 flags r-x
private flags = 200: [APCS-32] [FPA float format] [software FP]

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000028  00010000  00010000  00008000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .comment      00000011  00000000  00000000  00008028  2**0
                  CONTENTS, READONLY
  2 .ARM.attributes 00000010  00000000  00000000  00008039  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00010000 l    d  .text  00000000 .text
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .ARM.attributes        00000000 .ARM.attributes
00000000 l    df *ABS*  00000000 test_1.c
00000000 l    df *ABS*  00000000 test_2.c
00010014 g     F .text  00000014 test_2
00010000 g     F .text  00000014 test_1

但如果我将 OUTPUT_ARCH(arm)更改为 OUTPUT_ARCH(armv4),我会从链接器收到错误:

c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe -static -nostartfiles -T main.lds -o main.elf test_1.o test_2.o
c:/sysgcc/arm-elf/bin/../lib/gcc/arm-elf/4.6.3/../../../../arm-elf/bin/ld.exe: error: test_1.o uses software FP, whereas main.elf uses hardware FP
c:/sysgcc/arm-elf/bin/../lib/gcc/arm-elf/4.6.3/../../../../arm-elf/bin/ld.exe: failed to merge target specific data of file test_1.o
c:/sysgcc/arm-elf/bin/../lib/gcc/arm-elf/4.6.3/../../../../arm-elf/bin/ld.exe: error: test_2.o uses software FP, whereas main.elf uses hardware FP
c:/sysgcc/arm-elf/bin/../lib/gcc/arm-elf/4.6.3/../../../../arm-elf/bin/ld.exe: failed to merge target specific data of file test_2.o
collect2: ld returned 1 exit status

可以通过指定 -mfloat-abi = hard 选项来修复它。在这种情况下,与以前的输出相比,私有标志存在差异:

c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe -mfloat-abi=hard test_1.c -c

c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe -mfloat-abi=hard test_2.c -c

c:\SysGCC\arm-elf\bin>arm-elf-objdump.exe -x test_1.o

test_1.o:     file format elf32-littlearm
test_1.o
architecture: arm, flags 0x00000010:
HAS_SYMS
start address 0x00000000
private flags = 0: [APCS-32] [FPA float format]

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000014  00000000  00000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000048  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000048  2**0
                  ALLOC
  3 .comment      00000012  00000000  00000000  00000048  2**0
                  CONTENTS, READONLY
  4 .ARM.attributes 00000010  00000000  00000000  0000005a  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test_1.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .ARM.attributes        00000000 .ARM.attributes
00000000 g     F .text  00000014 test_1



c:\SysGCC\arm-elf\bin>arm-elf-gcc.exe -static -nostartfiles -T main.lds -o main.elf test_1.o test_2.o

c:\SysGCC\arm-elf\bin>arm-elf-objdump.exe -x main.elf

main.elf:     file format elf32-littlearm
main.elf
architecture: arm, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00010000

Program Header:
    LOAD off    0x00008000 vaddr 0x00010000 paddr 0x00010000 align 2**15
         filesz 0x00000028 memsz 0x00000028 flags r-x
private flags = 0: [APCS-32] [FPA float format]

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000028  00010000  00010000  00008000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .comment      00000011  00000000  00000000  00008028  2**0
                  CONTENTS, READONLY
  2 .ARM.attributes 00000010  00000000  00000000  00008039  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00010000 l    d  .text  00000000 .text
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .ARM.attributes        00000000 .ARM.attributes
00000000 l    df *ABS*  00000000 test_1.c
00000000 l    df *ABS*  00000000 test_2.c
00010014 g     F .text  00000014 test_2
00010000 g     F .text  00000014 test_1

这是否意味着 OUTPUT_ARCH(armv4)导致链接器仅为硬浮点生成输出?

一般来说, OUTPUT_ARCH(arm) OUTPUT_ARCH(armv4)之间有什么区别?

根据ld manual OUTPUT_ARCH()指定特定的输出机器架构。

参数是BFD库使用的名称之一。

但除了一般信息之外,我没有找到关于BFD库的明确信息。

我使用来自here的arm-elf工具链(Binutils 2.22,GCC 4.6.3,Newlib 1.2.0,GDB 7.4)。

提前感谢您的帮助。

更新1:

此更新是对以下评论的回复。

我们现在使用的旧工具链的编译器-v输出:

Using built-in specs.
Target: arm-elf
Configured with: ../gcc-4.4.1/configure --target=arm-elf --host=i686-pc-mingw32 --with-cpu=xscale --without-stabs -nfp --prefix=/c/cross-gcc/4.4.1 --disable-nls --disable-shared --disable-__cxa_atexit
 --enable-threads --with-gnu-gcc --with-gnu-ld --with-gnu-as --with-dwarf2 --enable-languages=c,c++ --enable-interwork --disable-multilib --with-gmp=/c/cross-gcc/4.4.1 --with-mpfr=/c/cross-gcc/4.4.1 -
-with-newlib --with-headers=../../newlib-1.17.0/newlib-1.17.0/newlib/libc/include --disable-libssp --disable-libstdcxx-pch --disable-libmudflap --disable-libgomp -v
Thread model: single
gcc version 4.4.1 (GCC)

我在示例中使用的较新工具链的编译器-v输出(SysGCC arm-elf):

Using built-in specs.
COLLECT_GCC=arm-elf-gcc.exe
COLLECT_LTO_WRAPPER=c:/sysgcc/arm-elf/bin/../libexec/gcc/arm-elf/4.6.3/lto-wrapper.exe
Target: arm-elf
Configured with: ../gcc-4.6.3/configure --target arm-elf --enable-win32-registry=SysGCC-arm-elf-4.6.3 --prefix /c/gnu/auto/bu-2.22+gcc-4.6.3+gmp-4.2.4+mpfr-2.4.1+mpc-0.8+newlib-1.20.0-arm-elf/ --enabl
e-languages=c,c++ --disable-nls --with-newlib --with-headers=../newlib-1.20.0/newlib/libc/include --enable-interwork --enable-multilib --with-float=soft
Thread model: single
gcc version 4.6.3 (GCC)

旧编译器的 OUTPUT_ARCH(arm) OUTPUT_ARCH(armv4)的链接器输出没有区别。我想我应该先检查一下。 似乎这是对这个问题的回答。

我的目标是使用组合-mfpu=vfpv3 -mfloat-abi=hard,但根据Debian documentationGCC 4.4.7 manual,GCC 4.4不支持此组合。

实际上,如果我尝试使用旧编译器使用-mfpu=vfpv3 -mfloat-abi=hard进行编译,则会返回错误:

sorry, unimplemented: -mfloat-abi=hard and VFP

仍然可以将-mfpu=vfpv3 -mfloat-abi=softfp与旧编译器一起使用,但根据this comparison,它为小例程提供了很大的开销。

0 个答案:

没有答案