[llvm-branch-commits] [llvm] db07d9f - [MC] Fix llvm_unreachable when a STB_GNU_UNIQUE symbol needs a relocation
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 5 21:45:14 PDT 2022
Author: Fangrui Song
Date: 2022-04-05T21:43:39-07:00
New Revision: db07d9f098b3c8f180c1f3d2d21b509bc6e94113
URL: https://github.com/llvm/llvm-project/commit/db07d9f098b3c8f180c1f3d2d21b509bc6e94113
DIFF: https://github.com/llvm/llvm-project/commit/db07d9f098b3c8f180c1f3d2d21b509bc6e94113.diff
LOG: [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 6bdad85b26fbfd064772f2b382b27fbbf0b0afce)
Added:
Modified:
llvm/lib/MC/ELFObjectWriter.cpp
llvm/test/MC/ELF/gnu-unique.s
Removed:
################################################################################
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 883735fcc293a..6fd2f7e7a7185 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1336,6 +1336,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 8948b33b9afbd..21609365d5277 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, at 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
More information about the llvm-branch-commits
mailing list