This is sources Bugzilla
Bugzilla Version 2.17.5
Bugzilla Bug 349
  ld -r silently renames sections Last modified: 2009-10-14 02:29
     Query page      Enter new bug
Bug#: 349   Hardware:   Reporter: Jan Beulich <jbeulich@novell.com>
Host: Target: Build:
Product:     Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: RESOLVED   Priority:  
Resolution: FIXED   Severity:  
Assigned To: unassigned@sources.redhat.com   Target Milestone:  
Summary:
Keywords:

Attachment Description Type Created Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 349 depends on: Show dependency tree
Show dependency graph
Bug 349 blocks:

Additional Comments:


Leave as RESOLVED FIXED
Reopen bug
Mark bug as VERIFIED

View Bug Activity   |   Format For Printing


Description:   Last confirmed: 0000-00-00 00:00 Opened: 2004-08-27 14:06
Encountering two input sections with different allocation flags but identical
names, ld renames the second one encountered by attaching a .<number> suffix.
While the ELF spec isn't really explicit about this, it would have been my
understanding that an ELF section is uniquely identified by {name,type,flags}
rather than just by its name. At the very least I'd expect ld to be able to
optionally issue a warning to the user that this happened (especially when -r is
in effect), because (for instance) linker scripts subsequently used to deal with
the resulting output may deal only with the un-renamed sections unless the
programmer(s) learn(s) that it needs to deal with more.

The problematic code is ld/emultempl/elf32.em, function
gld${EMULATION_NAME}_place_orphan calling bfd_get_unique_section_name.

And a response to this I got on the mailing list from Ian Lance Taylor:

Oh yeah.  I think this code may be buggy.  It was intended to handle
the case in which an input section was orphaned even though the output
section exists.  That can happen if, for example, the output section
is created by the linker for whatever reason.

However, the way the code is written, if two orphaned input sections
have the same name, the second one will get a unique output section
name.  Really they should both go into the same output section (if the
flags are compatible).  That is, the test should not be unconditional
on whether an output section exists with the same name.  Perhaps we
should test SEC_LINKER_CREATED, if that is used consistently.

You are correct that in the case of incompatible flags, or
SEC_LINKER_CREATED, the linker should arguably create a new section
with the same name and the appropriate flags.  This is where we may
run into trouble with the way that linker scripts base everything
purely on the section name.  On the other hand, it may work fine, as
place_orphan sets up the appropriate links directly.

------- Additional Comment #1 From Alan Modra 2004-10-11 06:06 -------
Ian's comment isn't exactly right.  Current ld behaviour is as he says it should
be, that is, two orphan sections with the same name and compatible flags will be
linked to the same output section.  Since I also think current ld behaviour is
correct, I'm closing this bug report.

------- Additional Comment #2 From Jan Beulich 2004-10-11 06:57 -------
Note the difference between the original description and your response: The
original text is talking about a difference in allocation flags (one section has
the SHF_ALLOC flag set, the other [identically named in another object file]
doesn't), while you're talking about compatible flags (which these aren't).
The thing is that current behavior results in entirely different behavior when,
using in both cases the same linker script mentioning the questionable section,
(a) linking the original object files into an executable and (b) combining the
original object files into intermediate object files and only then linking those
into an executable. I continue to believe that in these two scenarios the
outcome should be the same, requiring that the linker does not rename one of the
two input sections when using -r.

------- Additional Comment #3 From Alan Modra 2004-10-11 09:38 -------
I understand your original description, and still think current ld  behaviour is
correct.

Many people seem to think that "ld -r" can be used much like "ar" to package a
group of objects together, and that the resultant object will link into a final
executable to produce the same result as if the original objects were directly
linked.  This is *not* true in general.

------- Additional Comment #4 From Jan Beulich 2004-10-11 11:38 -------
I can't judge whether or under what conditions this might not be true, but I
can't immediately see why it wouldn't be.
Independent of that, (silently) renaming a section seems unacceptable to me. The
more that in ELF one doesn't even have to, since sections are not solely
identified by their name, but instead the pair (name, flags) serves as the full
identification. Thus I believe that not only the renaming is a problem in ld,
but also the combining of what you call compatible sections (instead, if names
match but flags are different, two output sections should be generated).

------- Additional Comment #5 From Alan Modra 2004-10-12 04:34 -------
http://sources.redhat.com/ml/binutils/2004-10/msg00178.html

It might be reasonable to change ld -r so that an attempt to combine two input
sections with incompatible flags results in two output sections of the same name.

------- Additional Comment #6 From Alan Modra 2009-10-14 02:29 -------
Fixed in 2.20

     Query page      Enter new bug
Actions: New | Query | bug # | Reports | Requests   New Account | Log In