binutils/SOURCES/binutils-s390x-prevent-GOT-rewrite.patch
2021-10-06 15:46:35 +00:00

44 lines
1.6 KiB
Diff

--- binutils.orig/bfd/elf64-s390.c 2020-06-15 11:01:54.671940830 +0100
+++ binutils-2.30/bfd/elf64-s390.c 2020-06-15 11:04:44.663343784 +0100
@@ -2335,6 +2335,9 @@ elf_s390_relocate_section (bfd *output_b
&& SYMBOL_REFERENCES_LOCAL (info, h))
|| resolved_to_zero)
{
+ Elf_Internal_Sym *isym;
+ asection *sym_sec;
+
/* This is actually a static link, or it is a
-Bsymbolic link and the symbol is defined
locally, or the symbol was forced to be local
@@ -2356,6 +2359,10 @@ elf_s390_relocate_section (bfd *output_b
h->got.offset |= 1;
}
+ /* When turning a GOT slot dereference into a direct
+ reference using larl we have to make sure that
+ the symbol is 1. properly aligned and 2. it is no
+ ABS symbol or will become one. */
if ((h->def_regular
&& bfd_link_pic (info)
&& SYMBOL_REFERENCES_LOCAL (info, h))
@@ -2370,8 +2377,17 @@ elf_s390_relocate_section (bfd *output_b
contents + rel->r_offset - 2)
& 0xff00f000) == 0xe300c000
&& bfd_get_8 (input_bfd,
- contents + rel->r_offset + 3) == 0x04)))
-
+ contents + rel->r_offset + 3) == 0x04))
+ && (isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ input_bfd, r_symndx))
+ && isym->st_shndx != SHN_ABS
+ && h != htab->elf.hdynamic
+ && h != htab->elf.hgot
+ && h != htab->elf.hplt
+ && !(isym->st_value & 1)
+ && (sym_sec = bfd_section_from_elf_index (input_bfd,
+ isym->st_shndx))
+ && sym_sec->alignment_power)
{
unsigned short new_insn =
(0xc000 | (bfd_get_8 (input_bfd,