[PATCH] D84803: [ThinLTO][MachO] Preserve both possible GUIDs from exported list
Steven Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 14:37:50 PDT 2020
steven_wu created this revision.
steven_wu added reviewers: tejohnson, mehdi_amini.
Herald added subscribers: ributzka, dexonsmith, jkorous, hiraditya, inglorion.
Herald added a project: LLVM.
steven_wu requested review of this revision.
For MachO object file format that uses '_' as prefix for symbols, a
symbol in the final output `_$NAME` can have two possible names in IR
which has different GUID. It can be either `$NAME` or `\01_$NAME` and
we should try to preserve both of them because we don't know which one
it can be in the module file.
rdar://65853754
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84803
Files:
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/test/ThinLTO/X86/mangled_symbol.ll
Index: llvm/test/ThinLTO/X86/mangled_symbol.ll
===================================================================
--- /dev/null
+++ llvm/test/ThinLTO/X86/mangled_symbol.ll
@@ -0,0 +1,20 @@
+; RUN: opt -module-summary %s -o %t1.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc
+; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=REGULAR
+; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - --exported-symbol=_extern_not_mangled --exported-symbol=_extern_mangled | llvm-dis -o - | FileCheck %s --check-prefix=INTERNALIZE
+
+; REGULAR: define void @extern_not_mangled
+; REGULAR: define void @"\01_extern_mangled"
+; INTERNALIZE: define void @extern_not_mangled
+; INTERNALIZE: define void @"\01_extern_mangled"
+
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+define void @extern_not_mangled() {
+ ret void
+}
+
+define void @"\01_extern_mangled"() {
+ ret void
+}
Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp
===================================================================
--- llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -275,8 +275,11 @@
DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
for (auto &Entry : PreservedSymbols) {
StringRef Name = Entry.first();
+ // For MachO object format, symbols are prefixed with "_". For preserved
+ // symbols "_$NAME", we need to preserve the corresponding GUID for "$NAME"
+ // and "\01_$NAME".
if (TheTriple.isOSBinFormatMachO() && Name.size() > 0 && Name[0] == '_')
- Name = Name.drop_front();
+ GUIDPreservedSymbols.insert(GlobalValue::getGUID(Name.substr(1)));
GUIDPreservedSymbols.insert(GlobalValue::getGUID(Name));
}
return GUIDPreservedSymbols;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84803.281366.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/adee7e32/attachment.bin>
More information about the llvm-commits
mailing list