Re: [tip: objtool/core] x86/insn: Support big endian cross-compiles

From: Borislav Petkov
Date: Fri Oct 09 2020 - 16:49:37 EST


On Fri, Oct 09, 2020 at 10:38:22PM +0200, Peter Zijlstra wrote:
> On Wed, Oct 07, 2020 at 04:20:19PM -0000, tip-bot2 for Martin Schwidefsky wrote:
> > The following commit has been merged into the objtool/core branch of tip:
> >
> > Commit-ID: 2a522b53c47051d3bf98748418f4f8e5f20d2c04
> > Gitweb: https://git.kernel.org/tip/2a522b53c47051d3bf98748418f4f8e5f20d2c04
> > Author: Martin Schwidefsky <schwidefsky@xxxxxxxxxx>
> > AuthorDate: Mon, 05 Oct 2020 17:50:31 +02:00
> > Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> > CommitterDate: Tue, 06 Oct 2020 09:32:29 -05:00
> >
> > x86/insn: Support big endian cross-compiles
> >
> > x86 instruction decoder code is shared across the kernel source and the
> > tools. Currently objtool seems to be the only tool from build tools needed
> > which breaks x86 cross compilation on big endian systems. Make the x86
> > instruction decoder build host endianness agnostic to support x86 cross
> > compilation and enable objtool to implement endianness awareness for
> > big endian architectures support.
> >
> > Signed-off-by: Martin Schwidefsky <schwidefsky@xxxxxxxxxx>
> > Co-developed-by: Vasily Gorbik <gor@xxxxxxxxxxxxx>
> > Signed-off-by: Vasily Gorbik <gor@xxxxxxxxxxxxx>
> > Acked-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
> > Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
>
> This commit breaks the x86 build with CONFIG_X86_DECODER_SELFTEST=y.
>
> I've asked Boris to truncate tip/objtool/core.

Yeah, top 4 are gone until this is resolved.

What I would suggest is to have a look at how tools/ headers are kept
separate from kernel proper ones, see tools/include/ and how those
headers there are full of dummy definitions just so it builds.

And then including a global one like linux/kernel.h is just looking for
trouble:

In file included from ./include/uapi/linux/byteorder/little_endian.h:12,
from ./include/linux/byteorder/little_endian.h:5,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./tools/include/linux/types.h:30:18: error: conflicting types for ‘u64’
30 | typedef uint64_t u64;
| ^~~
In file included from /usr/include/asm-generic/types.h:7,
from /usr/include/x86_64-linux-gnu/asm/types.h:1,
from ./tools/include/linux/types.h:10,
from ./include/uapi/linux/byteorder/little_endian.h:12,
from ./include/linux/byteorder/little_endian.h:5,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/asm-generic/int-ll64.h:23:15: note: previous declaration of ‘u64’ was here
23 | typedef __u64 u64;
| ^~~
In file included from ./include/uapi/linux/byteorder/little_endian.h:12,
from ./include/linux/byteorder/little_endian.h:5,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./tools/include/linux/types.h:31:17: error: conflicting types for ‘s64’
31 | typedef int64_t s64;
| ^~~
In file included from /usr/include/asm-generic/types.h:7,
from /usr/include/x86_64-linux-gnu/asm/types.h:1,
from ./tools/include/linux/types.h:10,
from ./include/uapi/linux/byteorder/little_endian.h:12,
from ./include/linux/byteorder/little_endian.h:5,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/asm-generic/int-ll64.h:22:15: note: previous declaration of ‘s64’ was here
22 | typedef __s64 s64;
| ^~~
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:87: warning: "cpu_to_le16" redefined
87 | #define cpu_to_le16
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:90: note: this is the location of the previous definition
90 | #define cpu_to_le16 __cpu_to_le16
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:88: warning: "cpu_to_le32" redefined
88 | #define cpu_to_le32
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:88: note: this is the location of the previous definition
88 | #define cpu_to_le32 __cpu_to_le32
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:89: warning: "cpu_to_le64" redefined
89 | #define cpu_to_le64
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:86: note: this is the location of the previous definition
86 | #define cpu_to_le64 __cpu_to_le64
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:90: warning: "le16_to_cpu" redefined
90 | #define le16_to_cpu
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:91: note: this is the location of the previous definition
91 | #define le16_to_cpu __le16_to_cpu
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:91: warning: "le32_to_cpu" redefined
91 | #define le32_to_cpu
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:89: note: this is the location of the previous definition
89 | #define le32_to_cpu __le32_to_cpu
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:92: warning: "le64_to_cpu" redefined
92 | #define le64_to_cpu
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:87: note: this is the location of the previous definition
87 | #define le64_to_cpu __le64_to_cpu
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:93: warning: "cpu_to_be16" redefined
93 | #define cpu_to_be16 bswap_16
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:96: note: this is the location of the previous definition
96 | #define cpu_to_be16 __cpu_to_be16
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:94: warning: "cpu_to_be32" redefined
94 | #define cpu_to_be32 bswap_32
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:94: note: this is the location of the previous definition
94 | #define cpu_to_be32 __cpu_to_be32
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:95: warning: "cpu_to_be64" redefined
95 | #define cpu_to_be64 bswap_64
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:92: note: this is the location of the previous definition
92 | #define cpu_to_be64 __cpu_to_be64
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:96: warning: "be16_to_cpu" redefined
96 | #define be16_to_cpu bswap_16
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:97: note: this is the location of the previous definition
97 | #define be16_to_cpu __be16_to_cpu
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:97: warning: "be32_to_cpu" redefined
97 | #define be32_to_cpu bswap_32
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:95: note: this is the location of the previous definition
95 | #define be32_to_cpu __be32_to_cpu
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:98: warning: "be64_to_cpu" redefined
98 | #define be64_to_cpu bswap_64
|
In file included from ./include/linux/byteorder/little_endian.h:11,
from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5,
from ./arch/x86/include/asm/insn.h:10,
from arch/x86/tools/insn_sanity.c:21:
./include/linux/byteorder/generic.h:93: note: this is the location of the previous definition
93 | #define be64_to_cpu __be64_to_cpu
|
In file included from ./arch/x86/lib/insn.c:8,
from arch/x86/tools/insn_sanity.c:23:
./tools/include/linux/kernel.h:105: warning: "ARRAY_SIZE" redefined
105 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
|
arch/x86/tools/insn_sanity.c:19: note: this is the location of the previous definition
19 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
|
make[1]: *** [scripts/Makefile.host:95: arch/x86/tools/insn_sanity] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [arch/x86/Makefile:267: bzImage] Error 2
make: *** Waiting for unfinished jobs....

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette