public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sylvain BERTRAND <sylvain.bertrand@gmail.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/3] x86: tools: shell-ify calc_run_size perl-ism
Date: Wed, 31 Dec 2014 17:43:06 +0100	[thread overview]
Message-ID: <20141231164306.GA1872@dhcppc1> (raw)


Add the shell script.

Signed-off-by: Sylvain BERTRAND <sylvain.bertrand@gmail.com>
---
--- arch/x86/tools/calc_run_size.sh
+++ arch/x86/tools/calc_run_size.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Calculate the amount of space needed to run the kernel, including room for
+# the .bss and .brk sections.
+#
+# Usage:
+# objdump -h a.out | sh calc_run_size.sh
+
+set -e
+
+file_offset=0
+mem_size=0
+
+while read Idx Name Size_hex VMA_hex LMA_hex File_off_hex Algn
+do
+	if [ "$Name" = ".bss" -o "$Name" = ".brk" ]; then
+		Size=$((0x$Size_hex))
+		File_off=$((0x$File_off_hex))
+
+		mem_size=$(($mem_size + $Size))
+
+		if [ $file_offset -eq 0 ]; then
+			file_offset=$File_off
+		elif [ $file_offset -ne $File_off ]; then
+			# BFD linker shows the same file offset in ELF.
+			# Gold linker shows them as consecutive.
+			if [ $(($file_offset + $mem_size)) -eq $(($File_off + $Size)) ]; then
+				continue
+			fi
+			
+			printf "file_offset: 0x%x\n" $file_offset >&2
+			printf "mem_size: 0x%x\n" $mem_size >&2
+			printf "offset: 0x%x\n" $File_off >&2
+			printf "size: 0x%x\n" $Size >&2
+
+			echo ".bss and .brk are non-contiguous" >&2
+			exit 1
+		fi
+	fi
+done
+
+if [ $file_offset -eq 0 ]; then
+	echo "Never found .bss or .brk file offset" >&2
+	exit 1
+fi
+printf "%d\n" $(($mem_size + $file_offset))

                 reply	other threads:[~2014-12-31 16:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141231164306.GA1872@dhcppc1 \
    --to=sylvain.bertrand@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox