[llvm] 4c94760 - [ORC] Fix materialization of weak local symbols
Ben Langmuir via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 19 07:26:04 PST 2021
Author: Ben Langmuir
Date: 2021-11-19T07:25:56-08:00
New Revision: 4c94760f360bd4e24519a61bea3bde0413aaf78a
URL: https://github.com/llvm/llvm-project/commit/4c94760f360bd4e24519a61bea3bde0413aaf78a
DIFF: https://github.com/llvm/llvm-project/commit/4c94760f360bd4e24519a61bea3bde0413aaf78a.diff
LOG: [ORC] Fix materialization of weak local symbols
We were adding all defined weak symbols to the materialization
responsibility, but local symbols will not be in the symbol table, so it
failed to materialize due to the "missing" symbol.
Local weak symbols come up in practice when using `ld -r` with a hidden
weak symbol.
rdar://85574696
Added:
llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
Modified:
llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index 92da6723c3724..6f840a079dd1b 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -423,7 +423,8 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
std::vector<std::pair<SymbolStringPtr, Symbol *>> NameToSym;
auto ProcessSymbol = [&](Symbol *Sym) {
- if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak) {
+ if (Sym->hasName() && Sym->getLinkage() == Linkage::Weak &&
+ Sym->getScope() != Scope::Local) {
auto Name = ES.intern(Sym->getName());
if (!MR->getSymbols().count(ES.intern(Sym->getName()))) {
JITSymbolFlags SF = JITSymbolFlags::Weak;
diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
new file mode 100644
index 0000000000000..41990b1312244
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_weak_local.s
@@ -0,0 +1,16 @@
+# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s
+# RUN: llvm-jitlink -noexec %t -show-graph | FileCheck %s
+
+# CHECK: linkage: weak, scope: local, live - _foo_weak
+
+# _foo_weak is weak and local. Make sure we can link it.
+ .section __TEXT,__text,regular,pure_instructions
+ .weak_definition _foo_weak
+ .p2align 4, 0x90
+_foo_weak:
+ retq
+
+ .globl _main
+ .p2align 4, 0x90
+_main:
+ jmp _foo_weak
More information about the llvm-commits
mailing list