Skip to contentSkip to conversation

ARC: module: provide linker script to discard debug sections

PATCH New Vineet Gupta 1 participant 1 message Sep 13, 2016 Synopsys ARC architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARC: module: provide linker script to discard debug sections

The module .ko files seem to bloated due to lot of needless sections, most of which come due to -gdwarf-2 toggle (needed in turn to get .debug_frame which kernel stack unwinder usese).

However there's no reason for the other .debug_* sections, so discard them using arch specific linker script (linker collates module-common.lds and arch specific lds)

For a very simply module using DEBUG_FS

before

| There are 35 section headers, starting at offset 0x205a0:
| ls -sh q_proc.ko
| 132K q_proc.ko

after

| There are 25 section headers, starting at offset 0x205a0:
| ls -sh q_proc.ko
| 8K q_proc.ko
Reported-by Daniel Mentz <danielmentz at google.com>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/Makefile          |  5 +++++
 arch/arc/kernel/module.lds | 12 ++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 arch/arc/kernel/module.lds
arch/arc/Makefile +5 -0
index 85814e74677d..fe1b702f5c69 100644
@@ -97,6 +97,11 @@ LIBGCC	:= $(shell $(CC) $(cflags-y) --print-libgcc-file-name)
 # Modules with short calls might break for calls into builtin-kernel
 KBUILD_CFLAGS_MODULE	+= -mlong-calls -mno-millicode
 
+# toss away debug section, ifdef not allowed in the linker script
+ifndef CONFIG_DEBUG_INFO
+KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arc/kernel/module.lds
+endif
+
 # Finally dump eveything into kernel build system
 KBUILD_CFLAGS	+= $(cflags-y)
 KBUILD_AFLAGS	+= $(KBUILD_CFLAGS)
arch/arc/kernel/module.lds new file +12 -0
new file mode 100644
index 000000000000..c9839be105fc
@@ -0,0 +1,12 @@
+SECTIONS
+{
+	/DISCARD/ : { *(.debug_aranges) }
+	/DISCARD/ : { *(.debug_pubnames) }
+	/DISCARD/ : { *(.debug_info) }
+	/DISCARD/ : { *(.debug_abbrev) }
+	/DISCARD/ : { *(.debug_line) }
+	/DISCARD/ : { *(.debug_str) }
+	/DISCARD/ : { *(.debug_loc) }
+	/DISCARD/ : { *(.debug_macinfo) }
+	/DISCARD/ : { *(.debug_ranges) }
+}
Signature · 1 line
2.7.4