file-4.16-fix-array-64bit.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --- file/src/readelf.h
  2. +++ file/src/readelf.h
  3. @@ -50,6 +50,7 @@
  4. typedef uint32_t Elf64_Off[2];
  5. typedef uint32_t Elf64_Xword[2];
  6. #else
  7. +#undef USE_ARRAY_FOR_64BIT_TYPES
  8. typedef uint64_t Elf64_Addr;
  9. typedef uint64_t Elf64_Off;
  10. typedef uint64_t Elf64_Xword;
  11. --- file/src/readelf.c
  12. +++ file/src/readelf.c
  13. @@ -121,6 +121,14 @@
  14. return value;
  15. }
  16. +#ifdef USE_ARRAY_FOR_64BIT_TYPES
  17. +# define elf_getu64(swap, array) \
  18. + ((swap ? ((uint64_t)getu32(swap, array[0])) << 32 : getu32(swap, array[0])) + \
  19. + (swap ? getu32(swap, array[1]) : ((uint64_t)getu32(swap, array[1]) << 32)))
  20. +#else
  21. +# define elf_getu64(swap, value) getu64(swap, value)
  22. +#endif
  23. +
  24. #define xsh_addr (class == ELFCLASS32 \
  25. ? (void *) &sh32 \
  26. : (void *) &sh64)
  27. @@ -913,11 +921,7 @@
  28. if (getu16(swap, elfhdr.e_type) == ET_CORE) {
  29. #ifdef ELFCORE
  30. if (dophn_core(ms, class, swap, fd,
  31. -#ifdef USE_ARRAY_FOR_64BIT_TYPES
  32. - (off_t)getu32(swap, elfhdr.e_phoff[1]),
  33. -#else
  34. - (off_t)getu64(swap, elfhdr.e_phoff),
  35. -#endif
  36. + (off_t)elf_getu64(swap, elfhdr.e_phoff),
  37. getu16(swap, elfhdr.e_phnum),
  38. (size_t)getu16(swap, elfhdr.e_phentsize)) == -1)
  39. return -1;
  40. @@ -927,22 +931,14 @@
  41. } else {
  42. if (getu16(swap, elfhdr.e_type) == ET_EXEC) {
  43. if (dophn_exec(ms, class, swap, fd,
  44. -#ifdef USE_ARRAY_FOR_64BIT_TYPES
  45. - (off_t)getu32(swap, elfhdr.e_phoff[1]),
  46. -#else
  47. - (off_t)getu64(swap, elfhdr.e_phoff),
  48. -#endif
  49. + (off_t)elf_getu64(swap, elfhdr.e_phoff),
  50. getu16(swap, elfhdr.e_phnum),
  51. (size_t)getu16(swap, elfhdr.e_phentsize))
  52. == -1)
  53. return -1;
  54. }
  55. if (doshn(ms, class, swap, fd,
  56. -#ifdef USE_ARRAY_FOR_64BIT_TYPES
  57. - (off_t)getu32(swap, elfhdr.e_shoff[1]),
  58. -#else
  59. - (off_t)getu64(swap, elfhdr.e_shoff),
  60. -#endif
  61. + (off_t)elf_getu64(swap, elfhdr.e_shoff),
  62. getu16(swap, elfhdr.e_shnum),
  63. (size_t)getu16(swap, elfhdr.e_shentsize)) == -1)
  64. return -1;