The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Paul Mundt <lethal@linux-sh.org>
To: Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org
Subject: Re: Detecting endianness in scripts/recordmcount.pl?
Date: Wed, 26 Nov 2008 18:17:52 +0900	[thread overview]
Message-ID: <20081126091752.GA21466@linux-sh.org> (raw)
In-Reply-To: <20081126083905.GA20472@linux-sh.org>

On Wed, Nov 26, 2008 at 05:39:05PM +0900, Paul Mundt wrote:
> Presently there doesn't seem to be any way to determine whether the
> target is big or little endian, and it is assumed that the compiler will
> do the right thing by default. Unfortunately this can not be assumed,
> and mismatches ensue, resulting in the linker bailing out.
> 
> The only obvious solution I saw was to pass in KBUILD_CFLAGS and ld_flags
> along with $(CC) and $(LD) to the script, and killing off the hardcoded
> flags. This at least gets things building, but that still leaves objcopy
> and objdump as the odd ones out. On the other hand, the format can be figured
> out by objdumping the object and reading in the file format line, but people
> obviously do not have consistent naming for these, and a double-pass would
> be needed -- once for establishing little or big, followed by figuring out
> which set of regexes to use.
> 
This is roughly what I had in mind for the objdump test, perhaps
something like this could be reimplemented by someone who knows something
about perl?

---

diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index c67cec8..177f4ee 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -143,6 +143,20 @@ if ($arch eq "x86") {
     }
 }
 
+open(IN, "$objdump -p $inputfile|") || die "error running $objdump";
+
+my $endian = "little";
+
+while (<IN>) {
+	next if /^(\s)*$/;
+	s/^.*file format //g;
+	if (/big/) {
+		$endian = "big";
+	}
+	last;
+}
+close(IN);
+
 if ($arch eq "x86_64") {
     $section_regex = "Disassembly of section\\s+(\\S+):";
     $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
@@ -174,10 +188,15 @@ if ($arch eq "x86_64") {
     $type = ".long";
 
     # force flags for this arch
-    $ld .= " -m shlelf_linux";
-    $objcopy .= " -O elf32-sh-linux";
-    $cc .= " -m32";
-
+    if ($endian eq "big") {
+	    $ld .= " -m shelf_linux";
+	    $objcopy .= " -O elf32-shbig-linux";
+	    $cc .= " -mb";
+    } else {
+            $ld .= " -m shlelf_linux";
+            $objcopy .= " -O elf32-sh-linux";
+            $cc .= " -ml";
+    }
 } else {
     die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
 }

  reply	other threads:[~2008-11-26  9:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-26  8:39 Detecting endianness in scripts/recordmcount.pl? Paul Mundt
2008-11-26  9:17 ` Paul Mundt [this message]
2008-11-26 12:24   ` Steven Rostedt
2008-11-26 13:54 ` Sam Ravnborg
2008-11-26 17:13   ` Steven Rostedt
2008-11-26 17:39     ` Sam Ravnborg

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=20081126091752.GA21466@linux-sh.org \
    --to=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.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