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

Message ID 20180325071057.15646-1-npiggin@gmail.com
State New
Headers show
Series
  • [RFC] build: link with --orphan-handling=warn, explicitly place orphan sections
Related show

Commit Message

Nicholas Piggin March 25, 2018, 7:10 a.m.
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. This should be at least 2 patches, but I'll just ask for comments
first.

Thanks,
Nick
---
 Makefile.main |  3 ++-
 skiboot.lds.S | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 5 deletions(-)

Patch

diff --git a/Makefile.main b/Makefile.main
index 96836384..3b69f4f5 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -126,7 +126,8 @@  LDFLAGS += -Wl,-pie
 LDFLAGS += -Wl,-Ttext-segment,$(LD_TEXT) -Wl,-N -Wl,--build-id=none
 LDFLAGS += -Wl,--no-multi-toc
 LDFLAGS += -mcpu=power7 -mbig-endian -Wl,--oformat,elf64-powerpc
-LDFLAGS_FINAL = $(LDFLAGS) -Wl,--whole-archive
+LDFLAGS_FINAL = $(LDFLAGS) -Wl,--whole-archive -Wl,--orphan-handling=warn
+
 LDRFLAGS=-melf64ppc
 # Debug stuff
 #LDFLAGS += -Wl,-v -Wl,-Map,foomap 
diff --git a/skiboot.lds.S b/skiboot.lds.S
index a6e71077..edadd93c 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
 {
@@ -55,7 +98,7 @@  SECTIONS
 	_stext = .;
  	.text : {
 		*(.text*)
-		*(.sfpr)
+		*(.sfpr .glink)
 	}
 	_etext = .;
 
@@ -134,10 +177,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 : {
@@ -151,12 +199,15 @@  SECTIONS
 
 	_sbss = .;
 	.bss : {
+		*(.dynbss)
 		*(.bss*)
 	}
 	. = ALIGN(0x10000);
 	_ebss = .;
 	_end = .;
 
+	DEBUG_SECTIONS
+
 	/* Optional kernel image */
        . = ALIGN(0x10000);
        .builtin_kernel : {
@@ -167,6 +218,8 @@  SECTIONS
 
 	/* Discards */
 	/DISCARD/ : {
+		*(.note.GNU-stack)
+		*(.eh_frame)
 		*(.comment)
 		*(.interp)
 	}