This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: ld changing section names with attr "a" (ALLOC)
Hi Atul,
"GNU ld version 2.13.1" Cross-compiled for MIPS on x86.
First off, when reporting bugs, please use the latest release of
binutils (which in this case is 2.15) or, even better, the current
sources in the CVS repository.
As it happens this bug is present in the current sources as well, but it
is always best to use the most up-to-date sources that you can.
[3] mips-elf-ld --section-start .new_section=0x8000 test.o -o
test_cmdline.exe
I case of command [3] I see that linker adds the suffix ".1"
to the my new section name:
(and does *not* place it at the address I want)
Well strictly speaking it does place a section called .new.section at
address 0x8000, it is just that this section does not have the contents
(or attributes) of .new.section from the test.o input file. Instead
these are given to a newly created new.section.1.
The problem is a bug in the place_orphans() function which assumes that
since the .new.section in the test.o input file was not named in the
linker map it will have to create a section in the output file to hold
its contents. It tries to create a section called .new.section but
discovers that the linker has already created a section by this name.
So it assumes that the linker did not use this section because a
mismatch in the section's attributes and so it goes on to create a brand
new section name .new.section.1.
The patch below resolves this problem by teaching the place_orphan
function that it is OK to use a section name that already exists
provided that that section does not have any flags set. Such a section
will have been created by the linker in response to a --section-start
switch.
Cheers
Nick
ld/ChangeLog
2004-07-23 Nick Clifton <nickc@redhat.com>
* emultempl/elf32.em (_place_orphan): Use an already existing
section name if that section does not have any flags set.
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.119
diff -c -3 -p -r1.119 elf32.em
*** ld/emultempl/elf32.em 19 Jul 2004 16:40:52 -0000 1.119
--- ld/emultempl/elf32.em 23 Jul 2004 16:19:01 -0000
*************** gld${EMULATION_NAME}_place_orphan (lang_
*** 1175,1182 ****
--- 1175,1184 ----
lang_statement_union_type **os_tail;
etree_type *load_base;
int isdyn = 0;
+ asection *sec;
secname = bfd_get_section_name (s->owner, s);
+
if (! link_info.relocatable
&& link_info.combreloc
&& (s->flags & SEC_ALLOC)
*************** gld${EMULATION_NAME}_place_orphan (lang_
*** 1260,1267 ****
/* Choose a unique name for the section. This will be needed if the
same section name appears in the input file with different
! loadable or allocatable characteristics. */
! if (bfd_get_section_by_name (output_bfd, secname) != NULL)
{
secname = bfd_get_unique_section_name (output_bfd, secname, &count);
if (secname == NULL)
--- 1262,1273 ----
/* Choose a unique name for the section. This will be needed if the
same section name appears in the input file with different
! loadable or allocatable characteristics. But if the section
! already exists but does not have any flags set, then it has been
! been created by the linker, probably as a result of a --section-start
! command line switch. */
! if ((sec = bfd_get_section_by_name (output_bfd, secname)) != NULL
! && bfd_get_section_flags (output_bfd, sec) != 0)
{
secname = bfd_get_unique_section_name (output_bfd, secname, &count);
if (secname == NULL)