Position-independent linker script symbols

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When compiling the following code (test.c):

extern void __text_start__;
int main()
{
return (int)&__text_start__;
}

...with the following invocations (gcc 4.4.2):
gcc -fpie -fmessage-length=0 -mcpu=arm7tdmi-s -mthumb-interwork -mlittle-endian -mfpu=vfp -mfloat-abi=soft -nostdinc -quiet -O1
  -fno-builtin test.c -o temp.

as --traditional-format -mcpu=arm7tdmi-s -mthumb-interwork -EL -mfpu=vfp -mfloat-abi=soft temp. -o test.o

ld -pie -X -nostdlib --omagic --fatal-warnings -EL -Tlink.ld -Map test.map -u_vectors -o test.elf --start-group test.o

(__text_start__ is declared in the linker script to be the start of the .text section)

The following code is produced:
a0000000 <main>:
a0000000: e59f300c  ldr r3, [pc, #12] ; a0000014 <__rodata_start__+0x14>
a0000004: e08f3003  add r3, pc, r3
a0000008: e59f2008  ldr r2, [pc, #8] ; a0000018 <__rodata_start__+0x18>
a000000c: e7930002  ldr r0, [r3, r2]
a0000010: e12fff1e  bx lr
a0000014: 00000010  .word 0x00000010
a0000018: 00000000  .word 0x00000000

As I understand, this will return 0, instead of the expected 0xA0000000. If I remove the position-independent options from the compiler and linker, the following code is generated:


a0000000 <main>:
a0000000: e59f0000  ldr r0, [pc, #0] ; a0000008 <main+0x8>
a0000004: e12fff1e  bx lr
a0000008: a0000000  .word 0xa0000000

which returns the expected 0xA0000000. If position-independence is used, can I not reference symbols defined in the linker script? Thank for you any help.

Luke Trowbridge
Electrodata Inc.
www.electrodata.com






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux