public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* SEC_NEVER_LOAD cleanup
@ 2010-09-16  0:03 Alan Modra
  2010-10-15 20:31 ` Dave Korn
  0 siblings, 1 reply; 23+ messages in thread
From: Alan Modra @ 2010-09-16  0:03 UTC (permalink / raw)
  To: binutils

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-09-16  0:03 SEC_NEVER_LOAD cleanup Alan Modra
@ 2010-10-15 20:31 ` Dave Korn
  2010-10-15 20:36   ` Kai Tietz
  2010-10-16  2:36   ` Alan Modra
  0 siblings, 2 replies; 23+ messages in thread
From: Dave Korn @ 2010-10-15 20:31 UTC (permalink / raw)
  To: binutils; +Cc: Alan Modra


    Hi Alan,

On 16/09/2010 01:03, Alan Modra wrote:
> This gets rid of SEC_NEVER_LOAD in ELF code, curing these failures:

> 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.

> 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.

  This patch causes a failure building the cygwin dll:

> GNU ld (GNU Binutils) 2.20.51.20100916
> Creating library file: cygdll.a
> /gnu/binutils/git.repo/obj/ld/.libs/ld-new: BFD (GNU Binutils) 2.20.51.20100916
> assertion fail /gnu/binutils/git.repo/binutils/bfd/linker.c:2678
> /gnu/binutils/git.repo/obj/ld/.libs/ld-new: final link failed: Section has no contents

  Which appears to be from here:

> static bfd_boolean
> default_data_link_order (bfd *abfd,
> 			 struct bfd_link_info *info ATTRIBUTE_UNUSED,
> 			 asection *sec,
> 			 struct bfd_link_order *link_order)
> {
>   bfd_size_type size;
>   size_t fill_size;
>   bfd_byte *fill;
>   file_ptr loc;
>   bfd_boolean result;
> 
>   BFD_ASSERT ((sec->flags & SEC_HAS_CONTENTS) != 0);

  That's triggered by the ".gnu_debuglink_overlay" section.  It has flags =
512 - SEC_NEVER_LOAD is set and nothing else.  It's getting added to the link
via a bit of custom linker script in the cygwin dll build system that looks
like so:

>   .gnu_debuglink_overlay ALIGN(__section_alignment__) (NOLOAD):
>   {
>     BYTE(0)	/* c */
>     BYTE(0)	/* y */
>     BYTE(0)	/* g */
>     BYTE(0)	/* w */
>     BYTE(0)	/* i */
>     BYTE(0)	/* n */
>     BYTE(0)	/* 1 */
>     BYTE(0)	/* . */
>     BYTE(0)	/* d */
>     BYTE(0)	/* b */
>     BYTE(0)	/* g */
>     BYTE(0)	/* \0 */
>     LONG(0)	/* checksum */
>   }

  I think (haven't checked yet) that this looks like a consequence of the
ldlang.c changes.  Any thoughts on how to fix it?

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-15 20:31 ` Dave Korn
@ 2010-10-15 20:36   ` Kai Tietz
  2010-10-15 22:27     ` Dave Korn
  2010-10-16  2:36   ` Alan Modra
  1 sibling, 1 reply; 23+ messages in thread
From: Kai Tietz @ 2010-10-15 20:36 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils, Alan Modra

2010/10/15 Dave Korn <dave.korn.cygwin@gmail.com>:
>
>    Hi Alan,
>
> On 16/09/2010 01:03, Alan Modra wrote:
>> This gets rid of SEC_NEVER_LOAD in ELF code, curing these failures:
>
>> 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.
>
>> 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.
>
>  This patch causes a failure building the cygwin dll:
>
>> GNU ld (GNU Binutils) 2.20.51.20100916
>> Creating library file: cygdll.a
>> /gnu/binutils/git.repo/obj/ld/.libs/ld-new: BFD (GNU Binutils) 2.20.51.20100916
>> assertion fail /gnu/binutils/git.repo/binutils/bfd/linker.c:2678
>> /gnu/binutils/git.repo/obj/ld/.libs/ld-new: final link failed: Section has no contents
>
>  Which appears to be from here:
>
>> static bfd_boolean
>> default_data_link_order (bfd *abfd,
>>                        struct bfd_link_info *info ATTRIBUTE_UNUSED,
>>                        asection *sec,
>>                        struct bfd_link_order *link_order)
>> {
>>   bfd_size_type size;
>>   size_t fill_size;
>>   bfd_byte *fill;
>>   file_ptr loc;
>>   bfd_boolean result;
>>
>>   BFD_ASSERT ((sec->flags & SEC_HAS_CONTENTS) != 0);
>
>  That's triggered by the ".gnu_debuglink_overlay" section.  It has flags =
> 512 - SEC_NEVER_LOAD is set and nothing else.  It's getting added to the link
> via a bit of custom linker script in the cygwin dll build system that looks
> like so:
>
>>   .gnu_debuglink_overlay ALIGN(__section_alignment__) (NOLOAD):
>>   {
>>     BYTE(0)   /* c */
>>     BYTE(0)   /* y */
>>     BYTE(0)   /* g */
>>     BYTE(0)   /* w */
>>     BYTE(0)   /* i */
>>     BYTE(0)   /* n */
>>     BYTE(0)   /* 1 */
>>     BYTE(0)   /* . */
>>     BYTE(0)   /* d */
>>     BYTE(0)   /* b */
>>     BYTE(0)   /* g */
>>     BYTE(0)   /* \0 */
>>     LONG(0)   /* checksum */
>>   }
>
>  I think (haven't checked yet) that this looks like a consequence of the
> ldlang.c changes.  Any thoughts on how to fix it?
>
>    cheers,
>      DaveK
>
>

Well, you can add this section to the comparison for debugging section
in bfd's coffcode.h (like done there for the others - .debug*,
comment, etc). Should work then.

Cheers,
Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-15 20:36   ` Kai Tietz
@ 2010-10-15 22:27     ` Dave Korn
  2010-10-15 22:28       ` Dave Korn
  0 siblings, 1 reply; 23+ messages in thread
From: Dave Korn @ 2010-10-15 22:27 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils, Alan Modra

On 15/10/2010 21:36, Kai Tietz wrote:

> Well, you can add this section to the comparison for debugging section
> in bfd's coffcode.h (like done there for the others - .debug*,
> comment, etc). Should work then.

  You mean like the attached?  Didn't work.  It's specifically this hunk here
that's losing the flag and causing the later failure:

> @@ -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)

from ldlang.c

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-15 22:27     ` Dave Korn
@ 2010-10-15 22:28       ` Dave Korn
  0 siblings, 0 replies; 23+ messages in thread
From: Dave Korn @ 2010-10-15 22:28 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils, Alan Modra

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

On 15/10/2010 23:50, Dave Korn wrote:
> On 15/10/2010 21:36, Kai Tietz wrote:
> 
>> Well, you can add this section to the comparison for debugging section
>> in bfd's coffcode.h (like done there for the others - .debug*,
>> comment, etc). Should work then.
> 
>   You mean like the attached?  Didn't work.  

  Wasn't attached either.  Boh!

    cheers,
      DaveK

[-- Attachment #2: doesnt-work.diff --]
[-- Type: text/x-c, Size: 1562 bytes --]

diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index ff69704..c7739a8 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -372,6 +372,7 @@ CODE_FRAGMENT
 #define STRING_SIZE_SIZE 4
 
 #define DOT_DEBUG	".debug"
+#define GNU_DEBUGLINK	".gnu_debuglink"
 #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
 #define DOT_RELOC	".reloc"
 
@@ -544,7 +545,8 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
       styp_flags = STYP_LIT;
 #endif /* _LIT */
     }
-  else if (CONST_STRNEQ (sec_name, DOT_DEBUG))
+  else if (CONST_STRNEQ (sec_name, DOT_DEBUG)
+	|| CONST_STRNEQ (sec_name, GNU_DEBUGLINK))
     {
       /* Handle the XCOFF debug section and DWARF2 debug sections.  */
       if (!sec_name[6])
@@ -641,6 +643,7 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
   if (CONST_STRNEQ (sec_name, DOT_DEBUG)
 #ifdef COFF_LONG_SECTION_NAMES
       || CONST_STRNEQ (sec_name, GNU_LINKONCE_WI)
+      || CONST_STRNEQ (sec_name, GNU_DEBUGLINK)
 #endif
       || CONST_STRNEQ (sec_name, ".stab"))
     is_dbg = TRUE;
@@ -799,6 +802,7 @@ styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
 #endif
 #ifdef COFF_LONG_SECTION_NAMES
 	   || CONST_STRNEQ (name, GNU_LINKONCE_WI)
+	   || CONST_STRNEQ (name, GNU_DEBUGLINK)
 #endif
 	   || CONST_STRNEQ (name, ".stab"))
     {
@@ -1132,6 +1136,7 @@ styp_to_sec_flags (bfd *abfd,
   if (CONST_STRNEQ (name, DOT_DEBUG)
 #ifdef COFF_LONG_SECTION_NAMES
       || CONST_STRNEQ (name, GNU_LINKONCE_WI)
+      || CONST_STRNEQ (name, GNU_DEBUGLINK)
 #endif
       || CONST_STRNEQ (name, ".stab"))
     is_dbg = TRUE;

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-15 20:31 ` Dave Korn
  2010-10-15 20:36   ` Kai Tietz
@ 2010-10-16  2:36   ` Alan Modra
  2010-10-16 20:08     ` Kai Tietz
  2010-10-21 23:32     ` Alan Modra
  1 sibling, 2 replies; 23+ messages in thread
From: Alan Modra @ 2010-10-16  2:36 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

On Fri, Oct 15, 2010 at 09:54:18PM +0100, Dave Korn wrote:
> >   .gnu_debuglink_overlay ALIGN(__section_alignment__) (NOLOAD):
> >   {
> >     BYTE(0)	/* c */
> >     BYTE(0)	/* y */
> >     BYTE(0)	/* g */
> >     BYTE(0)	/* w */
> >     BYTE(0)	/* i */
> >     BYTE(0)	/* n */
> >     BYTE(0)	/* 1 */
> >     BYTE(0)	/* . */
> >     BYTE(0)	/* d */
> >     BYTE(0)	/* b */
> >     BYTE(0)	/* g */
> >     BYTE(0)	/* \0 */
> >     LONG(0)	/* checksum */
> >   }

Using your script with a small tweak for ELF gave me the same error.

>   I think (haven't checked yet) that this looks like a consequence of the
> ldlang.c changes.  Any thoughts on how to fix it?

Like this, I think, just as we discard input sections and padding in
noload sections.  Can you test this out for me on cygwin?

	* ldwrite.c (build_link_order <lang_data_statement_enum>): Don't
	output when section has no contents.
	(build_link_order <lang_reloc_statement_enum>): Likewise.

Index: ld/ldwrite.c
===================================================================
RCS file: /cvs/src/src/ld/ldwrite.c,v
retrieving revision 1.32
diff -u -p -r1.32 ldwrite.c
--- ld/ldwrite.c	22 Sep 2010 14:20:24 -0000	1.32
+++ ld/ldwrite.c	16 Oct 2010 01:26:37 -0000
@@ -51,6 +51,11 @@ build_link_order (lang_statement_union_t
 	output_section = statement->data_statement.output_section;
 	ASSERT (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))))
+	  break;
+
 	link_order = bfd_new_link_order (link_info.output_bfd, output_section);
 	if (link_order == NULL)
 	  einfo (_("%P%F: bfd_new_link_order failed\n"));
@@ -191,6 +196,11 @@ build_link_order (lang_statement_union_t
 	output_section = rs->output_section;
 	ASSERT (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))))
+	  break;
+
 	link_order = bfd_new_link_order (link_info.output_bfd, output_section);
 	if (link_order == NULL)
 	  einfo (_("%P%F: bfd_new_link_order failed\n"));

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-16  2:36   ` Alan Modra
@ 2010-10-16 20:08     ` Kai Tietz
  2010-10-16 20:19       ` Dave Korn
  2010-10-17 23:29       ` Alan Modra
  2010-10-21 23:32     ` Alan Modra
  1 sibling, 2 replies; 23+ messages in thread
From: Kai Tietz @ 2010-10-16 20:08 UTC (permalink / raw)
  To: Dave Korn, binutils

2010/10/16 Alan Modra <amodra@gmail.com>:
> On Fri, Oct 15, 2010 at 09:54:18PM +0100, Dave Korn wrote:
>> >   .gnu_debuglink_overlay ALIGN(__section_alignment__) (NOLOAD):
>> >   {
>> >     BYTE(0) /* c */
>> >     BYTE(0) /* y */
>> >     BYTE(0) /* g */
>> >     BYTE(0) /* w */
>> >     BYTE(0) /* i */
>> >     BYTE(0) /* n */
>> >     BYTE(0) /* 1 */
>> >     BYTE(0) /* . */
>> >     BYTE(0) /* d */
>> >     BYTE(0) /* b */
>> >     BYTE(0) /* g */
>> >     BYTE(0) /* \0 */
>> >     LONG(0) /* checksum */
>> >   }
>
> Using your script with a small tweak for ELF gave me the same error.
>
>>   I think (haven't checked yet) that this looks like a consequence of the
>> ldlang.c changes.  Any thoughts on how to fix it?
>
> Like this, I think, just as we discard input sections and padding in
> noload sections.  Can you test this out for me on cygwin?
>
>        * ldwrite.c (build_link_order <lang_data_statement_enum>): Don't
>        output when section has no contents.
>        (build_link_order <lang_reloc_statement_enum>): Likewise.
>
> Index: ld/ldwrite.c
> ===================================================================
> RCS file: /cvs/src/src/ld/ldwrite.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 ldwrite.c
> --- ld/ldwrite.c        22 Sep 2010 14:20:24 -0000      1.32
> +++ ld/ldwrite.c        16 Oct 2010 01:26:37 -0000
> @@ -51,6 +51,11 @@ build_link_order (lang_statement_union_t
>        output_section = statement->data_statement.output_section;
>        ASSERT (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))))
> +         break;
> +
>        link_order = bfd_new_link_order (link_info.output_bfd, output_section);
>        if (link_order == NULL)
>          einfo (_("%P%F: bfd_new_link_order failed\n"));
> @@ -191,6 +196,11 @@ build_link_order (lang_statement_union_t
>        output_section = rs->output_section;
>        ASSERT (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))))
> +         break;
> +
>        link_order = bfd_new_link_order (link_info.output_bfd, output_section);
>        if (link_order == NULL)
>          einfo (_("%P%F: bfd_new_link_order failed\n"));
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

Well, this looks ok, too. But AFAICS it is touching just the surface.
My recent patch took care that for PE-COFF the content of the
debugging sections didn't got zero'ed. Maybe it is a general failure
to assume (at least for pe-coff, but maybe for elf, too) that NOLOAD
means to discard sections from linking?

Cheers,
Kai


-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-16 20:08     ` Kai Tietz
@ 2010-10-16 20:19       ` Dave Korn
  2010-10-17 10:32         ` Kai Tietz
  2010-10-17 23:29       ` Alan Modra
  1 sibling, 1 reply; 23+ messages in thread
From: Dave Korn @ 2010-10-16 20:19 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On 16/10/2010 21:08, Kai Tietz wrote:
> 2010/10/16 Alan Modra <amodra@gmail.com>:
>> On Fri, Oct 15, 2010 at 09:54:18PM +0100, Dave Korn wrote:
>>>>   .gnu_debuglink_overlay ALIGN(__section_alignment__) (NOLOAD):
>>>>   {
>>>>     BYTE(0) /* c */

>> Using your script with a small tweak for ELF gave me the same error.
>>
>>>   I think (haven't checked yet) that this looks like a consequence of the
>>> ldlang.c changes.  Any thoughts on how to fix it?
>> Like this, I think, just as we discard input sections and padding in
>> noload sections.  Can you test this out for me on cygwin?
>>
>>        * ldwrite.c (build_link_order <lang_data_statement_enum>): Don't
>>        output when section has no contents.
>>        (build_link_order <lang_reloc_statement_enum>): Likewise.

> Well, this looks ok, too. But AFAICS it is touching just the surface.
> My recent patch took care that for PE-COFF the content of the
> debugging sections didn't got zero'ed. Maybe it is a general failure
> to assume (at least for pe-coff, but maybe for elf, too) that NOLOAD
> means to discard sections from linking?

  I'm seeing odd behaviour.  If I build the cygwin dll with the
map_input_to_output_sections reverted, I get this:

> $ objdump -h cygwin0.dll
> 
> cygwin0.dll:     file format pei-i386
> 
> Sections:
> Idx Name          Size      VMA       LMA       File off  Algn

>   9 .gnu_debuglink_overlay 00000010  61239000  61239000  001fee00  2**2
>                   CONTENTS, EXCLUDE

  ... and this:

> $ objdump -s -j .gnu_debuglink_overlay  cygwin0.dll
> 
> cygwin0.dll:     file format pei-i386
> 
> Contents of section .gnu_debuglink_overlay:
>  61239000 00000000 00000000 00000000 00000000  ................
> 
> $

  With the build_link_order change instead, I get this:

> $ objdump -h cygwin0.dll
> 
> cygwin0.dll:     file format pei-i386
> 
> Sections:
> Idx Name          Size      VMA       LMA       File off  Algn

>   9 .gnu_debuglink_overlay 00000010  61239000  61239000  00000000  2**2
>                   EXCLUDE

  ... and this:

> $ objdump -s -j .gnu_debuglink_overlay  cygwin0.dll
> 
> cygwin0.dll:     file format pei-i386
> 
> objdump: section '.gnu_debuglink_overlay' mentioned in a -j option, but not
> found in any input file

  I think it really needs that CONTENTS flag.  Can look closer at it later, I
have to go offline for a while now.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-16 20:19       ` Dave Korn
@ 2010-10-17 10:32         ` Kai Tietz
  2010-10-17 16:40           ` Dave Korn
  0 siblings, 1 reply; 23+ messages in thread
From: Kai Tietz @ 2010-10-17 10:32 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

2010/10/16 Dave Korn <dave.korn.cygwin@gmail.com>:
> On 16/10/2010 21:08, Kai Tietz wrote:
>> 2010/10/16 Alan Modra <amodra@gmail.com>:
>>> On Fri, Oct 15, 2010 at 09:54:18PM +0100, Dave Korn wrote:
>>>>>   .gnu_debuglink_overlay ALIGN(__section_alignment__) (NOLOAD):
>>>>>   {
>>>>>     BYTE(0) /* c */
>
>>> Using your script with a small tweak for ELF gave me the same error.
>>>
>>>>   I think (haven't checked yet) that this looks like a consequence of the
>>>> ldlang.c changes.  Any thoughts on how to fix it?
>>> Like this, I think, just as we discard input sections and padding in
>>> noload sections.  Can you test this out for me on cygwin?
>>>
>>>        * ldwrite.c (build_link_order <lang_data_statement_enum>): Don't
>>>        output when section has no contents.
>>>        (build_link_order <lang_reloc_statement_enum>): Likewise.
>
>> Well, this looks ok, too. But AFAICS it is touching just the surface.
>> My recent patch took care that for PE-COFF the content of the
>> debugging sections didn't got zero'ed. Maybe it is a general failure
>> to assume (at least for pe-coff, but maybe for elf, too) that NOLOAD
>> means to discard sections from linking?
>
>  I'm seeing odd behaviour.  If I build the cygwin dll with the
> map_input_to_output_sections reverted, I get this:
>
>> $ objdump -h cygwin0.dll
>>
>> cygwin0.dll:     file format pei-i386
>>
>> Sections:
>> Idx Name          Size      VMA       LMA       File off  Algn
>
>>   9 .gnu_debuglink_overlay 00000010  61239000  61239000  001fee00  2**2
>>                   CONTENTS, EXCLUDE
>
>  ... and this:
>
>> $ objdump -s -j .gnu_debuglink_overlay  cygwin0.dll
>>
>> cygwin0.dll:     file format pei-i386
>>
>> Contents of section .gnu_debuglink_overlay:
>>  61239000 00000000 00000000 00000000 00000000  ................
>>
>> $
>
>  With the build_link_order change instead, I get this:
>
>> $ objdump -h cygwin0.dll
>>
>> cygwin0.dll:     file format pei-i386
>>
>> Sections:
>> Idx Name          Size      VMA       LMA       File off  Algn
>
>>   9 .gnu_debuglink_overlay 00000010  61239000  61239000  00000000  2**2
>>                   EXCLUDE
>
>  ... and this:
>
>> $ objdump -s -j .gnu_debuglink_overlay  cygwin0.dll
>>
>> cygwin0.dll:     file format pei-i386
>>
>> objdump: section '.gnu_debuglink_overlay' mentioned in a -j option, but not
>> found in any input file
>
>  I think it really needs that CONTENTS flag.  Can look closer at it later, I
> have to go offline for a while now.
>
>    cheers,
>      DaveK
>
>

Well, the CONTENT flag is here of less use. The underlying issue is
(at least for pe-coff) that SEC_NEVER_LOAD (which indicates for
pe-coff just that this section doesn't have load and allocation flags
set and will not loaded into memory - btw different to discard flag,
which means that it is initially loaded but then discarded) is treated
similar to SEC_EXCLUDE. The SEC_EXCLUDE is in fact the PE-COFF flag
IMAGE_SCN_LNK_REMOVE.
This looks wrong to me. If you want I can prepare a patch for this.

Cheers,
Kai
-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-17 10:32         ` Kai Tietz
@ 2010-10-17 16:40           ` Dave Korn
  2010-10-17 19:18             ` Kai Tietz
  0 siblings, 1 reply; 23+ messages in thread
From: Dave Korn @ 2010-10-17 16:40 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On 17/10/2010 11:32, Kai Tietz wrote:

> Well, the CONTENT flag is here of less use. The underlying issue is
> (at least for pe-coff) that SEC_NEVER_LOAD (which indicates for
> pe-coff just that this section doesn't have load and allocation flags
> set and will not loaded into memory - btw different to discard flag,
> which means that it is initially loaded but then discarded) is treated
> similar to SEC_EXCLUDE. The SEC_EXCLUDE is in fact the PE-COFF flag
> IMAGE_SCN_LNK_REMOVE.
> This looks wrong to me. If you want I can prepare a patch for this.

  Thanks, that would be very helpful.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-17 16:40           ` Dave Korn
@ 2010-10-17 19:18             ` Kai Tietz
  0 siblings, 0 replies; 23+ messages in thread
From: Kai Tietz @ 2010-10-17 19:18 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 945 bytes --]

2010/10/17 Dave Korn <dave.korn.cygwin@gmail.com>:
> On 17/10/2010 11:32, Kai Tietz wrote:
>
>> Well, the CONTENT flag is here of less use. The underlying issue is
>> (at least for pe-coff) that SEC_NEVER_LOAD (which indicates for
>> pe-coff just that this section doesn't have load and allocation flags
>> set and will not loaded into memory - btw different to discard flag,
>> which means that it is initially loaded but then discarded) is treated
>> similar to SEC_EXCLUDE. The SEC_EXCLUDE is in fact the PE-COFF flag
>> IMAGE_SCN_LNK_REMOVE.
>> This looks wrong to me. If you want I can prepare a patch for this.
>
>  Thanks, that would be very helpful.
>
>    cheers,
>      DaveK
>
>

Dave,

could you give the attached patch a whirl? It should solve your issue AFAICS.

Cheers,
Kai


-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

[-- Attachment #2: noload.diff --]
[-- Type: application/octet-stream, Size: 3186 bytes --]

Index: src/bfd/coffcode.h
===================================================================
--- src.orig/bfd/coffcode.h	2010-09-27 07:37:47.000000000 +0200
+++ src/bfd/coffcode.h	2010-10-17 19:11:43.024545800 +0200
@@ -655,7 +655,11 @@ sec_to_styp_flags (const char *sec_name,
 
   /* FIXME: There is no gas syntax to specify the debug section flag.  */
   if (is_dbg)
-      sec_flags = SEC_DEBUGGING | SEC_READONLY;
+    {
+      /* We want to keep link once semantic even for debugging.  */
+      sec_flags &= ~SEC_LINK_ONCE;
+      sec_flags |= SEC_DEBUGGING | SEC_READONLY;
+    }
 
   /* skip LOAD */
   /* READONLY later */
@@ -673,10 +677,10 @@ sec_to_styp_flags (const char *sec_name,
     styp_flags |= IMAGE_SCN_LNK_COMDAT;
   if ((sec_flags & SEC_DEBUGGING) != 0)
     styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
-  if ((sec_flags & SEC_EXCLUDE) != 0 && !is_dbg)
-    styp_flags |= IMAGE_SCN_LNK_REMOVE;
-  if ((sec_flags & SEC_NEVER_LOAD) != 0 && !is_dbg)
+  if ((sec_flags & SEC_EXCLUDE) != 0)
     styp_flags |= IMAGE_SCN_LNK_REMOVE;
+  /*if ((sec_flags & SEC_NEVER_LOAD) != 0)
+    styp_flags |= IMAGE_SCN_LNK_REMOVE;*/
   /* skip IN_MEMORY */
   /* skip SORT */
   if (sec_flags & SEC_LINK_ONCE)
@@ -1171,6 +1175,7 @@ styp_to_sec_flags (bfd *abfd,
 #ifdef SEC_NEVER_LOAD
 	case STYP_NOLOAD:
 	  sec_flags |= SEC_NEVER_LOAD;
+	  sec_flags &= ~(SEC_ALLOC | SEC_LOAD);
 	  break;
 #endif
 	case IMAGE_SCN_MEM_READ:
@@ -1221,13 +1226,19 @@ styp_to_sec_flags (bfd *abfd,
 	    sec_flags |= SEC_EXCLUDE;
 	  break;
 	case IMAGE_SCN_CNT_CODE:
-	  sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
+	  sec_flags |= SEC_CODE;
+	  if ((sec_flags & SEC_NEVER_LOAD) == 0)
+	    sec_flags |= SEC_ALLOC | SEC_LOAD;
 	  break;
 	case IMAGE_SCN_CNT_INITIALIZED_DATA:
 	  if (is_dbg)
 	    sec_flags |= SEC_DEBUGGING;
 	  else
-	    sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
+	    {
+	      sec_flags |= SEC_DATA;
+	      if ((sec_flags & SEC_NEVER_LOAD) == 0)
+		sec_flags |= SEC_ALLOC | SEC_LOAD;
+	    }
 	  break;
 	case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
 	  sec_flags |= SEC_ALLOC;
Index: src/ld/ldlang.c
===================================================================
--- src.orig/ld/ldlang.c	2010-10-15 23:32:18.000000000 +0200
+++ src/ld/ldlang.c	2010-10-17 20:44:41.402610800 +0200
@@ -2254,8 +2254,7 @@ lang_add_section (lang_statement_list_ty
 	   || (bfd_get_flavour (section->owner)
 	       == bfd_target_coff_flavour)))
 	{
-	  if ((flags & (SEC_COFF_SHARED_LIBRARY | SEC_DEBUGGING)) == 0)
-	    flags &= ~SEC_HAS_CONTENTS;
+	  /* For pe-coff noload can have content.  */
 	}
       else
 	flags &= ~SEC_HAS_CONTENTS;
Index: src/ld/ldwrite.c
===================================================================
--- src.orig/ld/ldwrite.c	2010-09-27 07:37:57.000000000 +0200
+++ src/ld/ldwrite.c	2010-10-17 20:45:50.552566000 +0200
@@ -246,7 +246,7 @@ build_link_order (lang_statement_union_t
 						 output_section);
 
 		if ((i->flags & SEC_NEVER_LOAD) != 0
-		    && (i->flags & SEC_DEBUGGING) == 0)
+		    && (i->flags & SEC_HAS_CONTENTS) == 0)
 		  {
 		    /* We've got a never load section inside one which
 		       is going to be output, we'll change it into a

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-16 20:08     ` Kai Tietz
  2010-10-16 20:19       ` Dave Korn
@ 2010-10-17 23:29       ` Alan Modra
  2010-10-18  6:22         ` Kai Tietz
  1 sibling, 1 reply; 23+ messages in thread
From: Alan Modra @ 2010-10-17 23:29 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Dave Korn, binutils

On Sat, Oct 16, 2010 at 10:08:07PM +0200, Kai Tietz wrote:
> Maybe it is a general failure
> to assume (at least for pe-coff, but maybe for elf, too) that NOLOAD
> means to discard sections from linking?

Possibly.  Can you say exactly how NOLOAD should behave from a COFF
perspective?  ie. what STYP_NOLOAD ought to do?

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-17 23:29       ` Alan Modra
@ 2010-10-18  6:22         ` Kai Tietz
  2010-10-18 13:44           ` Alan Modra
  0 siblings, 1 reply; 23+ messages in thread
From: Kai Tietz @ 2010-10-18  6:22 UTC (permalink / raw)
  To: Kai Tietz, Dave Korn, binutils

2010/10/18 Alan Modra <amodra@gmail.com>:
> On Sat, Oct 16, 2010 at 10:08:07PM +0200, Kai Tietz wrote:
>> Maybe it is a general failure
>> to assume (at least for pe-coff, but maybe for elf, too) that NOLOAD
>> means to discard sections from linking?
>
> Possibly.  Can you say exactly how NOLOAD should behave from a COFF
> perspective?  ie. what STYP_NOLOAD ought to do?
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

According to pe-coff specification NOLOAD means that a section has
neither allocation nor the load flag set. For example .debug* or
.metadata sections have this style described in pe-coff specification.
They are part of the image without being mapped into process-memory on
module load time, but have content and have image-file pointers.

Regards,
Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-18  6:22         ` Kai Tietz
@ 2010-10-18 13:44           ` Alan Modra
  2010-10-18 14:39             ` Kai Tietz
  0 siblings, 1 reply; 23+ messages in thread
From: Alan Modra @ 2010-10-18 13:44 UTC (permalink / raw)
  To: Kai Tietz; +Cc: Dave Korn, binutils

On Mon, Oct 18, 2010 at 08:21:56AM +0200, Kai Tietz wrote:
> According to pe-coff specification NOLOAD means that a section has
> neither allocation nor the load flag set. For example .debug* or
> .metadata sections have this style described in pe-coff specification.
> They are part of the image without being mapped into process-memory on
> module load time, but have content and have image-file pointers.

http://osr507doc.sco.com/en/topics/COFF_SectHdrFlags.html disagrees.
STYP_NOLOAD 	0x02 	Noload section (allocated, relocated, not loaded)

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-18 13:44           ` Alan Modra
@ 2010-10-18 14:39             ` Kai Tietz
  2010-10-19 15:05               ` Kai Tietz
  0 siblings, 1 reply; 23+ messages in thread
From: Kai Tietz @ 2010-10-18 14:39 UTC (permalink / raw)
  To: Kai Tietz, Dave Korn, binutils

2010/10/18 Alan Modra <amodra@gmail.com>:
> On Mon, Oct 18, 2010 at 08:21:56AM +0200, Kai Tietz wrote:
>> According to pe-coff specification NOLOAD means that a section has
>> neither allocation nor the load flag set. For example .debug* or
>> .metadata sections have this style described in pe-coff specification.
>> They are part of the image without being mapped into process-memory on
>> module load time, but have content and have image-file pointers.
>
> http://osr507doc.sco.com/en/topics/COFF_SectHdrFlags.html disagrees.
> STYP_NOLOAD     0x02    Noload section (allocated, relocated, not loaded)
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

Well, the issue for pe-coff is that no-LOAD with ALLOC leads to
uninitialized data, which is used for .bss. But sections with NOLOAD
have content and therefore need INITIALIZED_DATA flag set.
So it makes sense for ELF that a section, which is allocated but not
loaded, to short-cut to write zero-data. But well, the no-load case
should be covered by ELF-loader and not necessarily means that section
must have zero'ed content, or am I wrong here?
For pe-coff the no-load (caused by .bss, which has really no content
stored), but isn't marked as STYP_NOLOAD AFAICS) the no-load should
have still CONTENT.

Kai
-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-18 14:39             ` Kai Tietz
@ 2010-10-19 15:05               ` Kai Tietz
  2010-10-20 14:48                 ` Dave Korn
  0 siblings, 1 reply; 23+ messages in thread
From: Kai Tietz @ 2010-10-19 15:05 UTC (permalink / raw)
  To: Kai Tietz, Dave Korn, binutils

2010/10/18 Kai Tietz <ktietz70@googlemail.com>:
> 2010/10/18 Alan Modra <amodra@gmail.com>:
>> On Mon, Oct 18, 2010 at 08:21:56AM +0200, Kai Tietz wrote:
>>> According to pe-coff specification NOLOAD means that a section has
>>> neither allocation nor the load flag set. For example .debug* or
>>> .metadata sections have this style described in pe-coff specification.
>>> They are part of the image without being mapped into process-memory on
>>> module load time, but have content and have image-file pointers.
>>
>> http://osr507doc.sco.com/en/topics/COFF_SectHdrFlags.html disagrees.
>> STYP_NOLOAD     0x02    Noload section (allocated, relocated, not loaded)
>>
>> --
>> Alan Modra
>> Australia Development Lab, IBM
>>
>
> Well, the issue for pe-coff is that no-LOAD with ALLOC leads to
> uninitialized data, which is used for .bss. But sections with NOLOAD
> have content and therefore need INITIALIZED_DATA flag set.
> So it makes sense for ELF that a section, which is allocated but not
> loaded, to short-cut to write zero-data. But well, the no-load case
> should be covered by ELF-loader and not necessarily means that section
> must have zero'ed content, or am I wrong here?
> For pe-coff the no-load (caused by .bss, which has really no content
> stored), but isn't marked as STYP_NOLOAD AFAICS) the no-load should
> have still CONTENT.
>
> Kai
> --
> |  (\_/) This is Bunny. Copy and paste
> | (='.'=) Bunny into your signature to help
> | (")_(") him gain world domination
>

Dave,

have you test if the patch solves your issue?

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-19 15:05               ` Kai Tietz
@ 2010-10-20 14:48                 ` Dave Korn
  2010-10-26 12:46                   ` Alan Modra
  0 siblings, 1 reply; 23+ messages in thread
From: Dave Korn @ 2010-10-20 14:48 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On 19/10/2010 16:05, Kai Tietz wrote:

> 
> have you test if the patch solves your issue?

  Pardon the delay, I'll get on with this shortly.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-16  2:36   ` Alan Modra
  2010-10-16 20:08     ` Kai Tietz
@ 2010-10-21 23:32     ` Alan Modra
  1 sibling, 0 replies; 23+ messages in thread
From: Alan Modra @ 2010-10-21 23:32 UTC (permalink / raw)
  To: Dave Korn, binutils

On Sat, Oct 16, 2010 at 01:05:59PM +1030, Alan Modra wrote:
> 	* ldwrite.c (build_link_order <lang_data_statement_enum>): Don't
> 	output when section has no contents.
> 	(build_link_order <lang_reloc_statement_enum>): Likewise.

Committed.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-20 14:48                 ` Dave Korn
@ 2010-10-26 12:46                   ` Alan Modra
  2010-10-26 16:56                     ` Dave Korn
  2010-11-05  4:36                     ` Dave Korn
  0 siblings, 2 replies; 23+ messages in thread
From: Alan Modra @ 2010-10-26 12:46 UTC (permalink / raw)
  To: Dave Korn; +Cc: Kai Tietz, binutils

It seems we have irreconcilable differences between ELF and COFF in
the treatment of NOLOAD.  How does the following look to you COFF
people?

Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.344
diff -u -p -r1.344 ldlang.c
--- ld/ldlang.c	14 Oct 2010 01:31:31 -0000	1.344
+++ ld/ldlang.c	26 Oct 2010 12:40:11 -0000
@@ -2249,16 +2249,14 @@ lang_add_section (lang_statement_list_ty
     case noload_section:
       flags &= ~SEC_LOAD;
       flags |= SEC_NEVER_LOAD;
-      if (((bfd_get_flavour (section->owner)
-	    == bfd_target_ecoff_flavour)
-	   || (bfd_get_flavour (section->owner)
-	       == bfd_target_coff_flavour)))
-	{
-	  if ((flags & (SEC_COFF_SHARED_LIBRARY | SEC_DEBUGGING)) == 0)
-	    flags &= ~SEC_HAS_CONTENTS;
-	}
-      else
+      /* Unfortunately GNU ld has managed to evolve two different
+	 meanings to NOLOAD in scripts.  ELF gets a .bss style noload,
+	 alloc, no contents section.  All others get a noload, noalloc
+	 section.  */
+      if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
 	flags &= ~SEC_HAS_CONTENTS;
+      else
+	flags &= ~SEC_ALLOC;
       break;
     }
 
@@ -3510,7 +3508,11 @@ map_input_to_output_sections
 	      flags = SEC_HAS_CONTENTS;
 	      break;
 	    case noload_section:
-	      flags = SEC_NEVER_LOAD;
+	      if (bfd_get_flavour (link_info.output_bfd)
+		  == bfd_target_elf_flavour)
+		flags = SEC_NEVER_LOAD | SEC_ALLOC;
+	      else
+		flags = SEC_NEVER_LOAD | SEC_HAS_CONTENTS;
 	      break;
 	    }
 	  if (os->bfd_section == NULL)
@@ -4572,13 +4574,9 @@ sort_sections_by_lma (const void *arg1, 
   return 0;
 }
 
-/* On ELF, a debugging section must never set SEC_NEVER_LOAD, as no output
-   would be written for it. So the combination of debugging and never-load
-   is something which can only happen for pe-coff and must not be ignored.  */
 #define IGNORE_SECTION(s) \
-  ((s->flags & (SEC_NEVER_LOAD | SEC_DEBUGGING)) == SEC_NEVER_LOAD	\
-   || (s->flags & SEC_ALLOC) == 0				\
-   || ((s->flags & SEC_THREAD_LOCAL) != 0			\
+  ((s->flags & SEC_ALLOC) == 0				\
+   || ((s->flags & SEC_THREAD_LOCAL) != 0		\
 	&& (s->flags & SEC_LOAD) == 0))
 
 /* Check to see if any allocated sections overlap with other allocated
@@ -4610,8 +4608,7 @@ lang_check_section_addresses (void)
   for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
     {
       /* Only consider loadable sections with real contents.  */
-      if ((s->flags & (SEC_NEVER_LOAD | SEC_DEBUGGING)) == SEC_NEVER_LOAD
-	  || !(s->flags & SEC_LOAD)
+      if (!(s->flags & SEC_LOAD)
 	  || !(s->flags & SEC_ALLOC)
 	  || s->size == 0)
 	continue;
@@ -5190,7 +5187,10 @@ lang_size_sections_1
 		       should have space allocated to it, unless the
 		       user has explicitly stated that the section
 		       should not be allocated.  */
-		    if (output_section_statement->sectype != noalloc_section)
+		    if (output_section_statement->sectype != noalloc_section
+			&& (output_section_statement->sectype != noload_section
+			    || (bfd_get_flavour (link_info.output_bfd)
+				== bfd_target_elf_flavour)))
 		      output_section_statement->bfd_section->flags |= SEC_ALLOC;
 		  }
 		dot = newdot;

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-26 12:46                   ` Alan Modra
@ 2010-10-26 16:56                     ` Dave Korn
  2010-11-05  4:36                     ` Dave Korn
  1 sibling, 0 replies; 23+ messages in thread
From: Dave Korn @ 2010-10-26 16:56 UTC (permalink / raw)
  To: Dave Korn, Kai Tietz, binutils

On 26/10/2010 13:46, Alan Modra wrote:
> It seems we have irreconcilable differences between ELF and COFF in
> the treatment of NOLOAD.  How does the following look to you COFF
> people?

  I have one more patch I want to get done for GCC before stage1 ends, and not
a lot of time to do it in, whereas Tristan isn't planning to branch binutils
until Nov 2-3, so I'm not going to come back to this for a couple of days, but
thanks for sticking with it, I do intend to get this tied down before the branch.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-10-26 12:46                   ` Alan Modra
  2010-10-26 16:56                     ` Dave Korn
@ 2010-11-05  4:36                     ` Dave Korn
  2010-11-05  5:58                       ` Alan Modra
  1 sibling, 1 reply; 23+ messages in thread
From: Dave Korn @ 2010-11-05  4:36 UTC (permalink / raw)
  To: Dave Korn, Kai Tietz, binutils

On 26/10/2010 13:46, Alan Modra wrote:
> It seems we have irreconcilable differences between ELF and COFF in
> the treatment of NOLOAD.  How does the following look to you COFF
> people?

  Yes, please.  With that, HEAD now DTRT, by which I mean behaves the same as
2.20 and earlier: the created section has an address and CONTENTS:

>  10 .gnu_debuglink_overlay 00000010  6123a000  6123a000  00213a00  2**2
>                   CONTENTS, EXCLUDE

... whereas unpatched HEAD omits the contents:

>   9 .gnu_debuglink_overlay 00000010  61239000  61239000  00000000  2**2
>                   EXCLUDE

... which is not the desired outcome.

  I still have one discrepancy to tidy up, which is that running this command
on the generated DLL file:

> objcopy -g --add-gnu-debuglink=cygwin1.dbg cygwin0.dll

creates a section like so with 2.20:

>  12 .gnu_debuglink 00000010  61300000  61300000  00204600  2**2
>                   CONTENTS, READONLY

but creates a section like so:

>  12 .gnu_debuglink 00000010  61300000  61300000  00204c00  2**2
>                   CONTENTS, ALLOC, LOAD, READONLY, DATA

... with HEAD, either with or without your patch.  I imagine this is down to
the styp to/from section flags conversion in coffcode.h, I'm investigating
that now.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-11-05  4:36                     ` Dave Korn
@ 2010-11-05  5:58                       ` Alan Modra
  2010-11-05  7:24                         ` Dave Korn
  0 siblings, 1 reply; 23+ messages in thread
From: Alan Modra @ 2010-11-05  5:58 UTC (permalink / raw)
  To: Dave Korn; +Cc: Kai Tietz, binutils

On Fri, Nov 05, 2010 at 05:00:19AM +0000, Dave Korn wrote:
> On 26/10/2010 13:46, Alan Modra wrote:
> > It seems we have irreconcilable differences between ELF and COFF in
> > the treatment of NOLOAD.  How does the following look to you COFF
> > people?
> 
>   Yes, please.

Committed with this ChangeLog.

	* ldlang.c (lang_add_section): Distinguish ELF treatment of NOLOAD.
	(map_input_to_output_sections): Likewise.
	(lang_size_sections_1): Likewise.
	(IGNORE_SECTION): Don't test SEC_NEVER_LOAD.
	(lang_check_section_addresses): Likewise.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: SEC_NEVER_LOAD cleanup
  2010-11-05  5:58                       ` Alan Modra
@ 2010-11-05  7:24                         ` Dave Korn
  0 siblings, 0 replies; 23+ messages in thread
From: Dave Korn @ 2010-11-05  7:24 UTC (permalink / raw)
  To: Dave Korn, Kai Tietz, binutils

On 05/11/2010 05:58, Alan Modra wrote:
> On Fri, Nov 05, 2010 at 05:00:19AM +0000, Dave Korn wrote:
>> On 26/10/2010 13:46, Alan Modra wrote:
>>> It seems we have irreconcilable differences between ELF and COFF in
>>> the treatment of NOLOAD.  How does the following look to you COFF
>>> people?
>>   Yes, please.
> 
> Committed with this ChangeLog.
> 
> 	* ldlang.c (lang_add_section): Distinguish ELF treatment of NOLOAD.
> 	(map_input_to_output_sections): Likewise.
> 	(lang_size_sections_1): Likewise.
> 	(IGNORE_SECTION): Don't test SEC_NEVER_LOAD.
> 	(lang_check_section_addresses): Likewise.

  TYVM :)

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2010-11-05  7:24 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-16  0:03 SEC_NEVER_LOAD cleanup Alan Modra
2010-10-15 20:31 ` Dave Korn
2010-10-15 20:36   ` Kai Tietz
2010-10-15 22:27     ` Dave Korn
2010-10-15 22:28       ` Dave Korn
2010-10-16  2:36   ` Alan Modra
2010-10-16 20:08     ` Kai Tietz
2010-10-16 20:19       ` Dave Korn
2010-10-17 10:32         ` Kai Tietz
2010-10-17 16:40           ` Dave Korn
2010-10-17 19:18             ` Kai Tietz
2010-10-17 23:29       ` Alan Modra
2010-10-18  6:22         ` Kai Tietz
2010-10-18 13:44           ` Alan Modra
2010-10-18 14:39             ` Kai Tietz
2010-10-19 15:05               ` Kai Tietz
2010-10-20 14:48                 ` Dave Korn
2010-10-26 12:46                   ` Alan Modra
2010-10-26 16:56                     ` Dave Korn
2010-11-05  4:36                     ` Dave Korn
2010-11-05  5:58                       ` Alan Modra
2010-11-05  7:24                         ` Dave Korn
2010-10-21 23:32     ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).