0133-objtool-Fix-64-bit-build-on-32-bit-host.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From 475d437587dd1de2d6a53f7fbbb9bc88c7700fc3 Mon Sep 17 00:00:00 2001
  2. From: Mikulas Patocka <[email protected]>
  3. Date: Sat, 2 Dec 2017 16:17:44 -0600
  4. Subject: [PATCH 133/242] objtool: Fix 64-bit build on 32-bit host
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. The new ORC unwinder breaks the build of a 64-bit kernel on a 32-bit
  10. host. Building the kernel on a i386 or x32 host fails with:
  11. orc_dump.c: In function 'orc_dump':
  12. orc_dump.c:105:26: error: passing argument 2 of 'elf_getshdrnum' from incompatible pointer type [-Werror=incompatible-pointer-types]
  13. if (elf_getshdrnum(elf, &nr_sections)) {
  14. ^
  15. In file included from /usr/local/include/gelf.h:32:0,
  16. from elf.h:22,
  17. from warn.h:26,
  18. from orc_dump.c:20:
  19. /usr/local/include/libelf.h:304:12: note: expected 'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
  20. extern int elf_getshdrnum (Elf *__elf, size_t *__dst);
  21. ^~~~~~~~~~~~~~
  22. 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=]
  23. printf("%s+%lx:", name, rela.r_addend);
  24. ~~^ ~~~~~~~~~~~~~
  25. %llx
  26. Fix the build failure.
  27. Another problem is that if the user specifies HOSTCC or HOSTLD
  28. variables, they are ignored in the objtool makefile. Change the
  29. Makefile to respect these variables.
  30. Signed-off-by: Mikulas Patocka <[email protected]>
  31. Signed-off-by: Josh Poimboeuf <[email protected]>
  32. Cc: Linus Torvalds <[email protected]>
  33. Cc: Peter Zijlstra <[email protected]>
  34. Cc: Sven Joachim <[email protected]>
  35. Cc: Thomas Gleixner <[email protected]>
  36. Fixes: 627fce14809b ("objtool: Add ORC unwind table generation")
  37. Link: http://lkml.kernel.org/r/19f0e64d8e07e30a7b307cd010eb780c404fe08d.1512252895.git.jpoimboe@redhat.com
  38. Signed-off-by: Ingo Molnar <[email protected]>
  39. (cherry picked from commit 0db897fb081b66c26a338e5481f317c71df779c9)
  40. Signed-off-by: Andy Whitcroft <[email protected]>
  41. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  42. (cherry picked from commit 979c9a5cacd1d40d08c1c24ed5c5810cf7f3069c)
  43. Signed-off-by: Fabian Grünbichler <[email protected]>
  44. ---
  45. tools/objtool/Makefile | 8 +++++---
  46. tools/objtool/orc_dump.c | 7 ++++---
  47. 2 files changed, 9 insertions(+), 6 deletions(-)
  48. diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
  49. index 847e99aa54ea..5c71bae01064 100644
  50. --- a/tools/objtool/Makefile
  51. +++ b/tools/objtool/Makefile
  52. @@ -6,9 +6,11 @@ ARCH := x86
  53. endif
  54. # always use the host compiler
  55. -CC = gcc
  56. -LD = ld
  57. -AR = ar
  58. +HOSTCC ?= gcc
  59. +HOSTLD ?= ld
  60. +CC = $(HOSTCC)
  61. +LD = $(HOSTLD)
  62. +AR = ar
  63. ifeq ($(srctree),)
  64. srctree := $(patsubst %/,%,$(dir $(CURDIR)))
  65. diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
  66. index 36c5bf6a2675..c3343820916a 100644
  67. --- a/tools/objtool/orc_dump.c
  68. +++ b/tools/objtool/orc_dump.c
  69. @@ -76,7 +76,8 @@ int orc_dump(const char *_objname)
  70. int fd, nr_entries, i, *orc_ip = NULL, orc_size = 0;
  71. struct orc_entry *orc = NULL;
  72. char *name;
  73. - unsigned long nr_sections, orc_ip_addr = 0;
  74. + size_t nr_sections;
  75. + Elf64_Addr orc_ip_addr = 0;
  76. size_t shstrtab_idx;
  77. Elf *elf;
  78. Elf_Scn *scn;
  79. @@ -187,10 +188,10 @@ int orc_dump(const char *_objname)
  80. return -1;
  81. }
  82. - printf("%s+%lx:", name, rela.r_addend);
  83. + printf("%s+%llx:", name, (unsigned long long)rela.r_addend);
  84. } else {
  85. - printf("%lx:", orc_ip_addr + (i * sizeof(int)) + orc_ip[i]);
  86. + printf("%llx:", (unsigned long long)(orc_ip_addr + (i * sizeof(int)) + orc_ip[i]));
  87. }
  88. --
  89. 2.14.2