Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys work around a binutils bug where converting ELF kernels ...



details:   https://anonhg.NetBSD.org/src/rev/f676680e2ce8
branches:  trunk
changeset: 569905:f676680e2ce8
user:      chs <chs%NetBSD.org@localhost>
date:      Mon Sep 13 09:39:40 2004 +0000

description:
work around a binutils bug where converting ELF kernels to a.out with objcopy
produces corrupted binaries when the link_set_* sections extend into another
page after the end of the .text section by using a generated an ldscript that
puts all the link_set_* data into the .text section in the first place.

diffstat:

 sys/arch/arm/conf/kern.ldscript.head   |  17 ++++++++++++++++
 sys/arch/arm/conf/kern.ldscript.tail   |  35 ++++++++++++++++++++++++++++++++++
 sys/arch/arm/conf/mkldscript.sh        |  15 ++++++++++++++
 sys/arch/cats/conf/Makefile.cats.inc   |  11 ++++++++-
 sys/arch/shark/conf/Makefile.shark.inc |  11 ++++++++-
 sys/conf/Makefile.kern.inc             |   3 +-
 6 files changed, 87 insertions(+), 5 deletions(-)

diffs (148 lines):

diff -r 6f213a27497d -r f676680e2ce8 sys/arch/arm/conf/kern.ldscript.head
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/conf/kern.ldscript.head      Mon Sep 13 09:39:40 2004 +0000
@@ -0,0 +1,17 @@
+/*     $NetBSD: kern.ldscript.head,v 1.1 2004/09/13 09:39:40 chs Exp $ */
+
+OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
+             "elf32-littlearm")
+OUTPUT_ARCH(arm)
+SECTIONS
+{
+  . = 0xf0000020;      /* 0x20 == sizeof(a.out header) */
+
+  /* Read-only sections, merged into text segment: */
+  .text :
+  {
+    *(.text)
+    *(.text.*)
+    *(.stub)
+    *(.glue_7t) *(.glue_7)
+    *(.rodata) *(.rodata.*)
diff -r 6f213a27497d -r f676680e2ce8 sys/arch/arm/conf/kern.ldscript.tail
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/conf/kern.ldscript.tail      Mon Sep 13 09:39:40 2004 +0000
@@ -0,0 +1,35 @@
+/*     $NetBSD: kern.ldscript.tail,v 1.1 2004/09/13 09:39:40 chs Exp $ */
+
+  } =0
+  PROVIDE (__etext = .);
+  PROVIDE (_etext = .);
+  PROVIDE (etext = .);
+  . = ALIGN(0x1000);
+  .data :
+  {
+    __data_start = . ;
+    *(.data)
+    *(.data.*)
+    *(.sdata)
+    *(.sdata.*)
+  }
+  _edata = .;
+  PROVIDE (edata = .);
+  __bss_start = .;
+  __bss_start__ = .;
+  .bss       :
+  {
+   *(.dynbss)
+   *(.bss)
+   *(.bss.*)
+   *(COMMON)
+   /* Align here to ensure that the .bss section occupies space up to
+      _end.  Align after .bss to ensure correct alignment even if the
+      .bss section disappears because there are no input sections.  */
+   . = ALIGN(32 / 8);
+  }
+  . = ALIGN(32 / 8);
+  _end = .;
+  _bss_end__ = . ; __bss_end__ = . ; __end__ = . ;
+  PROVIDE (end = .);
+}
diff -r 6f213a27497d -r f676680e2ce8 sys/arch/arm/conf/mkldscript.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/conf/mkldscript.sh   Mon Sep 13 09:39:40 2004 +0000
@@ -0,0 +1,15 @@
+#!/bin/sh
+#      $NetBSD: mkldscript.sh,v 1.1 2004/09/13 09:39:40 chs Exp $
+
+TEMPLATE=$1
+shift
+
+SETS=`$OBJDUMP -x $* | fgrep "RELOCATION RECORDS FOR [link_set" | \
+        sort -u | sed 's/^.*\[\(.*\)\]:$/\1/'`
+
+for s in $SETS; do
+        printf "    . = ALIGN(4);\n"
+        printf "    PROVIDE (__start_%s = .);\n" $s
+        printf "    *(%s)\n" $s
+        printf "    PROVIDE (__stop_%s = .);\n" $s
+done 
diff -r 6f213a27497d -r f676680e2ce8 sys/arch/cats/conf/Makefile.cats.inc
--- a/sys/arch/cats/conf/Makefile.cats.inc      Mon Sep 13 08:32:19 2004 +0000
+++ b/sys/arch/cats/conf/Makefile.cats.inc      Mon Sep 13 09:39:40 2004 +0000
@@ -1,5 +1,6 @@
-#      $NetBSD: Makefile.cats.inc,v 1.15 2003/10/04 15:43:05 chris Exp $
+#      $NetBSD: Makefile.cats.inc,v 1.16 2004/09/13 09:39:40 chs Exp $
 
+MACHINE_ARCH=  arm
 CPPFLAGS+=     -D${MACHINE}
 
 .if (${OBJECT_FMT} == "ELF")
@@ -12,7 +13,13 @@
 # Need to convert the kernel from ELF to a.out so that the firmware
 # can load it.
 
-LINKFLAGS=     -T ${THISARM}/conf/kern.ldscript
+LINKFLAGS=     -T ldscript
+
+SYSTEM_LD_HEAD_EXTRA+=; \
+       ( cat ${ARM}/conf/kern.ldscript.head ; \
+         OBJDUMP=${OBJDUMP} ${HOST_SH} ${ARM}/conf/mkldscript.sh \
+               ${SYSTEM_OBJ} ; \
+         cat ${ARM}/conf/kern.ldscript.tail ) > ldscript
 
 SYSTEM_LD_TAIL_EXTRA+=; \
        echo "${DBSYM} $@ || true"; \
diff -r 6f213a27497d -r f676680e2ce8 sys/arch/shark/conf/Makefile.shark.inc
--- a/sys/arch/shark/conf/Makefile.shark.inc    Mon Sep 13 08:32:19 2004 +0000
+++ b/sys/arch/shark/conf/Makefile.shark.inc    Mon Sep 13 09:39:40 2004 +0000
@@ -1,5 +1,6 @@
-#      $NetBSD: Makefile.shark.inc,v 1.4 2003/09/21 00:20:28 matt Exp $
+#      $NetBSD: Makefile.shark.inc,v 1.5 2004/09/13 09:39:40 chs Exp $
 
+MACHINE_ARCH=          arm
 CPPFLAGS+=             -D${MACHINE}
 GENASSYM_EXTRAS+=      ${THISARM}/shark/genassym.cf
 
@@ -7,7 +8,13 @@
 # Need to convert the kernel from ELF to a.out so that OpenFirmware
 # can load it.
 
-LINKFLAGS=     -T ${THISARM}/conf/kern.ldscript
+LINKFLAGS=     -T ldscript
+
+SYSTEM_LD_HEAD_EXTRA+=; \
+       ( cat ${ARM}/conf/kern.ldscript.head ; \
+         OBJDUMP=${OBJDUMP} ${HOST_SH} ${ARM}/conf/mkldscript.sh \
+               ${SYSTEM_OBJ} ; \
+         cat ${ARM}/conf/kern.ldscript.tail ) > ldscript
 
 SYSTEM_LD_TAIL_EXTRA+=; \
        echo "${DBSYM} $@ || true"; \
diff -r 6f213a27497d -r f676680e2ce8 sys/conf/Makefile.kern.inc
--- a/sys/conf/Makefile.kern.inc        Mon Sep 13 08:32:19 2004 +0000
+++ b/sys/conf/Makefile.kern.inc        Mon Sep 13 09:39:40 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.kern.inc,v 1.56 2004/07/31 00:55:51 lukem Exp $
+#      $NetBSD: Makefile.kern.inc,v 1.57 2004/09/13 09:39:40 chs Exp $
 #
 # This file contains common `MI' targets and definitions and it is included
 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
@@ -203,6 +203,7 @@
 LINKFLAGS+=    ${LINKFLAGS_NORMAL}
 .endif
 
+SYSTEM_LD_HEAD+=${SYSTEM_LD_HEAD_EXTRA}
 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
 
 ##



Home | Main Index | Thread Index | Old Index