This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
LD bug
- To: "'binutils at sources dot redhat dot com'" <binutils at sources dot redhat dot com>
- Subject: LD bug
- From: "Slegers, Walter" <Walter dot Slegers at nl2 dot vdogrp dot de>
- Date: Tue, 2 Jan 2001 08:16:51 +0100
LD Bug report
From:
Walter.Slegers@nl2.vdogrp.de
Synopsis:
LD bug, relocation records referring to symbols from discarded
duplicate sections are broken.
Version:
ld-version 2.9 (with BFD 2.9)
gcc-version 2.95.2 19991024 (release)
Environment:
HOST: PC, Redhat 6.1
TARGET: MIPS TX39 (mipstx39-unknown-elf)
Summary:
Problem in LD. When we create relocatable output files containing
duplicate sections for a MIPS then the relocation records that refer to
symbols in the duplicate sections become relocation records to absolute
symbols. So we can't relocate anymore.
Full description:
We use a GCC MIPS compiler for an R3000 MIPS derivative without an
MMU. To be able to load and relocate files we convert elf files into a so
called flat file format (which originated from micro linux). To create a
flat file from an elf file we need the relocation records, hence we instruct
the linker to generate a relocatable (object) file instead of a
non-relocatable executable, using the -r option.
When we compile c++ sources with the gnu compiler (g++) then it
might have to compile a c++ header file with an inline method. If the
compiler can't inline the method (e.g. it uses a variable number of
arguments) then it generates a new section with the code for this method.
This small section has an elf flag "LINK_ONCE_DISCARD". Meaning, if the
linker detects multiple occurrences of this section it should throw away all
duplicates. This prevents the 'inline' method and its symbol from occurring
multiple times in the final executable.
A combination of the above has a side effect. Any reference to the
'inline' method (e.g. from a virtual function table) has a relocation
record. The relocation records refers to a symbol and hence to the symbol's
section. This section could be a duplicate and so it might have been
removed! The GNU linker sets the section for duplicates to absolute.
This prevents the section from being written, but if also causes the
relocations to refer to absolute symbols. The linker doesn't produce and
error or warning messages.
Our compiler and binutils were downloaded from
http://sourceware.cygnus.com/ecos/tools/linux-mips-tx39-elf.html
but I get the same problem with the binutils that came with my
redhat 6.1 distribution (bintuils-2.9.1.0.23).
The bintutils were configured with:
configure --target=mipstx39-unknown-elf
How-to-repeat:
Attached are a few very small source files that create a duplicate
section causing the problem to appear. The final elf (object) file is called
test and it contains a relocation records to "$LFB2" which has become an
absolute symbol.
Fix:
The linker 'removes' sections by setting their output_section to the
absolute section. I've made a simple patch that sets the output section of
the duplicate to the ouput section of the first occurance.
In ld/ldlang.c, in the routine 'section_already_linked' near the end
change
sec->output_section = bfd_abs_section_ptr;
into
sec->output_section = l->sec->output_section;
This patch causes the relocation records for the duplicate sections
to be written correctly. A side effect of this patch is that the duplicate
sections are included in the final 'executable'. The duplicates are appended
to the first occurrence of the section.
Attached file:
<<ld_bug.tar.gz>>
Kind regards,
Walter Slegers
-----------------------------------------------------------
This Mail has been checked for Viruses
Attention: Encrypted Mails can NOT be checked !
***
Diese Mail wurde auf Viren ueberprueft
Hinweis: Verschluesselte Mails koennen NICHT geprueft werden!
------------------------------------------------------------
ld_bug.tar.gz