While I was working on u-boot for MIPS arch, I encountered a problem referencing old symbol location after relocation. This is because global symbol table didn't get updated after relocation.
In the ARM arch, the table (in ".rel.dyn" section) is updated in relocation logic. So, I'd like to do the same thing for MIPS, but the elf image created didn't have .rel.dyn section.
The magic behind the creation of .rel.dyn is "-pie" option of ld.
ld -pie man page
-pie
--pic-executable
Create a position independent executable. This is currently only supported on ELF platforms. Position independent executables are similar to shared libraries in that they are relocated by the dynamic linker to the virtual address the OS chooses for them (which can vary between invocations). Like normal dynamically linked executables they can be executed and symbols defined in the executable cannot be overridden by shared libraries.
readelf u-boot
arm-none-linux-gnueabi-readelf -h u-boot
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x80000000
Start of program headers: 52 (bytes into file)
Start of section headers: 1202632 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 26
Section header string table index: 23
justin@Juhyun_Desktop:~/managed/u-boot$ /utils/gcc/4.5.2/codesourcery/arm/bin/arm-none-linux-gnueabi-objdump -f u-boot
u-boot: file format elf32-littlearm
architecture: arm, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x80000000
---------------------------------------------
arm-none-linux-gnueabi-readelf -S u-boot
There are 26 section headers, starting at offset 0x1259c8:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 80000000 008000 03c07c 00 AX 0 0 32
[ 2] .rodata PROGBITS 8003c07c 04407c 00cd89 00 A 0 0 4
[ 3] .hash HASH 80048e08 050e08 000044 04 A 9 0 4
[ 4] .ARM.exidx ARM_EXIDX 80048e4c 050e4c 000010 00 AL 1 0 4
[ 5] .data PROGBITS 80048e5c 050e5c 002600 00 WA 0 0 4
[ 6] .got.plt PROGBITS 8004b45c 05345c 00000c 04 WA 0 0 4
[ 7] .u_boot_cmd PROGBITS 8004b468 053468 00078c 00 WA 0 0 4
[ 8] .rel.dyn REL 8004bbf4 053bf4 007228 08 A 9 0 4
[ 9] .dynsym DYNSYM 80052e1c 05ae1c 0000c0 10 A 0 3 4
[10] .bss NOBITS 8004bbf4 000000 048be0 00 WA 0 0 32
[11] .ARM.attributes ARM_ATTRIBUTES 00000000 05aedc 000027 00 0 0 1
[12] .comment PROGBITS 00000000 05af03 00002a 01 MS 0 0 1
[13] .debug_line PROGBITS 00000000 05af2d 011587 00 0 0 1
[14] .debug_info PROGBITS 00000000 06c4b4 04abef 00 0 0 1
[15] .debug_abbrev PROGBITS 00000000 0b70a3 00f094 00 0 0 1
[16] .debug_aranges PROGBITS 00000000 0c6138 000ea0 00 0 0 8
[17] .debug_pubnames PROGBITS 00000000 0c6fd8 005045 00 0 0 1
[18] .debug_frame PROGBITS 00000000 0cc020 007e58 00 0 0 4
[19] .debug_str PROGBITS 00000000 0d3e78 00e30f 01 MS 0 0 1
[20] .debug_loc PROGBITS 00000000 0e2187 03ca8c 00 0 0 1
[21] .debug_pubtypes PROGBITS 00000000 11ec13 004d1a 00 0 0 1
[22] .debug_ranges PROGBITS 00000000 12392d 001f90 00 0 0 1
[23] .shstrtab STRTAB 00000000 1258bd 00010a 00 0 0 1
[24] .symtab SYMTAB 00000000 125dd8 00e450 10 25 2625 4
[25] .strtab STRTAB 00000000 134228 006962 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
References