On Fri, Jun 21, 2013 at 8:17 PM, Shawn <shaolin.xie@ia.ac.cn> wrote:
I'm trying to link the object files compiled by LLVM using GOLD , but
found the "SECTION SYMBOL" have been stripped in the ELF file, for example:
=================================================
= This is the object file with the "SECTION SYMBOL"
[xiesl@aurora-hp AGUTest]$ readelf -s app.s.o
Symbol table '.symtab' contains 5 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 SECTION LOCAL DEFAULT 1
2: 00000000 0 SECTION LOCAL DEFAULT 2
3: 00000000 0 SECTION LOCAL DEFAULT 3
4: 00000010 0 NOTYPE GLOBAL DEFAULT 1 _start
=================================================
= This is the executable file without the "SECTION SYMBOL"
[xiesl@aurora-hp AGUTest]$ /home/xiesl/tools/mapu-llvm/bin/ld.gold -T
Script.ld app.s.o -o app.s.out
[xiesl@aurora-hp AGUTest]$ readelf -s app.s.out
Symbol table '.symtab' contains 3 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000010 0 NOTYPE GLOBAL DEFAULT 1 _start
2: 00040000 0 NOTYPE GLOBAL DEFAULT ABS STACK_POINTER
=================================================
= This is the link script
[xiesl@aurora-hp AGUTest]$ cat Script.ld
MEMORY {
RAM : ORIGIN = 0x0, LENGTH = 0x40000
}
/* All text code & data are in IM */
SECTIONS {
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss ) }
}
/* The Stack Pointer */
STACK_POINTER = 0x40000;
=================================================
What can I do to preserve the "SECTION SYMBOL" in the output file ? Do I
need to modify the source code of gold?
When producing an executable, all ELF linkers discard the section
symbols in the input files. Otherwise you would have one section
symbol per input file, and that does not make sense. The only
question is the set of section symbols that the linker should emit in
the executable. The gold linker by default only emits section symbols
that are required (e.g., for a dynamic relocation) which often means
that no section symbols are emitted. There is no way to tell gold
that you want the section symbols.
Why do you want the section symbols?
If you want to change gold to always emit section symbols, change the
Output_section::Output_section constructor so that it initializes
needs_symtab_index_ to true.
Ian