Commit 179ac907a28e4d890314757f921880121642e3e5
Committed by
Greg Kroah-Hartman
1 parent
c2d6598eef
x86, build: replace Perl script with Shell script
commit d69911a68c865b152a067feaa45e98e6bb0f655b upstream. Commit e6023367d779 ("x86, kaslr: Prevent .bss from overlaping initrd") added Perl to the required build environment. This reimplements in shell the Perl script used to find the size of the kernel with bss and brk added. Signed-off-by: Kees Cook <keescook@chromium.org> Reported-by: Rob Landley <rob@landley.net> Acked-by: Rob Landley <rob@landley.net> Cc: Anca Emanuel <anca.emanuel@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Junjie Mao <eternal.n08@gmail.com> Cc: Kees Cook <keescook@chromium.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 3 changed files with 43 additions and 40 deletions Side-by-side Diff
arch/x86/boot/compressed/Makefile
... | ... | @@ -77,7 +77,7 @@ |
77 | 77 | suffix-$(CONFIG_KERNEL_LZ4) := lz4 |
78 | 78 | |
79 | 79 | RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \ |
80 | - perl $(srctree)/arch/x86/tools/calc_run_size.pl) | |
80 | + $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh) | |
81 | 81 | quiet_cmd_mkpiggy = MKPIGGY $@ |
82 | 82 | cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false ) |
83 | 83 |
arch/x86/tools/calc_run_size.pl
1 | -#!/usr/bin/perl | |
2 | -# | |
3 | -# Calculate the amount of space needed to run the kernel, including room for | |
4 | -# the .bss and .brk sections. | |
5 | -# | |
6 | -# Usage: | |
7 | -# objdump -h a.out | perl calc_run_size.pl | |
8 | -use strict; | |
9 | - | |
10 | -my $mem_size = 0; | |
11 | -my $file_offset = 0; | |
12 | - | |
13 | -my $sections=" *[0-9]+ \.(?:bss|brk) +"; | |
14 | -while (<>) { | |
15 | - if (/^$sections([0-9a-f]+) +(?:[0-9a-f]+ +){2}([0-9a-f]+)/) { | |
16 | - my $size = hex($1); | |
17 | - my $offset = hex($2); | |
18 | - $mem_size += $size; | |
19 | - if ($file_offset == 0) { | |
20 | - $file_offset = $offset; | |
21 | - } elsif ($file_offset != $offset) { | |
22 | - # BFD linker shows the same file offset in ELF. | |
23 | - # Gold linker shows them as consecutive. | |
24 | - next if ($file_offset + $mem_size == $offset + $size); | |
25 | - | |
26 | - printf STDERR "file_offset: 0x%lx\n", $file_offset; | |
27 | - printf STDERR "mem_size: 0x%lx\n", $mem_size; | |
28 | - printf STDERR "offset: 0x%lx\n", $offset; | |
29 | - printf STDERR "size: 0x%lx\n", $size; | |
30 | - | |
31 | - die ".bss and .brk are non-contiguous\n"; | |
32 | - } | |
33 | - } | |
34 | -} | |
35 | - | |
36 | -if ($file_offset == 0) { | |
37 | - die "Never found .bss or .brk file offset\n"; | |
38 | -} | |
39 | -printf("%d\n", $mem_size + $file_offset); |
arch/x86/tools/calc_run_size.sh
1 | +#!/bin/sh | |
2 | +# | |
3 | +# Calculate the amount of space needed to run the kernel, including room for | |
4 | +# the .bss and .brk sections. | |
5 | +# | |
6 | +# Usage: | |
7 | +# objdump -h a.out | sh calc_run_size.sh | |
8 | + | |
9 | +NUM='\([0-9a-fA-F]*[ \t]*\)' | |
10 | +OUT=$(sed -n 's/^[ \t0-9]*.b[sr][sk][ \t]*'"$NUM$NUM$NUM$NUM"'.*/\1\4/p') | |
11 | +if [ -z "$OUT" ] ; then | |
12 | + echo "Never found .bss or .brk file offset" >&2 | |
13 | + exit 1 | |
14 | +fi | |
15 | + | |
16 | +OUT=$(echo ${OUT# }) | |
17 | +sizeA=$(printf "%d" 0x${OUT%% *}) | |
18 | +OUT=${OUT#* } | |
19 | +offsetA=$(printf "%d" 0x${OUT%% *}) | |
20 | +OUT=${OUT#* } | |
21 | +sizeB=$(printf "%d" 0x${OUT%% *}) | |
22 | +OUT=${OUT#* } | |
23 | +offsetB=$(printf "%d" 0x${OUT%% *}) | |
24 | + | |
25 | +run_size=$(( $offsetA + $sizeA + $sizeB )) | |
26 | + | |
27 | +# BFD linker shows the same file offset in ELF. | |
28 | +if [ "$offsetA" -ne "$offsetB" ] ; then | |
29 | + # Gold linker shows them as consecutive. | |
30 | + endB=$(( $offsetB + $sizeB )) | |
31 | + if [ "$endB" != "$run_size" ] ; then | |
32 | + printf "sizeA: 0x%x\n" $sizeA >&2 | |
33 | + printf "offsetA: 0x%x\n" $offsetA >&2 | |
34 | + printf "sizeB: 0x%x\n" $sizeB >&2 | |
35 | + printf "offsetB: 0x%x\n" $offsetB >&2 | |
36 | + echo ".bss and .brk are non-contiguous" >&2 | |
37 | + exit 1 | |
38 | + fi | |
39 | +fi | |
40 | + | |
41 | +printf "%d\n" $run_size | |
42 | +exit 0 |