[PATCH] D113167: [lld-macho] Allow exporting weak def private-extern symbols.
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 08:24:58 PDT 2021
oontvoo updated this revision to Diff 384762.
oontvoo added a comment.
added test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113167/new/
https://reviews.llvm.org/D113167
Files:
lld/MachO/Driver.cpp
lld/MachO/MarkLive.cpp
lld/test/MachO/exported-symbols.s
Index: lld/test/MachO/exported-symbols.s
===================================================================
--- /dev/null
+++ lld/test/MachO/exported-symbols.s
@@ -0,0 +1,27 @@
+# REQUIRES: x86
+
+# RUN: rm -rf %t && mkdir -p %t
+# RUN: llvm-mc %s -triple=x86_64-apple-macos -filetype=obj -o %t/foo.o
+# RUN: llvm-objdump --macho --syms %t/foo.o | FileCheck %s --check-prefix=PRE-CHECK
+
+# PRE-CHECK: SYMBOL TABLE:
+# PRE-CHECK-NEXT w F __TEXT,__text __foo
+
+# RUN: %lld -exported_symbol "__foo" %t/foo.o -o %t/a.out
+## Post link check that __foo was exported.
+# RUN: llvm-nm %t/a.out | FileCheck %s --check-prefix=POST-CHECK
+# POST-CHECK-DAG: T __foo
+# POST-CHECK-DAG: t _main
+.section __TEXT,__text,regular,pure_instructions
+
+.globl __foo, _main
+.weak_def_can_be_hidden __foo
+__foo:
+ pushq %rbp
+ popq %rbp
+ retq
+
+
+_main:
+ callq __foo
+ retq
Index: lld/MachO/MarkLive.cpp
===================================================================
--- lld/MachO/MarkLive.cpp
+++ lld/MachO/MarkLive.cpp
@@ -67,7 +67,7 @@
// FIXME: Instead of doing this here, maybe the Driver code doing
// the matching should add them to explicitUndefineds? Then the
// explicitUndefineds code below would handle this automatically.
- assert(!defined->privateExtern &&
+ assert((!defined->privateExtern || defined->isWeakDef()) &&
"should have been rejected by driver");
addSym(defined);
continue;
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1472,8 +1472,15 @@
StringRef symbolName = defined->getName();
if (config->exportedSymbols.match(symbolName)) {
if (defined->privateExtern) {
- warn("cannot export hidden symbol " + symbolName +
- "\n>>> defined in " + toString(defined->getFile()));
+ // If it's a weak, it's not "hidden".
+ if (!defined->isWeakDef())
+ warn("cannot export hidden symbol " + symbolName +
+ "\n>>> defined in " + toString(defined->getFile()));
+ else
+ // When a weakdef private extern symbol is exported,
+ // it becomes "non-private".
+ // This matches LD64's behavior.
+ defined->privateExtern = false;
}
} else {
defined->privateExtern = true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113167.384762.patch
Type: text/x-patch
Size: 2496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211104/dc2c2f3c/attachment.bin>
More information about the llvm-commits
mailing list