Linux 4.6-rc6
[linux/fpc-iii.git] / arch / x86 / tools / calc_run_size.sh
blob1a4c17bb39108264dc33e7e2fea61ad1708ff296
1 #!/bin/sh
3 # Calculate the amount of space needed to run the kernel, including room for
4 # the .bss and .brk sections.
6 # Usage:
7 # objdump -h a.out | sh calc_run_size.sh
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
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%% *})
25 run_size=$(( $offsetA + $sizeA + $sizeB ))
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
41 printf "%d\n" $run_size
42 exit 0