This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bad behavior with explicit phdrs and loadable orphans


Hi David,

> When explicit PHDRs and memory regions are used with orphan input
> sections, the default placement of these sections can generate either
> very large files or a SEEK overflow.

Note - your problem could also be overcome by fixing the linker script
to provide a better definition for the memory regions.  For example in
your script if you change:

> MEMORY
> {
>    normal_seg : ORIGIN = 0xd0000000, LENGTH = 0x10000
> }

To:

  MEMORY
  {
     normal_seg (wax) : ORIGIN = 0xd0000000, LENGTH = 0x10000
  }

The link will work.  But anyway, this is only a workaround, not a full
solution.
 
An alternative is the patch below will also work.  It "fixes"
lang_memory_default() so that if a memory region does not have any
flags set, then it will accept any input section.  This seems to be a
better interpretation of how a memory region without attributes is
supposed to behave.


> This behavior seems a little extreme for misnaming a loadable
> section, but I'm not sure what a good solution would be.  The ld
> orphan placement algorithm seems to be looking for a good place to
> put the section in the emulation statements.  Perhaps it just needs
> to look for a good memory region while placing an orphan as well.
> Alternatively, when explicit PHDRS are used, the linker could do a
> better job of placing the default memory section so that it was
> reasonably contiguous with an existing PHDR.   Or perhaps orphan
> loadable sections should generate an error when using explicit PHDRs
> before the attempt is made to build a multi-gigabyte file.

I think that the linker ought to try to be a little bit better about
choosing memory regions for orphan sections.  Ideally it ought to
attempt to discover if the section it has chosen to inherit the orphan
has a memory region associated with it, and if so, use that region.
(Assuming that there is room of course).

Let me know what you think

Cheers
        Nick

2003-04-24  Nick Clifton  <nickc at redhat dot com>

	* ldlang.c (lang_memory_default): If a region has not
	attributes do not check for matching section flags.
        * ld.texinfo: Document that a region without attributes will
	accept any input section.

Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.111
diff -c -3 -p -w -r1.111 ldlang.c
*** ld/ldlang.c	31 Mar 2003 18:12:52 -0000	1.111
--- ld/ldlang.c	24 Apr 2003 14:08:39 -0000
*************** lang_memory_default (section)
*** 736,746 ****
         p != (lang_memory_region_type *) NULL;
         p = p->next)
      {
!       if ((p->flags & sec_flags) != 0
! 	  && (p->not_flags & sec_flags) == 0)
! 	{
  	  return p;
- 	}
      }
    return lang_memory_region_lookup ("*default*");
  }
--- 736,746 ----
         p != (lang_memory_region_type *) NULL;
         p = p->next)
      {
!       /* Only check for a positive match if the region has attributes set.  */
!       if (p->flags && ((p->flags & sec_flags) == 0))
! 	continue;
!       if ((p->not_flags & sec_flags) == 0)
  	return p;
      }
    return lang_memory_region_lookup ("*default*");
  }

Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.93
diff -c -3 -p -w -r1.93 ld.texinfo
*** ld/ld.texinfo	15 Apr 2003 08:51:54 -0000	1.93
--- ld/ld.texinfo	24 Apr 2003 14:08:56 -0000
*************** If a unmapped section matches any of the
*** 3563,3569 ****
  @samp{!}, it will be placed in the memory region.  The @samp{!}
  attribute reverses this test, so that an unmapped section will be placed
  in the memory region only if it does not match any of the listed
! attributes.
  
  @kindex ORIGIN =
  @kindex o =
--- 3563,3570 ----
  @samp{!}, it will be placed in the memory region.  The @samp{!}
  attribute reverses this test, so that an unmapped section will be placed
  in the memory region only if it does not match any of the listed
! attributes.  If not attributes are specified then the region will
! accept any input section.
  
  @kindex ORIGIN =
  @kindex o =


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]