@@ -78,6 +78,10 @@ cl::opt<bool> EnableLTOInternalization(
78
78
" enable-lto-internalization" , cl::init(true ), cl::Hidden,
79
79
cl::desc(" Enable global value internalization in LTO" ));
80
80
81
+ static cl::opt<bool >
82
+ LTOKeepSymbolCopies (" lto-keep-symbol-copies" , cl::init(false ), cl::Hidden,
83
+ cl::desc (" Keep copies of symbols in LTO indexing" ));
84
+
81
85
// / Indicate we are linking with an allocator that supports hot/cold operator
82
86
// / new interfaces.
83
87
extern cl::opt<bool > SupportsHotColdNew;
@@ -609,7 +613,12 @@ LTO::LTO(Config Conf, ThinBackend Backend,
609
613
ThinLTO(std::move(Backend)),
610
614
GlobalResolutions(
611
615
std::make_unique<DenseMap<StringRef, GlobalResolution>>()),
612
- LTOMode(LTOMode) {}
616
+ LTOMode(LTOMode) {
617
+ if (Conf.KeepSymbolNameCopies || LTOKeepSymbolCopies) {
618
+ Alloc = std::make_unique<BumpPtrAllocator>();
619
+ GlobalResolutionSymbolSaver = std::make_unique<llvm::StringSaver>(*Alloc);
620
+ }
621
+ }
613
622
614
623
// Requires a destructor for MapVector<BitcodeModule>.
615
624
LTO::~LTO () = default ;
@@ -628,8 +637,9 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
628
637
SymbolResolution Res = *ResI++;
629
638
630
639
StringRef SymbolName = Sym.getName ();
631
- if (Conf.KeepSymbolNameCopies )
632
- SymbolName = UniqueSymbolSaver->save (SymbolName);
640
+ // Keep copies of symbols if the client of LTO says so.
641
+ if (GlobalResolutionSymbolSaver && !GlobalResolutions->contains (SymbolName))
642
+ SymbolName = GlobalResolutionSymbolSaver->save (SymbolName);
633
643
634
644
auto &GlobalRes = (*GlobalResolutions)[SymbolName];
635
645
GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr ();
@@ -1803,7 +1813,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
1803
1813
// and export lists.
1804
1814
GlobalResolutions.reset ();
1805
1815
// Reset the bump pointer allocator to release its memory.
1806
- UniqueSymbolSaver .reset ();
1816
+ GlobalResolutionSymbolSaver .reset ();
1807
1817
Alloc.reset ();
1808
1818
1809
1819
if (Conf.OptLevel > 0 )
0 commit comments