Skip to content

Commit db07d9f

Browse files
MaskRaytstellar
authored andcommitted
[MC] Fix llvm_unreachable when a STB_GNU_UNIQUE symbol needs a relocation
STB_GNU_UNIQUE should be treated in a way similar to STB_GLOBAL. This fixes an "Invalid Binding" failure in an LLVM_ENABLE_ASSERTIONS=on build for source files like glibc elf/tst-unique1mod1.c . This bug has been benign so far because (a) Clang does not produce %gnu_unique_object by itself (b) a non-assertion build likely picks the STB_GLOBAL code path anyway. (cherry picked from commit 6bdad85)
1 parent 22d7bee commit db07d9f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
13361336
// can update it.
13371337
return true;
13381338
case ELF::STB_GLOBAL:
1339+
case ELF::STB_GNU_UNIQUE:
13391340
// Global ELF symbols can be preempted by the dynamic linker. The relocation
13401341
// has to point to the symbol for a reason analogous to the STB_WEAK case.
13411342
return true;

llvm/test/MC/ELF/gnu-unique.s

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# RUN: llvm-mc -triple=x86_64 %s | FileCheck %s --check-prefix=ASM
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s | llvm-readelf -h -s - | FileCheck %s --check-prefix=OBJ
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t
3+
# RUN: llvm-readelf -h -s %t | FileCheck %s --check-prefix=OBJ
4+
# RUN: llvm-objdump -d -r --no-show-raw-insn %t | FileCheck %s --check-prefix=DISASM
35

46
# ASM: .type unique,@gnu_unique_object
57

68
# OBJ: OS/ABI: UNIX - GNU
79
# OBJ: Type Bind Vis Ndx Name
810
# OBJ: OBJECT UNIQUE DEFAULT [[#]] unique
911

12+
# DISASM-LABEL: <.text>:
13+
# DISASM-NEXT: movl $1, 0
14+
## unique has a non-local binding. Reference unique instead of .data
15+
# DISASM-NEXT: R_X86_64_32S unique
16+
17+
movl $1, unique
18+
1019
.data
1120
.globl unique
1221
.type unique, @gnu_unique_object

0 commit comments

Comments
 (0)