}
// Convert the PreservedSymbols map from "Name" based to "GUID" based.
+static void computeGUIDPreservedSymbols(const lto::InputFile &File,
+ const StringSet<> &PreservedSymbols,
+ const Triple &TheTriple,
+ DenseSet<GlobalValue::GUID> &GUIDs) {
+ // Iterate the symbols in the input file and if the input has preserved symbol
+ // compute the GUID for the symbol.
+ for (const auto &Sym : File.symbols()) {
+ if (PreservedSymbols.count(Sym.getName()))
+ GUIDs.insert(GlobalValue::getGUID(GlobalValue::getGlobalIdentifier(
+ Sym.getIRName(), GlobalValue::ExternalLinkage, "")));
+ }
+}
+
static DenseSet<GlobalValue::GUID>
-computeGUIDPreservedSymbols(const StringSet<> &PreservedSymbols,
+computeGUIDPreservedSymbols(const lto::InputFile &File,
+ const StringSet<> &PreservedSymbols,
const Triple &TheTriple) {
DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
- for (auto &Entry : PreservedSymbols) {
- StringRef Name = Entry.first();
- if (TheTriple.isOSBinFormatMachO() && Name.size() > 0 && Name[0] == '_')
- Name = Name.drop_front();
- GUIDPreservedSymbols.insert(GlobalValue::getGUID(Name));
- }
+ computeGUIDPreservedSymbols(File, PreservedSymbols, TheTriple,
+ GUIDPreservedSymbols);
return GUIDPreservedSymbols;
}
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
- PreservedSymbols, Triple(TheModule.getTargetTriple()));
+ File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
// Add used symbol to the preserved symbols.
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
- PreservedSymbols, Triple(TheModule.getTargetTriple()));
+ File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
- PreservedSymbols, Triple(TheModule.getTargetTriple()));
+ File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
- PreservedSymbols, Triple(TheModule.getTargetTriple()));
+ File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
// Convert the preserved symbols set from string to GUID
auto GUIDPreservedSymbols =
- computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
+ computeGUIDPreservedSymbols(File, PreservedSymbols, TMBuilder.TheTriple);
addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
// Convert the preserved symbols set from string to GUID, this is needed for
// computing the caching hash and the internalization.
- auto GUIDPreservedSymbols =
- computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
+ DenseSet<GlobalValue::GUID> GUIDPreservedSymbols;
+ for (const auto &M : Modules)
+ computeGUIDPreservedSymbols(*M, PreservedSymbols, TMBuilder.TheTriple,
+ GUIDPreservedSymbols);
// Add used symbol from inputs to the preserved symbols.
for (const auto &M : Modules)
; prevailing the %t1.bc copy as non-prevailing.
; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t2.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=foo | llvm-dis -o - | FileCheck %s --check-prefix=INTERNALIZE
+; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - --exported-symbol=_foo | llvm-dis -o - | FileCheck %s --check-prefix=INTERNALIZE
; Test the enable-lto-internalization option by setting it to false.
; This makes sure indices are not marked as internallinkage and therefore
; internalization does not happen.
; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc \
-; RUN: -enable-lto-internalization=false --exported-symbol=foo
+; RUN: -enable-lto-internalization=false --exported-symbol=_foo
; RUN: llvm-dis < %t1.bc.thinlto.internalized.bc | FileCheck %s --check-prefix=INTERNALIZE-OPTION-DISABLE
; RUN: llvm-lto2 run %t1.bc -o %t.o -save-temps \
--- /dev/null
+; RUN: opt -module-summary %s -o %t1.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc
+;; Check baseline when both of them internalized when not exported.
+; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - --exported-symbol=_exported | llvm-dis -o - | FileCheck %s --check-prefix=INTERNALIZED
+;; Check symbols are exported, including the ones with `\01` prefix.
+; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - --exported-symbol=_exported --exported-symbol=_extern_not_mangled --exported-symbol=_extern_mangled | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTED
+
+; INTERNALIZED: define internal void @extern_not_mangled
+; INTERNALIZED: define internal void @"\01_extern_mangled"
+; EXPORTED: define void @extern_not_mangled
+; EXPORTED: 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 @exported() {
+ ret void
+}
+
+define void @extern_not_mangled() {
+ ret void
+}
+
+define void @"\01_extern_mangled"() {
+ ret void
+}