Blame SOURCES/binutils-s390x-prevent-GOT-rewrite.patch

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