This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Bug when generating Program Header in elf files
- To: thomas dot petazzoni at meridon dot com
- Subject: Re: Bug when generating Program Header in elf files
- From: Nick Clifton <nickc at cambridge dot redhat dot com>
- Date: 12 Jun 2001 15:06:36 +0100
- Cc: binutils at sourceware dot cygnus dot com
- References: <3B13C9C9.AA9D6A2B@meridon.com>
Hi Thomas,
As you have discovered this problem happens because your linker
script did not explicitly assign .rodata sections in the input files
to a section in the output file.
The algorithm used to decide where to place these unallocated
sections (called 'orphan sections') changed with binutils 2.11, so
that were being placed at the start of file rather than the end of
the file, and this meant a second (correctly specified) program
header was needed.
Although you have already solved the problem by fixing your linker
script, you may also want to try the patch below, which changes the
orphan placement algorithm slitghtly so that unallocates .rodata
sections will now be attached to the .data section.
Cheers
Nick
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.48
diff -p -r1.48 elf32.em
*** elf32.em 2001/05/25 05:39:22 1.48
--- elf32.em 2001/06/12 14:04:20
*************** gld${EMULATION_NAME}_place_orphan (file,
*** 1097,1105 ****
&& (hold_rel.os != NULL
|| (hold_rel.os = output_rel_find ()) != NULL))
place = &hold_rel;
! else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY
! && HAVE_SECTION (hold_rodata, ".rodata"))
! place = &hold_rodata;
else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY)
&& hold_text.os != NULL)
place = &hold_text;
--- 1097,1111 ----
&& (hold_rel.os != NULL
|| (hold_rel.os = output_rel_find ()) != NULL))
place = &hold_rel;
! else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY)
! {
! if (HAVE_SECTION (hold_rodata, ".rodata"))
! place = &hold_rodata;
! /* If the script does not provide a .rodata
! section try using the .data section instead. */
! else if (HAVE_SECTION (hold_data, ".data"))
! place = &hold_data;
! }
else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY)
&& hold_text.os != NULL)
place = &hold_text;