diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index 7ae11dc8e8b..7964ec665b9 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -2277,7 +2277,6 @@ elf_s390_relocate_section (bfd *output_bfd, || 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 @@ -2324,10 +2323,9 @@ elf_s390_relocate_section (bfd *output_bfd, && 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) + && !((h->root.u.def.value + + sec->output_section->vma + + sec->output_offset) & 1)) { unsigned short new_insn = (0xc000 | (bfd_get_8 (input_bfd, diff --git a/ld/testsuite/ld-s390/pr32969_64-1.dd b/ld/testsuite/ld-s390/pr32969_64-1.dd new file mode 100644 index 00000000000..fce262f5f39 --- /dev/null +++ b/ld/testsuite/ld-s390/pr32969_64-1.dd @@ -0,0 +1,15 @@ +tmpdir/pr32969_64-1: file format elf64-s390 + +Disassembly of section .text: + +.* <_start>: +.*: c0 10 00 00 00 0e [ ]*larl %r1,10000cc +.*: c4 18 00 00 08 1d [ ]*lgrl %r1,10010f0 <_GLOBAL_OFFSET_TABLE_\+0x20> + +.* : +.*: c4 18 00 00 08 1a [ ]*lgrl %r1,10010f0 <_GLOBAL_OFFSET_TABLE_\+0x20> +#?.* 07 07 [ ]*nopr %r7 + +.* : +.* c4 18 00 00 08 16 [ ]*lgrl %r1,10010f0 <_GLOBAL_OFFSET_TABLE_\+0x20> +#?.* 07 07 [ ]*nopr %r7 diff --git a/ld/testsuite/ld-s390/pr32969_64-2.dd b/ld/testsuite/ld-s390/pr32969_64-2.dd new file mode 100644 index 00000000000..88c770ec882 --- /dev/null +++ b/ld/testsuite/ld-s390/pr32969_64-2.dd @@ -0,0 +1,15 @@ +tmpdir/pr32969_64-2: file format elf64-s390 + +Disassembly of section .text: + +.* <_start>: +.*: c0 10 00 00 00 0e [ ]*larl %r1,10000cc +.*: c0 10 00 00 00 0c [ ]*larl %r1,10000ce + +.* : +.*: c0 10 00 00 00 09 [ ]*larl %r1,10000ce +#?.* 07 07 [ ]*nopr %r7 + +.* : +.* c0 10 00 00 00 05 [ ]*larl %r1,10000ce +#?.* 07 07 [ ]*nopr %r7 diff --git a/ld/testsuite/ld-s390/pr32969a.s b/ld/testsuite/ld-s390/pr32969a.s new file mode 100644 index 00000000000..baee6ca6d24 --- /dev/null +++ b/ld/testsuite/ld-s390/pr32969a.s @@ -0,0 +1,14 @@ + .text + .globl _start + .type _start,@function +_start: + lgrl %r1,foo@GOTENT + lgrl %r1,bar@GOTENT + + .section .rodata,"a",@progbits + .align 1 + .globl foo + .type foo,@object +foo: + .byte 0xa + .size foo, .-foo diff --git a/ld/testsuite/ld-s390/pr32969b.s b/ld/testsuite/ld-s390/pr32969b.s new file mode 100644 index 00000000000..54ee3699373 --- /dev/null +++ b/ld/testsuite/ld-s390/pr32969b.s @@ -0,0 +1,10 @@ +b: + lgrl %r1,bar@GOTENT + + .section .rodata,"aG",@progbits,bar_group,comdat + .align 1 + .globl bar + .type bar,@object +bar: + .byte 0xb + .size bar, .-bar diff --git a/ld/testsuite/ld-s390/pr32969c.s b/ld/testsuite/ld-s390/pr32969c.s new file mode 100644 index 00000000000..02cf58417d5 --- /dev/null +++ b/ld/testsuite/ld-s390/pr32969c.s @@ -0,0 +1,10 @@ +c: + lgrl %r1,bar@GOTENT + + .section .rodata,"aG",@progbits,bar_group,comdat + .align 2 + .globl bar + .type bar,@object +bar: + .byte 0xc + .size bar, .-bar diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp index d91eeacc730..aaba88d512a 100644 --- a/ld/testsuite/ld-s390/s390.exp +++ b/ld/testsuite/ld-s390/s390.exp @@ -125,6 +125,14 @@ set s390xtests { "-m elf64_s390 tmpdir/libpltlib_64.so" "" "-m64" {plt_64-1.s} {{objdump "-dzrj.plt" plt_64-1.pd} {readelf "-wf" plt_64-1_eh.wf}} "plt_64-1_eh"} + {"PR32969-1: do not rewrite load of misaligned COMDAT symbol address" + "-m elf64_s390" "" "-m64" {pr32969a.s pr32969b.s pr32969c.s} + {{objdump "-dzrj.text" pr32969_64-1.dd}} + "pr32969_64-1"} + {"PR32969-2: rewrite load of aligned COMDAT symbol address" + "-m elf64_s390" "" "-m64" {pr32969a.s pr32969c.s pr32969b.s} + {{objdump "-dzrj.text" pr32969_64-2.dd}} + "pr32969_64-2"} } if [istarget "s390-*-*"] {