Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build: Fix objtool build with ARCH=x86_64

The objtool build fails in a cross-compiled environment on a non-x86
host with "ARCH=x86_64":

tools/objtool/objtool-in.o: In function `decode_instructions':
tools/objtool/builtin-check.c:276: undefined reference to `arch_decode_instruction'

We could override the ARCH environment variable and change it back to
x86, similar to what the objtool Makefile was doing before; but it's
tricky to override environment variables consistently.

Instead, take a similar approach used by the Linux top-level Makefile
and introduce a SRCARCH Makefile variable which evaluates to "x86" when
ARCH is either "x86_64" or "x86".

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160722191920.ej62fnspnqurbaa7@treble
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Josh Poimboeuf and committed by
Arnaldo Carvalho de Melo
60cbdf5d 0cf6eb60

+34 -2
+1 -1
tools/objtool/Build
··· 1 - objtool-y += arch/$(ARCH)/ 1 + objtool-y += arch/$(SRCARCH)/ 2 2 objtool-y += builtin-check.o 3 3 objtool-y += elf.o 4 4 objtool-y += special.o
+1 -1
tools/objtool/Makefile
··· 33 33 CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) 34 34 35 35 AWK = awk 36 - export srctree OUTPUT CFLAGS ARCH AWK 36 + export srctree OUTPUT CFLAGS SRCARCH AWK 37 37 include $(srctree)/tools/build/Makefile.include 38 38 39 39 $(OBJTOOL_IN): fixdep FORCE
+32
tools/scripts/Makefile.arch
··· 5 5 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 6 6 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ 7 7 -e s/tile.*/tile/ ) 8 + 8 9 ifndef ARCH 9 10 ARCH := $(HOSTARCH) 11 + endif 12 + 13 + SRCARCH := $(ARCH) 14 + 15 + # Additional ARCH settings for x86 16 + ifeq ($(ARCH),i386) 17 + SRCARCH := x86 18 + endif 19 + ifeq ($(ARCH),x86_64) 20 + SRCARCH := x86 21 + endif 22 + 23 + # Additional ARCH settings for sparc 24 + ifeq ($(ARCH),sparc32) 25 + SRCARCH := sparc 26 + endif 27 + ifeq ($(ARCH),sparc64) 28 + SRCARCH := sparc 29 + endif 30 + 31 + # Additional ARCH settings for sh 32 + ifeq ($(ARCH),sh64) 33 + SRCARCH := sh 34 + endif 35 + 36 + # Additional ARCH settings for tile 37 + ifeq ($(ARCH),tilepro) 38 + SRCARCH := tile 39 + endif 40 + ifeq ($(ARCH),tilegx) 41 + SRCARCH := tile 10 42 endif 11 43 12 44 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)