All of lore.kernel.org
 help / color / mirror / Atom feed
* Detecting endianness in scripts/recordmcount.pl?
@ 2008-11-26  8:39 Paul Mundt
  2008-11-26  9:17 ` Paul Mundt
  2008-11-26 13:54 ` Sam Ravnborg
  0 siblings, 2 replies; 6+ messages in thread
From: Paul Mundt @ 2008-11-26  8:39 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel

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.

The CONFIG_64BIT test could likewise be adopted for testing endianness, but
not all architectures have config options for endian selections. Likewise, a
simple test program to check if __LITTLE_ENDIAN is set or not won't work
without having knowledge of KBUILD_CFLAGS, in which case it seems saner just
to pass it off as a starting point.

Any better ideas?

---

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 7a17677..de2cc42 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -201,7 +201,8 @@ endif
 ifdef CONFIG_FTRACE_MCOUNT_RECORD
 cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
 	"$(if $(CONFIG_64BIT),64,32)" \
-	"$(OBJDUMP)" "$(OBJCOPY)" "$(CC)" "$(LD)" "$(NM)" "$(RM)" "$(MV)" "$(@)";
+	"$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \
+	"$(LD) $(ld_flags)" "$(NM)" "$(RM)" "$(MV)" "$(@)";
 endif
 
 define rule_cc_o_c

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Detecting endianness in scripts/recordmcount.pl?
  2008-11-26  8:39 Detecting endianness in scripts/recordmcount.pl? Paul Mundt
@ 2008-11-26  9:17 ` Paul Mundt
  2008-11-26 12:24   ` Steven Rostedt
  2008-11-26 13:54 ` Sam Ravnborg
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Mundt @ 2008-11-26  9:17 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar, linux-kernel

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";
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Detecting endianness in scripts/recordmcount.pl?
  2008-11-26  9:17 ` Paul Mundt
@ 2008-11-26 12:24   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2008-11-26 12:24 UTC (permalink / raw)
  To: Paul Mundt; +Cc: Ingo Molnar, linux-kernel


On Wed, 26 Nov 2008, Paul Mundt wrote:

> 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);

I'll turn this into a function and only run it on those archs that need 
it. This is executed on all C files, and we do not want to punish those
archs that have a single endian.

-- Steve

> +
>  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";
>  }
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Detecting endianness in scripts/recordmcount.pl?
  2008-11-26  8:39 Detecting endianness in scripts/recordmcount.pl? Paul Mundt
  2008-11-26  9:17 ` Paul Mundt
@ 2008-11-26 13:54 ` Sam Ravnborg
  2008-11-26 17:13   ` Steven Rostedt
  1 sibling, 1 reply; 6+ messages in thread
From: Sam Ravnborg @ 2008-11-26 13:54 UTC (permalink / raw)
  To: Paul Mundt, Steven Rostedt, Ingo Molnar, linux-kernel

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.
> 
> The CONFIG_64BIT test could likewise be adopted for testing endianness, but
> not all architectures have config options for endian selections.
But we could add this - no?
Much better than executing objdump one thousand times.

	Sam

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Detecting endianness in scripts/recordmcount.pl?
  2008-11-26 13:54 ` Sam Ravnborg
@ 2008-11-26 17:13   ` Steven Rostedt
  2008-11-26 17:39     ` Sam Ravnborg
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2008-11-26 17:13 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Paul Mundt, Ingo Molnar, linux-kernel


On Wed, 26 Nov 2008, Sam Ravnborg wrote:

> 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.
> > 
> > The CONFIG_64BIT test could likewise be adopted for testing endianness, but
> > not all architectures have config options for endian selections.
> But we could add this - no?
> Much better than executing objdump one thousand times.

Adding a parameter would be better.

-- Steve


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Detecting endianness in scripts/recordmcount.pl?
  2008-11-26 17:13   ` Steven Rostedt
@ 2008-11-26 17:39     ` Sam Ravnborg
  0 siblings, 0 replies; 6+ messages in thread
From: Sam Ravnborg @ 2008-11-26 17:39 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Paul Mundt, Ingo Molnar, linux-kernel

> > > 
> > > The CONFIG_64BIT test could likewise be adopted for testing endianness, but
> > > not all architectures have config options for endian selections.
> > But we could add this - no?
> > Much better than executing objdump one thousand times.
> 
> Adding a parameter would be better.

Which moves the problem to the caller which is OK.
And then we are back to the same discussion and again we should
introduce a CONFIG_ symbol for it.

	Sam

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-11-26 17:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-26  8:39 Detecting endianness in scripts/recordmcount.pl? Paul Mundt
2008-11-26  9:17 ` Paul Mundt
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.