This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: gold script handling of program headers
- From: Ian Lance Taylor <iant at google dot com>
- To: David Miller <davem at davemloft dot net>
- Cc: binutils at sourceware dot org
- Date: Tue, 15 Apr 2008 15:51:29 -0700
- Subject: Re: gold script handling of program headers
- References: <20080415.000059.14392874.davem@davemloft.net>
David Miller <davem@davemloft.net> writes:
> So the resulting offset is 0x403f50, and this is where the bogus
> non-zero this->offset() seen by Output_file_header::do_write() seems
> to come from.
Thanks for the bug report. I committed this patch, which should fix
this problem.
Ian
2008-04-15 Ian Lance Taylor <iant@google.com>
* script-sections.cc (Script_sections::create_segments): Use
header_size_adjustment even when there is enough room for the
headers.
* testsuite/script_test_4.sh: New file.
* testsuite/script_test_4.t: New file.
* testsuite/Makefile.am (check_SCRIPTS): Add script_test_4.sh.
(check_DATA): Add script_test_4.stdout.
(MOSTLYCLEANFILES): Likewise.
(script_test_4): New target.
(script_test_4.stdout): New target.
* testsuite/Makefile.in: Rebuild.
Index: script-sections.cc
===================================================================
RCS file: /cvs/src/src/gold/script-sections.cc,v
retrieving revision 1.12
diff -p -u -r1.12 script-sections.cc
--- script-sections.cc 10 Apr 2008 01:02:46 -0000 1.12
+++ script-sections.cc 15 Apr 2008 22:48:17 -0000
@@ -2706,18 +2706,17 @@ Script_sections::create_segments(Layout*
size_t sizeof_headers = this->total_header_size(layout);
- if ((first_seg->paddr() & (abi_pagesize - 1)) >= sizeof_headers)
- {
- first_seg->set_addresses(first_seg->vaddr() - sizeof_headers,
- first_seg->paddr() - sizeof_headers);
- return first_seg;
- }
-
uint64_t vma = first_seg->vaddr();
uint64_t lma = first_seg->paddr();
uint64_t subtract = this->header_size_adjustment(lma, sizeof_headers);
+ if ((lma & (abi_pagesize - 1)) >= sizeof_headers)
+ {
+ first_seg->set_addresses(vma - subtract, lma - subtract);
+ return first_seg;
+ }
+
// If there is no room to squeeze in the headers, then punt. The
// resulting executable probably won't run on GNU/Linux, but we
// trust that the user knows what they are doing.
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.61
diff -p -u -r1.61 Makefile.am
--- testsuite/Makefile.am 11 Apr 2008 21:24:30 -0000 1.61
+++ testsuite/Makefile.am 15 Apr 2008 22:48:17 -0000
@@ -734,5 +734,13 @@ script_test_3: basic_test.o gcctestdir/l
script_test_3.stdout: script_test_3
$(TEST_READELF) -SlW script_test_3 > script_test_3.stdout
+check_SCRIPTS += script_test_4.sh
+check_DATA += script_test_4.stdout
+MOSTLYCLEANFILES += script_test_4.stdout
+script_test_4: basic_test.o gcctestdir/ld $(srcdir)/script_test_4.t
+ $(CXXLINK) -Bgcctestdir/ basic_test.o -T $(srcdir)/script_test_4.t
+script_test_4.stdout: script_test_4
+ $(TEST_READELF) -SlW script_test_4 > script_test_4.stdout
+
endif GCC
endif NATIVE_LINKER
Index: testsuite/script_test_4.sh
===================================================================
RCS file: testsuite/script_test_4.sh
diff -N testsuite/script_test_4.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/script_test_4.sh 15 Apr 2008 22:48:18 -0000
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# script_test_4.sh -- test load segment
+
+# Copyright 2008 Free Software Foundation, Inc.
+# Written by Ian Lance Taylor <iant@google.com>.
+
+# This file is part of gold.
+
+# This program 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+# This file goes with script_test_4.t, which is a linker script which
+# starts the program at an unaligned address.
+
+check()
+{
+ if ! grep -q "$2" "$1"
+ then
+ echo "Did not find expected segment in $1:"
+ echo " $2"
+ echo ""
+ echo "Actual output below:"
+ cat "$1"
+ exit 1
+ fi
+}
+
+check script_test_4.stdout "\\.interp[ ]*PROGBITS[ ]*10000400"
Index: testsuite/script_test_4.t
===================================================================
RCS file: testsuite/script_test_4.t
diff -N testsuite/script_test_4.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/script_test_4.t 15 Apr 2008 22:48:18 -0000
@@ -0,0 +1,40 @@
+/* script_test_4.t -- linker script test 4 for gold
+
+ Copyright 2008 Free Software Foundation, Inc.
+ Written by Ian Lance Taylor <iant@google.com>.
+
+ This file is part of gold.
+
+ This program 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+/* We won't try to run this program, just ensure that it links
+ as expected. */
+
+SECTIONS
+{
+ . = 0x10000400;
+
+ /* With luck this will be enough to get the program working. */
+ .interp : { *(.interp) }
+ .text : { *(.text) }
+ . += 0x100000;
+ . = ALIGN(0x100);
+ .dynamic : { *(.dynamic) }
+ .data : { *(.data) }
+ . += 0x100000;
+ . = ALIGN(0x100);
+ .bss : { *(.bss) }
+}