Skip to content

Commit

Permalink
objtool: Fix 64-bit build on 32-bit host
Browse files Browse the repository at this point in the history
The new ORC unwinder breaks the build of a 64-bit kernel on a 32-bit
host.  Building the kernel on a i386 or x32 host fails with:

  orc_dump.c: In function 'orc_dump':
  orc_dump.c:105:26: error: passing argument 2 of 'elf_getshdrnum' from incompatible pointer type [-Werror=incompatible-pointer-types]
    if (elf_getshdrnum(elf, &nr_sections)) {
                            ^
  In file included from /usr/local/include/gelf.h:32:0,
                   from elf.h:22,
                   from warn.h:26,
                   from orc_dump.c:20:
  /usr/local/include/libelf.h:304:12: note: expected 'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
   extern int elf_getshdrnum (Elf *__elf, size_t *__dst);
              ^~~~~~~~~~~~~~
  orc_dump.c:190:17: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'Elf64_Sxword {aka long long int}' [-Werror=format=]
      printf("%s+%lx:", name, rela.r_addend);
                 ~~^          ~~~~~~~~~~~~~
                 %llx

Fix the build failure.

Another problem is that if the user specifies HOSTCC or HOSTLD
variables, they are ignored in the objtool makefile.  Change the
Makefile to respect these variables.

Signed-off-by: Mikulas Patocka <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Sven Joachim <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Fixes: 627fce1 ("objtool: Add ORC unwind table generation")
Link: http://lkml.kernel.org/r/19f0e64d8e07e30a7b307cd010eb780c404fe08d.1512252895.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Mikulas Patocka authored and Ingo Molnar committed Dec 6, 2017
1 parent 5b1ead6 commit 14c47b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions tools/objtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ ARCH := x86
endif

# always use the host compiler
CC = gcc
LD = ld
AR = ar
HOSTCC ?= gcc
HOSTLD ?= ld
CC = $(HOSTCC)
LD = $(HOSTLD)
AR = ar

ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Expand Down
7 changes: 4 additions & 3 deletions tools/objtool/orc_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ int orc_dump(const char *_objname)
int fd, nr_entries, i, *orc_ip = NULL, orc_size = 0;
struct orc_entry *orc = NULL;
char *name;
unsigned long nr_sections, orc_ip_addr = 0;
size_t nr_sections;
Elf64_Addr orc_ip_addr = 0;
size_t shstrtab_idx;
Elf *elf;
Elf_Scn *scn;
Expand Down Expand Up @@ -187,10 +188,10 @@ int orc_dump(const char *_objname)
return -1;
}

printf("%s+%lx:", name, rela.r_addend);
printf("%s+%llx:", name, (unsigned long long)rela.r_addend);

} else {
printf("%lx:", orc_ip_addr + (i * sizeof(int)) + orc_ip[i]);
printf("%llx:", (unsigned long long)(orc_ip_addr + (i * sizeof(int)) + orc_ip[i]));
}


Expand Down

0 comments on commit 14c47b5

Please sign in to comment.