diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 00d18cd35ab40a..fe11768ca9943e 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -1325,6 +1325,7 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm, // can update it. return true; case ELF::STB_GLOBAL: + case ELF::STB_GNU_UNIQUE: // Global ELF symbols can be preempted by the dynamic linker. The relocation // has to point to the symbol for a reason analogous to the STB_WEAK case. return true; diff --git a/llvm/test/MC/ELF/gnu-unique.s b/llvm/test/MC/ELF/gnu-unique.s index 8948b33b9afbd1..21609365d52776 100644 --- a/llvm/test/MC/ELF/gnu-unique.s +++ b/llvm/test/MC/ELF/gnu-unique.s @@ -1,5 +1,7 @@ # RUN: llvm-mc -triple=x86_64 %s | FileCheck %s --check-prefix=ASM -# RUN: llvm-mc -filetype=obj -triple=x86_64 %s | llvm-readelf -h -s - | FileCheck %s --check-prefix=OBJ +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t +# RUN: llvm-readelf -h -s %t | FileCheck %s --check-prefix=OBJ +# RUN: llvm-objdump -d -r --no-show-raw-insn %t | FileCheck %s --check-prefix=DISASM # ASM: .type unique,@gnu_unique_object @@ -7,6 +9,13 @@ # OBJ: Type Bind Vis Ndx Name # OBJ: OBJECT UNIQUE DEFAULT [[#]] unique +# DISASM-LABEL: <.text>: +# DISASM-NEXT: movl $1, 0 +## unique has a non-local binding. Reference unique instead of .data +# DISASM-NEXT: R_X86_64_32S unique + + movl $1, unique + .data .globl unique .type unique, @gnu_unique_object