This is the mail archive of the binutils@sourceware.org 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: ld maps sections without consider memory region?


Hi Masaki,

But I have a new question.
I couldn't determine if this is my misunderstanding.

Using script-warn.ld with my test case, ld (applied your patch) shows an warning like this.
- mips64-elf-ld: a.out: warning: allocated section `.begin' \
- not in segmentThanks for your patch.
But using script-no-warn.ld in same environment, there is no warning.
I can't see why the warning is suppressed by defining HDR1 because it looks HDR1 is never used by any sections.

Oh this was a good one to track down. What is happening is this:


  If program headers are not specified in a linker script then the
  linker allows the BFD library to create a section-to-segment map
  and everything works as expected.

  If program headers are specified in a linker script then the linker
  walks over the list of headers checking to make sure that they are
  OK.  As a side effect of this it also remembers the last program
  header that it encounters and assigns this to sections that do not
  have a explicit segment associated with them.

  But - the code tries to be clever and combine these two things into
  one loop.  (See lang_record_phdrs() in ld/ldlang.c).  The practical
  result of this is that if there is only 1 program header then any
  sections which do not have a segment assigned to them before the first
  explicit mention of a program header will be left unassigned.  Whereas
  if there are 2 or more program headers then any section that misses
  out on a segment assignment when the first header is processed will
  receive an assignment when the second header is processed.

Anyway the attached patch should take care of this inconsistency. Let me know what you think.

Cheers
  Nick




Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.251
diff -c -3 -p -r1.251 ldlang.c
*** ld/ldlang.c	21 Feb 2007 16:43:50 -0000	1.251
--- ld/ldlang.c	21 Feb 2007 18:29:34 -0000
*************** lang_record_phdrs (void)
*** 6234,6240 ****
  		  || os->bfd_section == NULL
  		  || (os->bfd_section->flags & SEC_ALLOC) == 0)
  		continue;
! 	      pl = last;
  	    }
  
  	  if (os->bfd_section == NULL)
--- 6234,6259 ----
  		  || os->bfd_section == NULL
  		  || (os->bfd_section->flags & SEC_ALLOC) == 0)
  		continue;
! 
! 	      if (last)
! 		pl = last;
! 	      else
! 		{
! 		  lang_output_section_statement_type * tmp_os;
! 
! 		  /* If we have not run across a section with a program
! 		     header assigned to it yet, then scan forwards to find
! 		     one.  This prevents inconsistencies in the linker's
! 		     behaviour when a script has specified just a single
! 		     header and there are sections in that script which are
! 		     not assigned to it, and which occur before the first
! 		     use of that header. See here for more details:
! 		     http://sourceware.org/ml/binutils/2007-02/msg00291.html  */
! 		  for (tmp_os = os; tmp_os; tmp_os = tmp_os->next)
! 		    if (tmp_os->phdrs)
! 		      break;
! 		  pl = tmp_os->phdrs;
! 		}
  	    }
  
  	  if (os->bfd_section == NULL)

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