[PATCH] binutils: partially revert 17c6c3b99156fe82c1e637e1a5fd9f163ac788c8
徐持恒 Xu Chiheng
chiheng.xu@gmail.com
Thu Nov 17 17:44:00 GMT 2022
Phenomenal: In 32 bit and 64 bit mixed code, ld can't do relocation
for 32 bit code.
It is caused by commit 17c6c3b99156fe82c1e637e1a5fd9f163ac788c8.
/* src_mask selects the part of the instruction (or data) to be used
in the relocation sum. If the target relocations don't have an
addend in the reloc, eg. ELF USE_REL, src_mask will normally equal
dst_mask to extract the addend from the section contents. If
relocations do have an addend in the reloc, eg. ELF USE_RELA, this
field should normally be zero. Non-zero values for ELF USE_RELA
targets should be viewed with suspicion as normally the value in
the dst_mask part of the section contents should be ignored. */
bfd_vma src_mask;
Author: Jan Beulich <jbeulich@suse.com> 2021-05-07 18:05:12
Committer: Jan Beulich <jbeulich@suse.com> 2021-05-07 18:05:12
Parent: 98da05bf2698b55b73453480a3fbb92f163d2c7b (x86: don't mix disp
and imm processing)
Child: 4cf88725da1cb503be04d3237354105ec170bc86 ([gdb/symtab] Fix
infinite recursion in dwarf2_cu::get_builder())
Branches: master, test0558-01 and many more (41)
Follows: gdb-10-branchpoint
Precedes: binutils-2_37, gdb-11-branchpoint
x86-64/ELF: clear src_mask for all reloc types
x86-64 uses rela relocations. The comment next to the field's declaration
says "Non-zero values for ELF USE_RELA targets should be viewed with
suspicion ..." And indeed the fields being non-zero causes section
contents to be accumulated into the final relocated values in addition to
the relocations' addends, which is contrary to the ELF spec.
-------------- next part --------------
bfd/elf64-x86-64.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 2ae8dffba0f..27be6a6f0ba 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -50,13 +50,13 @@ static reloc_howto_type x86_64_elf_howto_table[] =
bfd_elf_generic_reloc, "R_X86_64_64", false, 0, MINUS_ONE,
false),
HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0xffffffff, 0xffffffff,
true),
HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0xffffffff, 0xffffffff,
false),
HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0xffffffff, 0xffffffff,
true),
HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0, 0xffffffff,
@@ -74,10 +74,10 @@ static reloc_howto_type x86_64_elf_howto_table[] =
bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0, 0xffffffff,
true),
HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned,
- bfd_elf_generic_reloc, "R_X86_64_32", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff,
false),
HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed,
- bfd_elf_generic_reloc, "R_X86_64_32S", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_32S", false, 0xffffffff, 0xffffffff,
false),
HOWTO(R_X86_64_16, 0, 2, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_X86_64_16", false, 0, 0xffff, false),
@@ -136,7 +136,7 @@ static reloc_howto_type x86_64_elf_howto_table[] =
bfd_elf_generic_reloc, "R_X86_64_PLTOFF64", false, 0, MINUS_ONE,
false),
HOWTO(R_X86_64_SIZE32, 0, 4, 32, false, 0, complain_overflow_unsigned,
- bfd_elf_generic_reloc, "R_X86_64_SIZE32", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_SIZE32", false, 0xffffffff, 0xffffffff,
false),
HOWTO(R_X86_64_SIZE64, 0, 8, 64, false, 0, complain_overflow_dont,
bfd_elf_generic_reloc, "R_X86_64_SIZE64", false, 0, MINUS_ONE,
@@ -188,7 +188,7 @@ static reloc_howto_type x86_64_elf_howto_table[] =
/* Use complain_overflow_bitfield on R_X86_64_32 for x32. */
HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_bitfield,
- bfd_elf_generic_reloc, "R_X86_64_32", false, 0, 0xffffffff,
+ bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff,
false)
};
More information about the Binutils
mailing list