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]

SEC_NEVER_LOAD cleanup


This gets rid of SEC_NEVER_LOAD in ELF code, curing these failures:

arc-elf/check.log1:FAIL: ld-elf/noload-3
d30v-elf/check.log1:FAIL: ld-elf/noload-3
dlx-elf/check.log1:FAIL: ld-elf/noload-3
i960-elf/check.log1:FAIL: ld-elf/noload-3
or32-elf/check.log1:FAIL: ld-elf/noload-3
pj-elf/check.log1:FAIL: ld-elf/noload-3

The patch also makes the testcase in
http://sourceware.org/ml/binutils/2000-01/msg00084.html produce a
SHT_NOBITS section for .klog rather than SHT_PROGBITS.

I spent quite a lot of time going through changes related to
SEC_NEVER_LOAD.  Testcases in various bug reports behave reasonably
after this patch, and I think the COFF support should work too but I'm
less sure of this since I don't have any reason to use COFF/ECOFF/PE
myself.

If you go searching on the web you'll find more than one freely
available COFF standard that says of STYP_NOLOAD:

"STYP_NOLOAD	0x02	Noload section (allocated, relocated, not loaded)"

and also of .bss

"A deviation from the norm in the section header table is the entry
for uninitialized data in a .bss section. A .bss section has a size
and symbols that refer to it, and symbols defined in it. At the same
time, a .bss section has no relocation entries, line number entries,
or data. Therefore, a .bss section has an entry in the section header
table but does not occupy space elsewhere in the file. In this case,
the number of relocation and line number entries, as well as all file
pointers, are 0. The same is true of the STYP_NOLOAD and STYP_DSECT
sections."

>From that I think we can conclude that STYP_NOLOAD ought to behave
much like a .bss section.  So should SEC_NEVER_LOAD, since I believe
STYP_NOLOAD was the inspiration for the BFD SEC_NEVER_LOAD flag and
NOLOAD in linker scripts.  In fact, contrary to our ld docs, NOLOAD in
linker scripts has always given something like a .bss section, except
that the COFF backend does some weird things for
SEC_COFF_SHARED_LIBARAY.

The only thing I'm not too sure about is why STYP_NOLOAD is marked as
"relocated", which seems to be a contradiction with the .bss blurb.
If there is a good reason why these sections should be relocated when
their contents are discarded, I'll need to revise this patch.

bfd/
	* elf.c (bfd_elf_get_default_section_type): Don't test SEC_NEVER_LOAD.
	* elflink.c (elf_link_input_bfd): Likewise.
ld/
	* ld.texinfo (NOLOAD): Do not erroneously state that contents will
	appear in output file.
	* ldlang.c (lang_add_section): Clear SEC_HAS_CONTENTS on noload
	unless SEC_COFF_SHARED_LIBRARY.
	(map_input_to_output_sections): Don't set SEC_HAS_CONTENTS for noload
	output sections.
	(lang_size_sections_1): Don't test SEC_NEVER_LOAD when deciding
	to update dot in region.  Ditto when setting SEC_ALLOC if dot
	advanced due to assignment.
	* ldwrite.c (build_link_order): Don't test SEC_NEVER_LOAD.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.519
diff -u -p -r1.519 elf.c
--- bfd/elf.c	9 Sep 2010 19:22:27 -0000	1.519
+++ bfd/elf.c	15 Sep 2010 02:34:50 -0000
@@ -2452,8 +2452,7 @@ int
 bfd_elf_get_default_section_type (flagword flags)
 {
   if ((flags & SEC_ALLOC) != 0
-      && ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0
-	  || (flags & SEC_NEVER_LOAD) != 0))
+      && (flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
     return SHT_NOBITS;
   return SHT_PROGBITS;
 }
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.378
diff -u -p -r1.378 elflink.c
--- bfd/elflink.c	9 Sep 2010 09:55:03 -0000	1.378
+++ bfd/elflink.c	15 Sep 2010 02:35:00 -0000
@@ -9843,7 +9843,6 @@ elf_link_input_bfd (struct elf_final_lin
 	  {
 	    /* FIXME: octets_per_byte.  */
 	    if (! (o->flags & SEC_EXCLUDE)
-		&& ! (o->output_section->flags & SEC_NEVER_LOAD)
 		&& ! bfd_set_section_contents (output_bfd, o->output_section,
 					       contents,
 					       (file_ptr) o->output_offset,
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.263
diff -u -p -r1.263 ld.texinfo
--- ld/ld.texinfo	31 Aug 2010 10:26:11 -0000	1.263
+++ ld/ld.texinfo	15 Sep 2010 23:14:27 -0000
@@ -4290,8 +4290,7 @@ The linker normally sets the attributes 
 the input sections which map into it.  You can override this by using
 the section type.  For example, in the script sample below, the
 @samp{ROM} section is addressed at memory location @samp{0} and does not
-need to be loaded when the program is run.  The contents of the
-@samp{ROM} section will appear in the linker output file as usual.
+need to be loaded when the program is run.
 @smallexample
 @group
 SECTIONS @{
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.339
diff -u -p -r1.339 ldlang.c
--- ld/ldlang.c	10 Sep 2010 01:23:12 -0000	1.339
+++ ld/ldlang.c	15 Sep 2010 23:42:10 -0000
@@ -2245,6 +2245,8 @@ lang_add_section (lang_statement_list_ty
     case noload_section:
       flags &= ~SEC_LOAD;
       flags |= SEC_NEVER_LOAD;
+      if ((flags & SEC_COFF_SHARED_LIBRARY) == 0)
+	flags &= ~SEC_HAS_CONTENTS;
       break;
     }
 
@@ -3479,8 +3481,8 @@ map_input_to_output_sections
 	  /* Make sure that any sections mentioned in the expression
 	     are initialized.  */
 	  exp_init_os (s->data_statement.exp);
-	  /* The output section gets CONTENTS, and usually ALLOC and
-	     LOAD, but the latter two may be overridden by the script.  */
+	  /* The output section gets CONTENTS, ALLOC and LOAD, but
+	     these may be overridden by the script.  */
 	  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD;
 	  switch (os->sectype)
 	    {
@@ -3491,7 +3493,7 @@ map_input_to_output_sections
 	      flags = SEC_HAS_CONTENTS;
 	      break;
 	    case noload_section:
-	      flags = SEC_HAS_CONTENTS | SEC_NEVER_LOAD;
+	      flags = SEC_NEVER_LOAD;
 	      break;
 	    }
 	  if (os->bfd_section == NULL)
@@ -4979,14 +4981,9 @@ lang_size_sections_1
 	    /* Update dot in the region ?
 	       We only do this if the section is going to be allocated,
 	       since unallocated sections do not contribute to the region's
-	       overall size in memory.
-
-	       If the SEC_NEVER_LOAD bit is not set, it will affect the
-	       addresses of sections after it. We have to update
-	       dot.  */
+	       overall size in memory.  */
 	    if (os->region != NULL
-		&& ((os->bfd_section->flags & SEC_NEVER_LOAD) == 0
-		    || (os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD))))
+		&& (os->bfd_section->flags & (SEC_ALLOC | SEC_LOAD)))
 	      {
 		os->region->current = dot;
 
@@ -5172,8 +5169,8 @@ lang_size_sections_1
 		    /* If dot is advanced, this implies that the section
 		       should have space allocated to it, unless the
 		       user has explicitly stated that the section
-		       should never be loaded.  */
-		    if (!(output_section_statement->flags & SEC_NEVER_LOAD))
+		       should not be allocated.  */
+		    if (output_section_statement->sectype != noalloc_section)
 		      output_section_statement->bfd_section->flags |= SEC_ALLOC;
 		  }
 		dot = newdot;
Index: ld/ldwrite.c
===================================================================
RCS file: /cvs/src/src/ld/ldwrite.c,v
retrieving revision 1.30
diff -u -p -r1.30 ldwrite.c
--- ld/ldwrite.c	7 Sep 2010 15:01:56 -0000	1.30
+++ ld/ldwrite.c	15 Sep 2010 02:35:41 -0000
@@ -276,10 +276,9 @@ build_link_order (lang_statement_union_t
 	output_section = statement->padding_statement.output_section;
 	ASSERT (statement->padding_statement.output_section->owner
 		== link_info.output_bfd);
-	if (((output_section->flags & SEC_HAS_CONTENTS) != 0
-	     || ((output_section->flags & SEC_LOAD) != 0
-		 && (output_section->flags & SEC_THREAD_LOCAL)))
-	    && (output_section->flags & SEC_NEVER_LOAD) == 0)
+	if ((output_section->flags & SEC_HAS_CONTENTS) != 0
+	    || ((output_section->flags & SEC_LOAD) != 0
+		&& (output_section->flags & SEC_THREAD_LOCAL)))
 	  {
 	    link_order = bfd_new_link_order (link_info.output_bfd,
 					     output_section);

-- 
Alan Modra
Australia Development Lab, IBM


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