I am writing some custom ELF binary postprocessing code which works on .o
files. Part of the processing includes performing relocation on the binary data. The input files are generated by the GNU assembler from my own assembly code.
Look at these crazy relocations which the GNU assembler generated:
Relocation section '.rel.bss' at offset 0x3b8 contains 2 entries:
Offset Info Type Sym.Value Sym. Name
0000010b 00000301 R_386_32 00000000 .bss
00000110 00000301 R_386_32 00000000 .bss
First of all, it doesn't make any sense to relocate data in .bss
. By definition, the data in .bss
is all zeroes and cannot be adjusted to become something else.
Second of all, it doesn't make any sense to relocate values relative to the base address of their own section. That would be a no-op.
So what gives?? What are these relocations supposed to mean?
(The asm code which went into this binary contains something like:
.bss
keybuffer:
.space 256
...and later:
.bss
anotherbuffer:
.space 4
That is where the offsets you can see above came from.)
readelf -r
output, you can see that there are relocations for BSS, and the "symbol value" which the (non-existent) pointers in BSS are relocated relative to is byte 0 of BSS = the base address of BSS. - Alex D.text
section? - ninjalj