Skip to content

Commit 61f3f8f

Browse files
Philipp RudoMartin Schwidefsky
authored andcommitted
s390/purgatory: Reduce purgatory size
The purgatory is compiled into the vmlinux and keept in memory all the time during runtime. Thus any section not needed to load the purgatory unnecessarily bloats up its foot print in file- and memorysize. Reduce the purgatory size by stripping the unneeded sections from the purgatory. This reduces the purgatories size by ~33%. Signed-off-by: Philipp Rudo <prudo@linux.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 729829d commit 61f3f8f

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

arch/s390/purgatory/Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OBJECT_FILES_NON_STANDARD := y
44

55
purgatory-y := head.o purgatory.o string.o sha256.o mem.o
66

7-
targets += $(purgatory-y) purgatory.ro kexec-purgatory.c
7+
targets += $(purgatory-y) purgatory.lds purgatory purgatory.ro kexec-purgatory.c
88
PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
99

1010
$(obj)/sha256.o: $(srctree)/lib/sha256.c FORCE
@@ -16,18 +16,24 @@ $(obj)/mem.o: $(srctree)/arch/s390/lib/mem.S FORCE
1616
$(obj)/string.o: $(srctree)/arch/s390/lib/string.c FORCE
1717
$(call if_changed_rule,cc_o_c)
1818

19-
LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib
20-
LDFLAGS_purgatory.ro += -z nodefaultlib
2119
KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes
2220
KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare
2321
KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding
2422
KBUILD_CFLAGS += -c -MD -Os -m64 -msoft-float -fno-common
2523
KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
2624
KBUILD_AFLAGS := $(filter-out -DCC_USING_EXPOLINE,$(KBUILD_AFLAGS))
2725

28-
$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
26+
LDFLAGS_purgatory := -r --no-undefined -nostdlib -z nodefaultlib -T
27+
$(obj)/purgatory: $(obj)/purgatory.lds $(PURGATORY_OBJS) FORCE
2928
$(call if_changed,ld)
3029

30+
OBJCOPYFLAGS_purgatory.ro := -O elf64-s390
31+
OBJCOPYFLAGS_purgatory.ro += --remove-section='*debug*'
32+
OBJCOPYFLAGS_purgatory.ro += --remove-section='.comment'
33+
OBJCOPYFLAGS_purgatory.ro += --remove-section='.note.*'
34+
$(obj)/purgatory.ro: $(obj)/purgatory FORCE
35+
$(call if_changed,objcopy)
36+
3137
quiet_cmd_bin2c = BIN2C $@
3238
cmd_bin2c = $(objtree)/scripts/bin2c kexec_purgatory < $< > $@
3339

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#include <asm-generic/vmlinux.lds.h>
4+
5+
OUTPUT_FORMAT("elf64-s390", "elf64-s390", "elf64-s390")
6+
OUTPUT_ARCH(s390:64-bit)
7+
8+
ENTRY(purgatory_start)
9+
10+
SECTIONS
11+
{
12+
. = 0;
13+
.head.text : {
14+
_head = . ;
15+
HEAD_TEXT
16+
_ehead = . ;
17+
}
18+
.text : {
19+
_text = .; /* Text */
20+
*(.text)
21+
*(.text.*)
22+
_etext = . ;
23+
}
24+
.rodata : {
25+
_rodata = . ;
26+
*(.rodata) /* read-only data */
27+
*(.rodata.*)
28+
_erodata = . ;
29+
}
30+
.data : {
31+
_data = . ;
32+
*(.data)
33+
*(.data.*)
34+
_edata = . ;
35+
}
36+
37+
. = ALIGN(256);
38+
.bss : {
39+
_bss = . ;
40+
*(.bss)
41+
*(.bss.*)
42+
*(COMMON)
43+
. = ALIGN(8); /* For convenience during zeroing */
44+
_ebss = .;
45+
}
46+
_end = .;
47+
48+
/* Sections to be discarded */
49+
/DISCARD/ : {
50+
*(.eh_frame)
51+
*(*__ksymtab*)
52+
*(___kcrctab*)
53+
}
54+
}

0 commit comments

Comments
 (0)