Index: lld/ELF/Relocations.cpp =================================================================== --- lld/ELF/Relocations.cpp +++ lld/ELF/Relocations.cpp @@ -1365,8 +1365,8 @@ if (oneof(expr)) { in.gotPlt->hasGotPltOffRel = true; - } else if (oneof( - expr)) { + } else if (oneof(expr)) { in.got->hasGotOffRel = true; } Index: lld/test/ELF/ppc32-plt-got.s =================================================================== --- /dev/null +++ lld/test/ELF/ppc32-plt-got.s @@ -0,0 +1,39 @@ +# REQUIRES: ppc + +## Ensure that, if we call a function through the plt, then the linker +## isn't discarding the .got section. + +# RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o +# RUN: ld.lld -shared %t.o -o %t.so +# RUN: llvm-readobj -Sdr %t.so | FileCheck %s + +## This -fPIC code sets r30 and calls the plt, but has no .got entries +## and never references _GLOBAL_OFFSET_TABLE_. The linker must not +## discard .got, only because the plt needs the first 12 bytes of .got. + +.section .got2,"aw",@progbits +.set .LTOC, .+0x8000 + +.text +.L0: +addis 30,30,.LTOC-.L0@ha +addi 30,30,.LTOC-.L0@l +bl baz+0x8000@plt + +## DT_PPC_GOT must point to .got, which must have the 12-byte header. +## The only relocation must be R_PPC_JMP_SLOT. + +# CHECK: Sections [ +# CHECK: Name: .got ({{[0-9]+}}) +# CHECK: Address: +# CHECK-SAME: {{ }}[[GOT_ADDRESS:0x[0-9A-F]+]]{{$}} +# CHECK: Size: +# CHECK-SAME: {{ 12$}} +# CHECK: DynamicSection [ +# CHECK-NEXT: Tag Type Name/Value +# CHECK: 0x70000000 PPC_GOT [[GOT_ADDRESS]] +# CHECK: Relocations [ +# CHECK-NEXT: Section ({{[0-9]+}}) .rela.plt { +# CHECK-NEXT: 0x{{[0-9A-F]+}} R_PPC_JMP_SLOT baz 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ]