@@ -231,7 +231,7 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef emul) {
231
231
// Returns slices of MB by parsing MB as an archive file.
232
232
// Each slice consists of a member file in the archive.
233
233
std::vector<std::pair<MemoryBufferRef, uint64_t >> static getArchiveMembers (
234
- MemoryBufferRef mb) {
234
+ Ctx &ctx, MemoryBufferRef mb) {
235
235
std::unique_ptr<Archive> file =
236
236
CHECK (Archive::create (mb),
237
237
mb.getBufferIdentifier () + " : failed to parse archive" );
@@ -296,7 +296,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
296
296
readLinkerScript (ctx, mbref);
297
297
return ;
298
298
case file_magic::archive: {
299
- auto members = getArchiveMembers (mbref);
299
+ auto members = getArchiveMembers (ctx, mbref);
300
300
if (inWholeArchive) {
301
301
for (const std::pair<MemoryBufferRef, uint64_t > &p : members) {
302
302
if (isBitcode (p.first ))
@@ -632,7 +632,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
632
632
633
633
// Handle -help
634
634
if (args.hasArg (OPT_help)) {
635
- printHelp ();
635
+ printHelp (ctx );
636
636
return ;
637
637
}
638
638
@@ -994,7 +994,7 @@ static void readCallGraph(Ctx &ctx, MemoryBufferRef mb) {
994
994
// true and populates cgProfile and symbolIndices.
995
995
template <class ELFT >
996
996
static bool
997
- processCallGraphRelocations (SmallVector<uint32_t , 32 > &symbolIndices,
997
+ processCallGraphRelocations (Ctx &ctx, SmallVector<uint32_t , 32 > &symbolIndices,
998
998
ArrayRef<typename ELFT::CGProfile> &cgProfile,
999
999
ObjFile<ELFT> *inputObj) {
1000
1000
if (inputObj->cgProfileSectionIndex == SHN_UNDEF)
@@ -1046,7 +1046,7 @@ template <class ELFT> static void readCallGraphsFromObjectFiles(Ctx &ctx) {
1046
1046
ArrayRef<typename ELFT::CGProfile> cgProfile;
1047
1047
for (auto file : ctx.objectFiles ) {
1048
1048
auto *obj = cast<ObjFile<ELFT>>(file);
1049
- if (!processCallGraphRelocations (symbolIndices, cgProfile, obj))
1049
+ if (!processCallGraphRelocations (ctx, symbolIndices, cgProfile, obj))
1050
1050
continue ;
1051
1051
1052
1052
if (symbolIndices.size () != cgProfile.size () * 2 )
@@ -2378,13 +2378,12 @@ static void replaceCommonSymbols(Ctx &ctx) {
2378
2378
2379
2379
// The section referred to by `s` is considered address-significant. Set the
2380
2380
// keepUnique flag on the section if appropriate.
2381
- static void markAddrsig (Symbol *s) {
2381
+ static void markAddrsig (bool icfSafe, Symbol *s) {
2382
+ // We don't need to keep text sections unique under --icf=all even if they
2383
+ // are address-significant.
2382
2384
if (auto *d = dyn_cast_or_null<Defined>(s))
2383
- if (d->section )
2384
- // We don't need to keep text sections unique under --icf=all even if they
2385
- // are address-significant.
2386
- if (ctx.arg .icf == ICFLevel::Safe || !(d->section ->flags & SHF_EXECINSTR))
2387
- d->section ->keepUnique = true ;
2385
+ if (d->section && (icfSafe || !(d->section ->flags & SHF_EXECINSTR)))
2386
+ d->section ->keepUnique = true ;
2388
2387
}
2389
2388
2390
2389
// Record sections that define symbols mentioned in --keep-unique <symbol>
@@ -2409,9 +2408,10 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
2409
2408
2410
2409
// Symbols in the dynsym could be address-significant in other executables
2411
2410
// or DSOs, so we conservatively mark them as address-significant.
2411
+ bool icfSafe = ctx.arg .icf == ICFLevel::Safe;
2412
2412
for (Symbol *sym : ctx.symtab ->getSymbols ())
2413
2413
if (sym->includeInDynsym ())
2414
- markAddrsig (sym);
2414
+ markAddrsig (icfSafe, sym);
2415
2415
2416
2416
// Visit the address-significance table in each object file and mark each
2417
2417
// referenced symbol as address-significant.
@@ -2428,14 +2428,14 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
2428
2428
uint64_t symIndex = decodeULEB128 (cur, &size, contents.end (), &err);
2429
2429
if (err)
2430
2430
fatal (toString (f) + " : could not decode addrsig section: " + err);
2431
- markAddrsig (syms[symIndex]);
2431
+ markAddrsig (icfSafe, syms[symIndex]);
2432
2432
cur += size;
2433
2433
}
2434
2434
} else {
2435
2435
// If an object file does not have an address-significance table,
2436
2436
// conservatively mark all of its symbols as address-significant.
2437
2437
for (Symbol *s : syms)
2438
- markAddrsig (s);
2438
+ markAddrsig (icfSafe, s);
2439
2439
}
2440
2440
}
2441
2441
}
@@ -2497,7 +2497,7 @@ static void readSymbolPartitionSection(Ctx &ctx, InputSectionBase *s) {
2497
2497
sym->partition = newPart.getNumber ();
2498
2498
}
2499
2499
2500
- static void markBuffersAsDontNeed (bool skipLinkedOutput) {
2500
+ static void markBuffersAsDontNeed (Ctx &ctx, bool skipLinkedOutput) {
2501
2501
// With --thinlto-index-only, all buffers are nearly unused from now on
2502
2502
// (except symbol/section names used by infrequent passes). Mark input file
2503
2503
// buffers as MADV_DONTNEED so that these pages can be reused by the expensive
@@ -2535,7 +2535,7 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
2535
2535
lto->add (*file);
2536
2536
2537
2537
if (!ctx.bitcodeFiles .empty ())
2538
- markBuffersAsDontNeed (skipLinkedOutput);
2538
+ markBuffersAsDontNeed (ctx, skipLinkedOutput);
2539
2539
2540
2540
for (InputFile *file : lto->compile ()) {
2541
2541
auto *obj = cast<ObjFile<ELFT>>(file);
@@ -2569,7 +2569,8 @@ struct WrappedSymbol {
2569
2569
// This function instantiates wrapper symbols. At this point, they seem
2570
2570
// like they are not being used at all, so we explicitly set some flags so
2571
2571
// that LTO won't eliminate them.
2572
- static std::vector<WrappedSymbol> addWrappedSymbols (opt::InputArgList &args) {
2572
+ static std::vector<WrappedSymbol> addWrappedSymbols (Ctx &ctx,
2573
+ opt::InputArgList &args) {
2573
2574
std::vector<WrappedSymbol> v;
2574
2575
DenseSet<StringRef> seen;
2575
2576
@@ -2620,7 +2621,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {
2620
2621
return v;
2621
2622
}
2622
2623
2623
- static void combineVersionedSymbol (Symbol &sym,
2624
+ static void combineVersionedSymbol (Ctx &ctx, Symbol &sym,
2624
2625
DenseMap<Symbol *, Symbol *> &map) {
2625
2626
const char *suffix1 = sym.getVersionSuffix ();
2626
2627
if (suffix1[0 ] != ' @' || suffix1[1 ] == ' @' )
@@ -2687,7 +2688,7 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
2687
2688
if (ctx.arg .versionDefinitions .size () > 2 )
2688
2689
for (Symbol *sym : ctx.symtab ->getSymbols ())
2689
2690
if (sym->hasVersionSuffix )
2690
- combineVersionedSymbol (*sym, map);
2691
+ combineVersionedSymbol (ctx, *sym, map);
2691
2692
2692
2693
if (map.empty ())
2693
2694
return ;
@@ -2927,7 +2928,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
2927
2928
}
2928
2929
2929
2930
// Archive members defining __wrap symbols may be extracted.
2930
- std::vector<WrappedSymbol> wrapped = addWrappedSymbols (args);
2931
+ std::vector<WrappedSymbol> wrapped = addWrappedSymbols (ctx, args);
2931
2932
2932
2933
// No more lazy bitcode can be extracted at this point. Do post parse work
2933
2934
// like checking duplicate symbols.
0 commit comments