LD patch to silence warnings about removed sections

Richard Sandiford rsandifo@redhat.com
Fri Jun 7 10:10:00 GMT 2002


On mips-elf, the linker script:

  MEMORY
  {
    TEXTMEM : ORIGIN = 0x10000, LENGTH = 32K
    DATAMEM : ORIGIN = 0x20000, LENGTH = 32K
  }

  SECTIONS
  {
    .text : { *(.text) } > TEXTMEM
    .data : { *(.data) } > DATAMEM
    .bss  : { *(.bss)  } > DATAMEM
  }

can make ld warn:

  warning: no memory region specified for section `.rel.dyn'

even though the output doesn't contain a .rel.dyn section.
We do create one during processing, but remove it again while
sizing the dynamic sections, because we realise it isn't needed.
But that's after we've added script statements for orphaned
sections.

I'm not sure what the best fix is.  The patch below makes
lang_size_sections_1 skip sections that we've already removed,
but it seems a bit hackish.  I couldn't find a way of checking
for removed sections directly (is there one?) so I made
_bfd_strip_section_from_output set the SEC_EXCLUDE flag in
output sections too.

Anyway, patch tested on mip64-elf and i686-pc-linux-gnu.
Fixes the attached test case.

Richard


[bfd/]
	* section.c (_bfd_strip_section_from_output): Set SEC_EXCLUDE
	for removed output sections.

[ld/]
	* ldlang.c (lang_size_sections_1): Skip removed output sections.

[ld/testsuite/]
	* ld-mips-elf/region1a.s,
	* ld-mips-elf/region1b.s,
	* ld-mips-elf/region1.t,
	* ld-mips-elf/region1.d: New test.
	* ld-mips-elf/mips-elf.exp: Run it.

Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.47
diff -c -d -p -r1.47 section.c
*** bfd/section.c	5 Jun 2002 03:43:11 -0000	1.47
--- bfd/section.c	7 Jun 2002 16:31:50 -0000
*************** _bfd_strip_section_from_output (info, s)
*** 1368,1373 ****
--- 1368,1374 ----
  	if (*spp == os)
  	  {
  	    bfd_section_list_remove (os->owner, spp);
+ 	    os->flags |= SEC_EXCLUDE;
  	    os->owner->section_count--;
  	    break;
  	  }
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.89
diff -c -d -p -r1.89 ldlang.c
*** ld/ldlang.c	4 Jun 2002 01:07:29 -0000	1.89
--- ld/ldlang.c	7 Jun 2002 16:31:50 -0000
*************** lang_size_sections_1 (s, output_section_
*** 2907,2912 ****
--- 2907,2919 ----
  	      /* This section was never actually created.  */
  	      break;
  
+ 	    /* The section might have been removed after its statement was
+ 	       added.  For example, ldemul_before_allocation can remove
+ 	       dynamic sections if they turn out not to be needed.  */
+ 	    if ((bfd_get_section_flags (output_bfd, os->bfd_section)
+ 		 & SEC_EXCLUDE) != 0)
+ 	      break;
+ 
  	    /* If this is a COFF shared library section, use the size and
  	       address from the input section.  FIXME: This is COFF
  	       specific; it would be cleaner if there were some other way
Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.2
diff -c -d -p -r1.2 mips-elf.exp
*** ld/testsuite/ld-mips-elf/mips-elf.exp	30 Jan 2002 02:20:13 -0000	1.2
--- ld/testsuite/ld-mips-elf/mips-elf.exp	7 Jun 2002 16:31:50 -0000
*************** if { [istarget mips*-*-*] } then {
*** 38,42 ****
--- 38,44 ----
  	# Check generation of embedded relocs section.
  	run_dump_test "emrelocs-eb"
  	run_dump_test "emrelocs-el"
+ 
+ 	run_dump_test "region1"
      }
  }
*** /dev/null	Tue Nov 14 21:44:43 2000
--- ld/testsuite/ld-mips-elf/region1a.s	Fri Jun  7 16:35:46 2002
***************
*** 0 ****
--- 1,3 ----
+ 	.text
+ 	.global foo
+ foo:	.4byte	1
*** /dev/null	Tue Nov 14 21:44:43 2000
--- ld/testsuite/ld-mips-elf/region1b.s	Fri Jun  7 16:36:29 2002
***************
*** 0 ****
--- 1,2 ----
+ 	.data
+ 	.4byte	foo
*** /dev/null	Tue Nov 14 21:44:43 2000
--- ld/testsuite/ld-mips-elf/region1.d	Fri Jun  7 16:36:08 2002
***************
*** 0 ****
--- 1,11 ----
+ # as: -mabi=eabi -mips1 -G0
+ # source: region1a.s
+ # source: region1b.s
+ # ld: -T region1.t
+ # name: MIPS region1
+ # objdump: --headers
+ #...
+   0 \.text +0+004 +0+10000 .*
+ #...
+   1 \.data +0+004 +0+20000 .*
+ #pass
*** /dev/null	Tue Nov 14 21:44:43 2000
--- ld/testsuite/ld-mips-elf/region1.t	Fri Jun  7 16:37:23 2002
***************
*** 0 ****
--- 1,12 ----
+ MEMORY
+ {
+   TEXTMEM : ORIGIN = 0x10000, LENGTH = 32K
+   DATAMEM : ORIGIN = 0x20000, LENGTH = 32K
+ }
+ 
+ SECTIONS
+ {
+   .text : { *(.text) } > TEXTMEM
+   .data : { *(.data) } > DATAMEM
+   .bss  : { *(.bss)  } > DATAMEM
+ }



More information about the Binutils mailing list