diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 9f9681ae3ef..da3e7efda8b 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -544,12 +544,12 @@ static bool ShouldRelocOnSymbol(const MCSymbolData &SD, if (SD.isExternal()) return true; - const llvm::MCSymbolRefExpr& Ref = *Target.getSymA(); + MCSymbolRefExpr::VariantKind Kind = Target.getSymA()->getKind(); const MCSectionELF &Sec2 = static_cast(F.getParent()->getSection()); - if (Ref.getKind() == MCSymbolRefExpr::VK_PLT && - &Sec2 != &Section) + if (&Sec2 != &Section && + (Kind == MCSymbolRefExpr::VK_PLT || Kind == MCSymbolRefExpr::VK_GOTPCREL)) return true; return false; @@ -648,6 +648,9 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm, case MCSymbolRefExpr::VK_GOT: Type = ELF::R_X86_64_GOT32; break; + case llvm::MCSymbolRefExpr::VK_GOTPCREL: + Type = ELF::R_X86_64_GOTPCREL; + break; default: llvm_unreachable("Unimplemented"); } diff --git a/test/MC/ELF/merge.s b/test/MC/ELF/merge.s index 227d4140e16..311327ebcea 100644 --- a/test/MC/ELF/merge.s +++ b/test/MC/ELF/merge.s @@ -11,6 +11,7 @@ movl $.Lfoo, %edi movl $.Lfoo+2, %edi jmp foo@PLT + movq foo@GOTPCREL, %rax .section .sec1,"aM",@progbits,16 .Lfoo: @@ -70,4 +71,12 @@ foo: // CHECK-NEXT: ('r_type', 4 // CHECK-NEXT: ('r_addend', // CHECK-NEXT: ), + +// Relocation 4 refers to symbol 2 +// CHECK-NEXT: # Relocation 4 +// CHECK-NEXT: (('r_offset', +// CHECK-NEXT: ('r_sym', 2) +// CHECK-NEXT: ('r_type', 9 +// CHECK-NEXT: ('r_addend', +// CHECK-NEXT: ), // CHECK-NEXT: ])