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: PATCH: fix crash when --gc-section discard the TLS segment


Hi Tristan,

this following tiny program crashes ld (at least on x86 linux):

Thanks for reporting this bug. In the future, for bugs like this, please could use the bugzilla reporting system:


http://sourceware.org/bugzilla/

Here is a patch.

Great - thanks for creating this, and bonus points for creating a test case too.


bfd:
2007-11-16  Tristan Gingold  <gingold@adacore.com>

* elflink.c (elf_link_output_extsym): Weaken assertion: if --gc-section
is set, there may be no TLS segment.

Approved and applied. (I had to apply it locally to test it, so I decided to check it in myself).


ld/testsuite:
2007-11-16  Tristan Gingold  <gingold@adacore.com>

        * ld-elf/tls_gc.s: New test.
        * ld-elf/elf.exp: Add tls_gc test.

Also approved and applied.


(The set of platforms that should run the test should be updated).

Indeed. In fact what you need is a copy of the check_gc_sections_available from gcc/testsuite/lib/target-supports.exp. So I have done that and add it as the attached patch.


Cheers
  Nick

ld/testsuite/ChangeLog
2007-11-20  Nick Clifton  <nickc@redhat.com>

	* lib/ld-lib.exp (check_gc_sections_available): New proc, based
	on the version in gcc/testsuite/lib/target-supports.exp.
	* lib/ld-elf/eld.exp: Use check_gc_sections_available.
Index: ld/testsuite/lib/ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.51
diff -c -3 -p -r1.51 ld-lib.exp
*** ld/testsuite/lib/ld-lib.exp	4 Sep 2007 14:49:43 -0000	1.51
--- ld/testsuite/lib/ld-lib.exp	20 Nov 2007 15:05:57 -0000
*************** proc run_cc_link_tests { ldtests } {
*** 1535,1537 ****
--- 1535,1579 ----
  	}
      }
  }
+ 
+ # Returns true if --gc-sections is supported on the target.
+ 
+ proc check_gc_sections_available { } {
+     global gc_sections_available_saved
+     global ld
+     
+     if {![info exists gc_sections_available_saved]} {
+ 	# Some targets don't support gc-sections despite whatever's
+ 	# advertised by ld's options.
+ 	if { [istarget alpha*-*-*]
+ 	     || [istarget ia64-*-*] } {
+ 	    set gc_sections_available_saved 0
+ 	    return 0
+ 	}
+ 
+ 	# elf2flt uses -q (--emit-relocs), which is incompatible with
+ 	# --gc-sections.
+ 	if { [board_info target exists ldflags]
+ 	     && [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
+ 	    set gc_sections_available_saved 0
+ 	    return 0
+ 	}
+ 
+ 	# VxWorks kernel modules are relocatable objects linked with -r,
+ 	# while RTP executables are linked with -q (--emit-relocs).
+ 	# Both of these options are incompatible with --gc-sections.
+ 	if { [istarget *-*-vxworks*] } {
+ 	    set gc_sections_available_saved 0
+ 	    return 0
+ 	}
+ 
+ 	# Check if the ld used by gcc supports --gc-sections.
+ 	set ld_output [remote_exec host $ld "--help"]
+ 	if { [ string first "--gc-sections" $ld_output ] >= 0 } {
+ 	    set gc_sections_available_saved 1
+ 	} else {
+ 	    set gc_sections_available_saved 0
+ 	}
+     }
+     return $gc_sections_available_saved
+ }

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