Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -111,6 +111,7 @@ class X86_64TargetInfo final : public TargetInfo { public: X86_64TargetInfo(); + uint32_t getDynRel(uint32_t Type) const override; uint32_t getTlsGotRel(uint32_t Type) const override; bool pointsToLocalDynamicGotEntry(uint32_t Type) const override; bool isTlsLocalDynamicRel(uint32_t Type) const override; @@ -732,6 +733,15 @@ return refersToGotEntry(Type) || needsPlt(Type, S); } +uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const { + if (Type == R_X86_64_PC32 || Type == R_X86_64_32) + if (Config->Shared) + error("relocation " + getELFRelocationTypeName(EM_X86_64, Type) + + " cannot be used when making a shared object; " + "recompile with -fPIC."); + return Type; +} + uint32_t X86_64TargetInfo::getTlsGotRel(uint32_t Type) const { // No other types of TLS relocations requiring GOT should // reach here. Index: test/ELF/Inputs/allow-shlib-undefined.s =================================================================== --- test/ELF/Inputs/allow-shlib-undefined.s +++ test/ELF/Inputs/allow-shlib-undefined.s @@ -1,3 +1,3 @@ .globl _shared _shared: - call _unresolved + callq _unresolved@PLT Index: test/ELF/Inputs/llvm33-rela-outside-group.o =================================================================== --- test/ELF/Inputs/llvm33-rela-outside-group.o +++ test/ELF/Inputs/llvm33-rela-outside-group.o @@ -1,2 +1,2 @@ ELF>˜@@ -è.rela.text._Z3fooIiEvv.text.bss.group.shstrtab.strtab.symtab.data#@HDHHHð*MJ<À 4Ø bar_Z3fooIiEvvüÿÿÿÿÿÿÿ \ No newline at end of file +è.rela.text._Z3fooIiEvv.text.bss.group.shstrtab.strtab.symtab.data#@HDHHH*MJ<Ø 4ð' bar_Z3fooIiEvv_GLOBAL_OFFSET_TABLE_üÿÿÿÿÿÿÿ \ No newline at end of file Index: test/ELF/allow-shlib-undefined.s =================================================================== --- test/ELF/allow-shlib-undefined.s +++ test/ELF/allow-shlib-undefined.s @@ -22,4 +22,4 @@ .globl _start _start: - call _shared + callq _shared@PLT Index: test/ELF/llvm33-rela-outside-group.s =================================================================== --- test/ELF/llvm33-rela-outside-group.s +++ test/ELF/llvm33-rela-outside-group.s @@ -8,4 +8,4 @@ .section .text._Z3fooIiEvv,"axG",@progbits,_Z3fooIiEvv,comdat _Z3fooIiEvv: - callq bar + callq bar@PLT Index: test/ELF/no-undefined.s =================================================================== --- test/ELF/no-undefined.s +++ test/ELF/no-undefined.s @@ -4,4 +4,4 @@ .globl _shared _shared: - call _unresolved + callq _unresolved@PLT Index: test/ELF/x86-64-reloc-32-fpic.s =================================================================== --- test/ELF/x86-64-reloc-32-fpic.s +++ test/ELF/x86-64-reloc-32-fpic.s @@ -0,0 +1,8 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s +# CHECK: relocation R_X86_64_32 cannot be used when making a shared object; recompile with -fPIC. + +.globl _start +_start: + .long _shared Index: test/ELF/x86-64-reloc-pc32-fpic.s =================================================================== --- test/ELF/x86-64-reloc-pc32-fpic.s +++ test/ELF/x86-64-reloc-pc32-fpic.s @@ -0,0 +1,8 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s +# CHECK: relocation R_X86_64_PC32 cannot be used when making a shared object; recompile with -fPIC. + +.globl _start +_start: + call _shared