This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
question about linker scripts
- To: binutils at sources dot redhat dot com
- Subject: question about linker scripts
- From: Jim Blandy <jimb at zwingli dot cygnus dot com>
- Date: Wed, 17 Oct 2001 17:23:42 -0500 (EST)
I've read the LD manual's description of the difference between
.foo : {
*(.foo)
*(.bar)
}
and
.foo : {
*(.foo .bar)
}
in a linker script's SECTIONS command, but the linker doesn't seem to
behave as I expect.
When I compile gcc/testsuite/g++.old-deja/g++.mike/eh53.C (shown at
bottom), I get a .o file with the following sections:
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000040 00000000 00000000 00000040 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 00000080 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000080 2**0
ALLOC
3 .debug_loc 00000000 00000000 00000000 00000080 2**0
CONTENTS, READONLY, DEBUGGING
4 .debug_abbrev 000000f1 00000000 00000000 00000080 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_info 000001b5 00000000 00000000 00000171 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
6 .debug_line 0000006f 00000000 00000000 00000326 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
7 .gnu.linkonce.t._ZN7zerosetD1Ev 00000030 00000000 00000000 000003a0 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE, LINK_ONCE_DISCARD
8 .eh_frame 00000048 00000000 00000000 000003d0 2**2
CONTENTS, ALLOC, LOAD, RELOC, DATA
9 .debug_pubnames 00000031 00000000 00000000 00000418 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
10 .debug_aranges 00000028 00000000 00000000 00000449 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
11 .comment 0000001b 00000000 00000000 00000471 2**0
CONTENTS, READONLY
The text here is divided between several sections: `.text' holds the
code for `main', and `.gnu.linkonce.t._ZN7zerosetD1Ev' holds the code
for the destructor for `class zeroset'.
My linker script is generated from the generic ld/scripttempl/elf.sc,
whose relevant section reads as follows:
.text ${RELOCATING-0} :
{
${RELOCATING+${TEXT_START_SYMBOLS}}
*(.text)
${RELOCATING+*(.text.*)}
*(.stub)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
${RELOCATING+*(.gnu.linkonce.t.*)}
${RELOCATING+${OTHER_TEXT_SECTIONS}}
} =${NOP-0}
When I link in the usual way, I get an executable where main appears
at one address, followed by a lot of stuff from libraries, and finally
the stuff from eh53.o's .gnu.linkonce.* section.
When I change ld/scripttempl/elf.sc to read as follows:
.text ${RELOCATING-0} :
{
${RELOCATING+${TEXT_START_SYMBOLS}}
*(.text ${RELOCATING+.gnu.linkonce.t.*})
${RELOCATING+*(.text.*)}
*(.stub)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
${RELOCATING+${OTHER_TEXT_SECTIONS}}
} =${NOP-0}
I expect to see eh53.o's .text and .gnu.linkonce.t.* sections appear
contiguously in the executable file. However, this doesn't happen; I
still get the machine code for `main', followed by various library
routines, and finally the code for `class zeroset''s destructor, from
.gnu.linkonce.t._ZN7zerosetD1Ev.
I've verified that the linker scripts installed in lib/ldscripts read
as intended:
.text :
{
*(.text .gnu.linkonce.t.*)
*(.text.*)
*(.stub)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
} =0
and that the linker scripts incorporated in the `ld' executable are
also changed.
Is this an ld bug, or am I doing something wrong?
Here's the code of my test program:
// Special g++ Options: -fexceptions -g
// excess errors test - XFAIL a29k-*-* sparc64-*-elf arm-*-pe
class zeroset {
public:
~zeroset () { }
};
int main () {
zeroset a;
try {
;
} catch( zeroset ) {
}
}