From 345af2c90a1784fb2c9fe3a5cf1bd92955a370ff Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Sat, 5 Oct 2002 07:20:36 -0500 Subject: [PATCH] kbuild: Put .bss back to the end of vmlinux The kallsyms patches added __kallsyms as last section into vmlinux, behind .bss. This was done to save two additional kallsyms passes, since as the added section was last, it did not change the symbols before it. With the new infrastructure in the top-level Makefile, we do not need to do full relinks for these passes, so they are cheaper. We now use one additional link/kallsyms run to be able to place the __kallsyms section before .bss. The other pass is saved by adding an empty but allocated __kallsyms section in kernel/kallsyms.c, so the first kallsyms pass already generates a section of the final size. --- Makefile | 19 ++++++++++++++++--- arch/i386/vmlinux.lds.S | 8 ++++---- kernel/kallsyms.c | 6 ++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b2550568e5c6..ce499cba9376 100644 --- a/Makefile +++ b/Makefile @@ -312,15 +312,28 @@ endef LDFLAGS_vmlinux += -T arch/$(ARCH)/vmlinux.lds.s # Generate section listing all symbols and add it into vmlinux +# It's a three stage process: +# o .tmp_vmlinux has all symbols and sections, but __kallsyms is +# empty +# Running kallsyms on that gives as .tmp_kallsyms1.o with +# the right size +# o .tmp_vmlinux1 now has a __kallsyms section of the right size, +# but due to the added section, some addresses have shifted +# From here, we generate a correct .tmp_kallsyms.o +# o The correct .tmp_kallsyms.o is linked into the final vmlinux +# below. ifdef CONFIG_KALLSYMS final-objs += .tmp_kallsyms.o quiet_cmd_kallsyms = KSYM $@ -define cmd_kallsyms - $(KALLSYMS) $< > $@ -endef +cmd_kallsyms = \ + $(KALLSYMS) $< > .tmp_kallsyms1.o; \ + $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) .tmp_vmlinux .tmp_kallsyms1.o \ + -o .tmp_vmlinux1; \ + $(KALLSYMS) .tmp_vmlinux1 > $@; \ + rm -f .tmp_kallsyms1.o .tmp_vmlinux1 .tmp_kallsyms.o: .tmp_vmlinux $(call cmd,kallsyms) diff --git a/arch/i386/vmlinux.lds.S b/arch/i386/vmlinux.lds.S index 3afaad74bf2f..09570eab04d8 100644 --- a/arch/i386/vmlinux.lds.S +++ b/arch/i386/vmlinux.lds.S @@ -78,14 +78,14 @@ SECTIONS . = ALIGN(32); .data.cacheline_aligned : { *(.data.cacheline_aligned) } - __bss_start = .; /* BSS */ - .bss : { *(.bss) } - __bss_stop = .; - __start___kallsyms = .; /* All kernel symbols */ __kallsyms : { *(__kallsyms) } __stop___kallsyms = .; + __bss_start = .; /* BSS */ + .bss : { *(.bss) } + __bss_stop = .; + _end = . ; /* Sections to be discarded */ diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 3c168c77d3fe..36d2da107b75 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -225,3 +225,9 @@ int kallsyms_sections(void *token, } return(1); } + +/* Allocate the __kallsyms section, so it's already present in + * the temporary vmlinux that kallsyms is run on, so the first + * run will pick up the section info already. */ + +__asm__(".section __kallsyms,\"a\"\n.previous"); -- 2.39.5