[Skiboot] [PATCH] build: link with --orphan-handling=warn, explicitly place orphan sections

Stewart Smith stewart at linux.ibm.com
Wed Feb 27 16:41:22 AEDT 2019


From: Nicholas Piggin <npiggin at gmail.com>

The linker can warn when the linker script does not explicitly
place all sections. These orphan sections are placed according to
heuristics, which may not always be desirable.

This patch enables orphan section warnings for the final link, and
attempts to do something sane with the orphan sections we currently
have.

---
I rebased this on top of master and it seems to build okay... any reason
not to merge?
---
 Makefile.main |  2 ++
 skiboot.lds.S | 61 +++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/Makefile.main b/Makefile.main
index 096a58d56986..c75aa6a743e0 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -131,6 +131,8 @@ LDFLAGS += -Wl,--no-multi-toc
 LDFLAGS += -mcpu=power7 -mbig-endian -Wl,--oformat,elf64-powerpc
 LDFLAGS_FINAL = -EB -m elf64ppc --no-multi-toc -N --build-id=none --whole-archive
 LDFLAGS_FINAL += -static -nostdlib -pie -Ttext-segment=$(LD_TEXT) --oformat=elf64-powerpc
+LDFLAGS_FINAL += --orphan-handling=warn
+
 LDRFLAGS=-melf64ppc
 # Debug stuff
 #LDFLAGS += -Wl,-v -Wl,-Map,foomap 
diff --git a/skiboot.lds.S b/skiboot.lds.S
index 8d09b40e601c..84a6e489450f 100644
--- a/skiboot.lds.S
+++ b/skiboot.lds.S
@@ -17,6 +17,49 @@
 #include <config.h>
 #include <mem-map.h>
 
+/* Debug sections from binutils `ld --verbose` */
+
+#define DEBUG_SECTIONS							\
+  /* Stabs debugging sections.  */					\
+  .stab          0 : { *(.stab) }					\
+  .stabstr       0 : { *(.stabstr) }					\
+  .stab.excl     0 : { *(.stab.excl) }					\
+  .stab.exclstr  0 : { *(.stab.exclstr) }				\
+  .stab.index    0 : { *(.stab.index) }					\
+  .stab.indexstr 0 : { *(.stab.indexstr) }				\
+  .comment       0 : { *(.comment) }					\
+  /* DWARF debug sections.						\
+     Symbols in the DWARF debugging sections are relative to the beginning \
+     of the section so we begin them at 0.  */				\
+  /* DWARF 1 */								\
+  .debug          0 : { *(.debug) }					\
+  .line           0 : { *(.line) }					\
+  /* GNU DWARF 1 extensions */						\
+  .debug_srcinfo  0 : { *(.debug_srcinfo) }				\
+  .debug_sfnames  0 : { *(.debug_sfnames) }				\
+  /* DWARF 1.1 and DWARF 2 */						\
+  .debug_aranges  0 : { *(.debug_aranges) }				\
+  .debug_pubnames 0 : { *(.debug_pubnames) }				\
+  /* DWARF 2 */								\
+  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }		\
+  .debug_abbrev   0 : { *(.debug_abbrev) }				\
+  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end ) }	\
+  .debug_frame    0 : { *(.debug_frame) }				\
+  .debug_str      0 : { *(.debug_str) }					\
+  .debug_loc      0 : { *(.debug_loc) }					\
+  .debug_macinfo  0 : { *(.debug_macinfo) }				\
+  /* SGI/MIPS DWARF 2 extensions */					\
+  .debug_weaknames 0 : { *(.debug_weaknames) }				\
+  .debug_funcnames 0 : { *(.debug_funcnames) }				\
+  .debug_typenames 0 : { *(.debug_typenames) }				\
+  .debug_varnames  0 : { *(.debug_varnames) }				\
+  /* DWARF 3 */								\
+  .debug_pubtypes 0 : { *(.debug_pubtypes) }				\
+  .debug_ranges   0 : { *(.debug_ranges) }				\
+  /* DWARF Extension.  */						\
+  .debug_macro    0 : { *(.debug_macro) }				\
+  .debug_addr     0 : { *(.debug_addr) }
+
 ENTRY(boot_entry);
 SECTIONS
 {
@@ -56,7 +99,7 @@ SECTIONS
 	_stext = .;
  	.text : {
 		*(.text*)
-		*(.sfpr)
+		*(.sfpr .glink)
 	}
 	_etext = .;
 
@@ -118,10 +161,15 @@ SECTIONS
 		*(.rela*)
 		__rela_dyn_end = .;
 	}
+	.plt    : { *(.plt) *(.iplt) }
 
-	.hash   : { *(.hash)   }
-	.dynsym : { *(.dynsym) }
-	.dynstr : { *(.dynstr) }
+	.hash          : { *(.hash)   }
+	.gnu.hash      : { *(.gnu.hash) }
+	.dynsym        : { *(.dynsym) }
+	.dynstr        : { *(.dynstr) }
+	.gnu.version   : { *(.gnu.version) }
+	.gnu.version_d : { *(.gnu.version_d) }
+	.gnu.version_r : { *(.gnu.version_r) }
 
 	. = ALIGN(0x10);
 	.sym_map : {
@@ -158,12 +206,15 @@ SECTIONS
 
 	_sbss = .;
 	.bss : {
+		*(.dynbss)
 		*(.bss*)
 	}
 	. = ALIGN(0x10000);
 	_ebss = .;
 	_end = .;
 
+	DEBUG_SECTIONS
+
 	/* Optional kernel image */
        . = ALIGN(0x10000);
        .builtin_kernel : {
@@ -174,6 +225,8 @@ SECTIONS
 
 	/* Discards */
 	/DISCARD/ : {
+		*(.note.GNU-stack)
+		*(.eh_frame)
 		*(.comment)
 		*(.interp)
 	}
-- 
2.20.1



More information about the Skiboot mailing list