From: Vasily Gorbik <gor@linux.ibm.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Miroslav Benes <mbenes@suse.cz>,
Alexandre Chartre <alexandre.chartre@oracle.com>,
Julien Thierry <jthierry@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 2/2] objtool: fix x86 orc generation on big endian cross compiles
Date: Wed, 30 Sep 2020 14:24:23 +0200 [thread overview]
Message-ID: <patch-2.thread-ca645c.git-ca645c336a18.your-ad-here.call-01601468251-ext-3723@work.hours> (raw)
In-Reply-To: <cover.thread-ca645c.your-ad-here.call-01601468251-ext-3723@work.hours>
Correct objtool orc generation endianness problems to enable fully
functional x86 cross compiles on big endian hardware.
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
arch/x86/include/asm/orc_types.h | 24 ++++++++++++++++++++++++
tools/arch/x86/include/asm/orc_types.h | 24 ++++++++++++++++++++++++
tools/objtool/orc_dump.c | 4 ++--
tools/objtool/orc_gen.c | 2 ++
4 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h
index fdbffec4cfde..c72bee8e6ec0 100644
--- a/arch/x86/include/asm/orc_types.h
+++ b/arch/x86/include/asm/orc_types.h
@@ -40,6 +40,13 @@
#define ORC_REG_MAX 15
#ifndef __ASSEMBLY__
+#ifdef __KERNEL__
+#include <linux/swab.h>
+#include <asm/byteorder.h>
+#else
+#include <endian.h>
+#endif
+
/*
* This struct is more or less a vastly simplified version of the DWARF Call
* Frame Information standard. It contains only the necessary parts of DWARF
@@ -48,6 +55,9 @@
* the stack for a given code address. Each instance of the struct corresponds
* to one or more code locations.
*/
+
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
+
struct orc_entry {
s16 sp_offset;
s16 bp_offset;
@@ -57,6 +67,20 @@ struct orc_entry {
unsigned end:1;
} __packed;
+#else
+
+struct orc_entry {
+ s16 sp_offset;
+ s16 bp_offset;
+ unsigned bp_reg:4;
+ unsigned sp_reg:4;
+ unsigned unused:5;
+ unsigned end:1;
+ unsigned type:2;
+} __packed;
+
+#endif
+
#endif /* __ASSEMBLY__ */
#endif /* _ORC_TYPES_H */
diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h
index fdbffec4cfde..c72bee8e6ec0 100644
--- a/tools/arch/x86/include/asm/orc_types.h
+++ b/tools/arch/x86/include/asm/orc_types.h
@@ -40,6 +40,13 @@
#define ORC_REG_MAX 15
#ifndef __ASSEMBLY__
+#ifdef __KERNEL__
+#include <linux/swab.h>
+#include <asm/byteorder.h>
+#else
+#include <endian.h>
+#endif
+
/*
* This struct is more or less a vastly simplified version of the DWARF Call
* Frame Information standard. It contains only the necessary parts of DWARF
@@ -48,6 +55,9 @@
* the stack for a given code address. Each instance of the struct corresponds
* to one or more code locations.
*/
+
+#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
+
struct orc_entry {
s16 sp_offset;
s16 bp_offset;
@@ -57,6 +67,20 @@ struct orc_entry {
unsigned end:1;
} __packed;
+#else
+
+struct orc_entry {
+ s16 sp_offset;
+ s16 bp_offset;
+ unsigned bp_reg:4;
+ unsigned sp_reg:4;
+ unsigned unused:5;
+ unsigned end:1;
+ unsigned type:2;
+} __packed;
+
+#endif
+
#endif /* __ASSEMBLY__ */
#endif /* _ORC_TYPES_H */
diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index 5e6a95368d35..19fa6f65040e 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -197,11 +197,11 @@ int orc_dump(const char *_objname)
printf(" sp:");
- print_reg(orc[i].sp_reg, orc[i].sp_offset);
+ print_reg(orc[i].sp_reg, (s16)le16toh(orc[i].sp_offset));
printf(" bp:");
- print_reg(orc[i].bp_reg, orc[i].bp_offset);
+ print_reg(orc[i].bp_reg, (s16)le16toh(orc[i].bp_offset));
printf(" type:%s end:%d\n",
orc_type_name(orc[i].type), orc[i].end);
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index 235663b96adc..ab9cff93fabd 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -96,6 +96,8 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti
/* populate ORC data */
orc = (struct orc_entry *)u_sec->data->d_buf + idx;
memcpy(orc, o, sizeof(*orc));
+ orc->sp_offset = htole16(orc->sp_offset);
+ orc->bp_offset = htole16(orc->bp_offset);
/* populate reloc for ip */
reloc = malloc(sizeof(*reloc));
--
⣿⣿⣿⣿⢋⡀⣀⠹⣿⣿⣿⣿
⣿⣿⣿⣿⠠⣶⡦⠀⣿⣿⣿⣿
⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿
⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿
⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿
⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
next prev parent reply other threads:[~2020-09-30 12:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 9:58 [RFC PATCH 0/2] objtool and cross compilation Vasily Gorbik
2020-09-30 9:58 ` [RFC PATCH 1/2] objtool: x86 instruction decoder and big endian cross compiles Vasily Gorbik
2020-09-30 9:58 ` [RFC PATCH 2/2] objtool: fix x86 orc generation on " Vasily Gorbik
2020-09-30 10:12 ` [RFC PATCH 0/2] objtool and cross compilation Peter Zijlstra
2020-09-30 12:24 ` [RFC PATCH v2 " Vasily Gorbik
2020-09-30 12:24 ` [RFC PATCH v2 1/2] objtool: x86 instruction decoder and big endian cross compiles Vasily Gorbik
2020-09-30 15:19 ` Josh Poimboeuf
2020-09-30 12:24 ` Vasily Gorbik [this message]
2020-09-30 13:06 ` [RFC PATCH v2 2/2] objtool: fix x86 orc generation on " David Laight
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=patch-2.thread-ca645c.git-ca645c336a18.your-ad-here.call-01601468251-ext-3723@work.hours \
--to=gor@linux.ibm.com \
--cc=alexandre.chartre@oracle.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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 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.