0001-x86-64-Treat-R_X86_64_PLT32-as-R_X86_64_PC32.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 842c390469e2c2e10b5aa36700324cd3bde25875 Mon Sep 17 00:00:00 2001
  2. From: "H.J. Lu" <hjl.tools@gmail.com>
  3. Date: Sat, 17 Feb 2018 06:47:28 -0800
  4. Subject: [PATCH] x86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32
  5. Starting from binutils commit bd7ab16b4537788ad53521c45469a1bdae84ad4a:
  6. https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bd7ab16b4537788ad53521c45469a1bdae84ad4a
  7. x86-64 assembler generates R_X86_64_PLT32, instead of R_X86_64_PC32, for
  8. 32-bit PC-relative branches. Grub2 should treat R_X86_64_PLT32 as
  9. R_X86_64_PC32.
  10. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  11. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Signed-off-by: Romain Naour <romain.naour@smile.fr>
  13. ---
  14. grub-core/efiemu/i386/loadcore64.c | 1 +
  15. grub-core/kern/x86_64/dl.c | 1 +
  16. util/grub-mkimagexx.c | 1 +
  17. util/grub-module-verifier.c | 1 +
  18. 4 files changed, 4 insertions(+)
  19. diff --git a/grub-core/efiemu/i386/loadcore64.c b/grub-core/efiemu/i386/loadcore64.c
  20. index e49d0b6..18facf4 100644
  21. --- a/grub-core/efiemu/i386/loadcore64.c
  22. +++ b/grub-core/efiemu/i386/loadcore64.c
  23. @@ -98,6 +98,7 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
  24. break;
  25. case R_X86_64_PC32:
  26. + case R_X86_64_PLT32:
  27. err = grub_efiemu_write_value (addr,
  28. *addr32 + rel->r_addend
  29. + sym.off
  30. diff --git a/grub-core/kern/x86_64/dl.c b/grub-core/kern/x86_64/dl.c
  31. index 4406906..3a73e6e 100644
  32. --- a/grub-core/kern/x86_64/dl.c
  33. +++ b/grub-core/kern/x86_64/dl.c
  34. @@ -70,6 +70,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
  35. break;
  36. case R_X86_64_PC32:
  37. + case R_X86_64_PLT32:
  38. {
  39. grub_int64_t value;
  40. value = ((grub_int32_t) *addr32) + rel->r_addend + sym->st_value -
  41. diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
  42. index a2bb054..39d7efb 100644
  43. --- a/util/grub-mkimagexx.c
  44. +++ b/util/grub-mkimagexx.c
  45. @@ -841,6 +841,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
  46. break;
  47. case R_X86_64_PC32:
  48. + case R_X86_64_PLT32:
  49. {
  50. grub_uint32_t *t32 = (grub_uint32_t *) target;
  51. *t32 = grub_host_to_target64 (grub_target_to_host32 (*t32)
  52. diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c
  53. index 9179285..a79271f 100644
  54. --- a/util/grub-module-verifier.c
  55. +++ b/util/grub-module-verifier.c
  56. @@ -19,6 +19,7 @@ struct grub_module_verifier_arch archs[] = {
  57. -1
  58. }, (int[]){
  59. R_X86_64_PC32,
  60. + R_X86_64_PLT32,
  61. -1
  62. }
  63. },
  64. --
  65. 2.7.4