Skip to contentSkip to conversation

x86, build: replace Perl script with Shell script

PATCH In review Kees Cook 2 participants 2 messages Jan 13, 2015 x86

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 x86, build: replace Perl script with Shell script

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.

---
Instead of the proposed "remove recently added perl build requirement" in -mm right now.

---
 arch/x86/boot/compressed/Makefile |  2 +-
 arch/x86/tools/calc_run_size.pl   | 39 ------------------------------------
 arch/x86/tools/calc_run_size.sh   | 42 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 40 deletions(-)
 delete mode 100644 arch/x86/tools/calc_run_size.pl
 create mode 100755 arch/x86/tools/calc_run_size.sh
arch/x86/boot/compressed/Makefile +1 -1
index d999398928bc..ad754b4411f7 100644
@@ -90,7 +90,7 @@ suffix-$(CONFIG_KERNEL_LZO) 	:= lzo
 suffix-$(CONFIG_KERNEL_LZ4) 	:= lz4
 
 RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
-	     perl $(srctree)/arch/x86/tools/calc_run_size.pl)
+	     $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh)
 quiet_cmd_mkpiggy = MKPIGGY $@
       cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false )
 
arch/x86/tools/calc_run_size.pl deleted +0 -39
deleted file mode 100644
index 23210baade2d..000000000000
@@ -1,39 +0,0 @@
-#!/usr/bin/perl
-#
-# Calculate the amount of space needed to run the kernel, including room for
-# the .bss and .brk sections.
-#
-# Usage:
-# objdump -h a.out | perl calc_run_size.pl
-use strict;
-
-my $mem_size = 0;
-my $file_offset = 0;
-
-my $sections=" *[0-9]+ \.(?:bss|brk) +";
-while (<>) {
-	if (/^$sections([0-9a-f]+) +(?:[0-9a-f]+ +){2}([0-9a-f]+)/) {
-		my $size = hex($1);
-		my $offset = hex($2);
-		$mem_size += $size;
-		if ($file_offset == 0) {
-			$file_offset = $offset;
-		} elsif ($file_offset != $offset) {
-			# BFD linker shows the same file offset in ELF.
-			# Gold linker shows them as consecutive.
-			next if ($file_offset + $mem_size == $offset + $size);
-
-			printf STDERR "file_offset: 0x%lx\n", $file_offset;
-			printf STDERR "mem_size: 0x%lx\n", $mem_size;
-			printf STDERR "offset: 0x%lx\n", $offset;
-			printf STDERR "size: 0x%lx\n", $size;
-
-			die ".bss and .brk are non-contiguous\n";
-		}
-	}
-}
-
-if ($file_offset == 0) {
-	die "Never found .bss or .brk file offset\n";
-}
-printf("%d\n", $mem_size + $file_offset);
arch/x86/tools/calc_run_size.sh new file +42 -0

42 lines not on this page · raw message

Signature · 6 lines
1.9.1


-- 
Kees Cook
Chrome OS Security
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Kees Cook

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.

I just noticed earlier today that my version doesn't notice if objdump isn't in the $PATH. (Happens if you're cross compiling and not all binaries prefixed.)

Other than that:

(I don't have a setup with gold to test...)

Rob