This is the mail archive of the binutils@sources.redhat.com 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: Bug in >64k-section ELF handling when linking (with -r)


> Date: Sat, 2 Nov 2002 23:12:40 +1030
> From: Alan Modra <amodra@bigpond.net.au>

> Oh dear.  elf_bfd_final_link sets up symtab_hdr but not
> symtab_shndx_hdr.  I guess I never tested >64k section support with
> ld -r.

Hmm, not just ld -r.  The trivial test below failed for a "trivial" link
too.

>  Would you mind running your test case with the following
> patch applied?  If it passes, please commit the patch for me.

That's the fix I was looking for! ... but unfortunately it
doesn't let the original case pass (after 10 hours; not analyzed
in detail) or (thankfully) the simplified test below.  There's
heap corruption with the test-case below and -r; it had run for
more than an hour when I attached gdb and saw it was stuck in
chunk_free (YMMV of course).  I've thrown valgrind on it; let's
see what comes out.

This patch adds two test-cases.  Note that it takes a few
minutes to even get to ldwrite on a 1GHz Athlon model 4 for the
-r case.  (Performance problem; todo for another day I guess.)
I'll commit this (if/when I get ok to the ld-lib.exp change) to
ld-cris in a few days, with sanity checks for presence of
64k-sections replacing the "#pass":es.  Though I'd prefer to add
it to e.g. a new generic dir ld-elf, decorated to avoid
non-applicable targets as in ld-linkonce/linkonce.exp.  Ok to
commit the ld-lib.exp change?  Would you prefer the tests in
ld-elf/sec64k.exp?  Perhaps best anyway to wait after a fix is
committed; having test-suite runs hanging is inproductive.

ld/testsuite:
	* ld-cris/sec64k.exp: New tests.
	* lib/ld-lib.exp (run_dump_test): Don't prepend "$srcdir/$subdir/"
	to a source file starting with "/".

Index: ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.16
diff -p -c -r1.16 ld-lib.exp
*** ld-lib.exp	27 Sep 2002 19:29:17 -0000	1.16
--- ld-lib.exp	3 Nov 2002 00:40:35 -0000
*************** proc run_dump_test { name } {
*** 678,684 ****
      } else {
  	set sourcefiles {}
  	foreach sf $opts(source) {
! 	    lappend sourcefiles "$srcdir/$subdir/$sf"
  	    # Must have asflags indexed on source name.
  	    set asflags($srcdir/$subdir/$sf) $asflags($sf)
  	}
--- 678,688 ----
      } else {
  	set sourcefiles {}
  	foreach sf $opts(source) {
! 	    if { [string match "/*" $sf] } {
! 		lappend sourcefiles "$sf"
! 	    } {
! 		lappend sourcefiles "$srcdir/$subdir/$sf"
! 	    }
  	    # Must have asflags indexed on source name.
  	    set asflags($srcdir/$subdir/$sf) $asflags($sf)
  	}
--- /dev/null	Tue Jan  1 05:00:00 1980
+++ ld-cris/sec64k.exp	Sat Nov  2 18:28:51 2002
@@ -0,0 +1,96 @@
+# Expect script for tests for >64k sections
+#   Copyright 2002 Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Written by Hans-Peter Nilsson (hp@axis.com)
+#
+
+if ![istarget cris-*-*] {
+    return
+}
+
+# Test >64k sections, with and without -r.  First, create the assembly
+# files.  Have a relocation to another section and one within the local
+# section.
+
+set test1 "64ksec-r"
+set test2 "64ksec"
+
+if { ![runtest_file_p $runtests $test1] \
+	&& ![runtest_file_p $runtests $test2] } {
+    return
+}
+
+set sfiles {}
+set maxj 1000
+for { set i 0 } { $i < 66 } { incr i } {
+    set sfile "$objdir/tmpdir/sec64-$i.s"
+    lappend sfiles $sfile
+    if [catch { set ofd [open $sfile w] } x] {
+	perror "$x"
+	unresolved $test1
+	unresolved $test2
+	return
+    }
+
+    if { $i == 0 } {
+	puts $ofd " .global _start"
+	puts $ofd "_start:"
+	puts $ofd " .global foo_0"
+	puts $ofd "foo_0: .long 0"
+    }
+
+    for { set j 0 } { $j < $maxj } { incr j } {
+	set ij [expr $i * $maxj + $j + 1]
+	puts $ofd " .section .foo.$ij,\"ax\""
+	puts $ofd " .global foo_$ij"
+	puts $ofd "foo_$ij:"
+	puts $ofd " .long foo_[expr $ij - 1]"
+	puts $ofd "bar_$ij:"
+	puts $ofd " .long bar_$ij"
+    }
+
+    close $ofd
+}
+
+if [catch { set ofd [open "tmpdir/$test1.d" w] } x] {
+    perror "$x"
+    unresolved $test1
+    unresolved $test2
+    return
+}
+# The ld-r linked file will contain relocation-sections too, so make it
+# half the size in order to try and keep the test-time down.
+foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] {
+    puts $ofd "#source: $sfile"
+}
+puts $ofd "#ld: -r"
+puts $ofd "#readelf: -Ss"
+puts $ofd "#pass"
+close $ofd
+run_dump_test "tmpdir/$test1"
+
+if [catch { set ofd [open "tmpdir/$test2.d" w] } x] {
+    perror "$x"
+    unresolved $test2
+    return
+}
+foreach sfile $sfiles { puts $ofd "#source: $sfile" }
+puts $ofd "#ld:"
+puts $ofd "#readelf: -Ss"
+puts $ofd "#pass"
+close $ofd
+run_dump_test "tmpdir/$test2"


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