@@ -231,7 +231,7 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef emul) {
231231// Returns slices of MB by parsing MB as an archive file.
232232// Each slice consists of a member file in the archive.
233233std::vector<std::pair<MemoryBufferRef, uint64_t >> static getArchiveMembers (
234- MemoryBufferRef mb) {
234+ Ctx &ctx, MemoryBufferRef mb) {
235235 std::unique_ptr<Archive> file =
236236 CHECK (Archive::create (mb),
237237 mb.getBufferIdentifier () + " : failed to parse archive" );
@@ -296,7 +296,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
296296 readLinkerScript (ctx, mbref);
297297 return ;
298298 case file_magic::archive: {
299- auto members = getArchiveMembers (mbref);
299+ auto members = getArchiveMembers (ctx, mbref);
300300 if (inWholeArchive) {
301301 for (const std::pair<MemoryBufferRef, uint64_t > &p : members) {
302302 if (isBitcode (p.first ))
@@ -632,7 +632,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
632632
633633 // Handle -help
634634 if (args.hasArg (OPT_help)) {
635- printHelp ();
635+ printHelp (ctx );
636636 return ;
637637 }
638638
@@ -994,7 +994,7 @@ static void readCallGraph(Ctx &ctx, MemoryBufferRef mb) {
994994// true and populates cgProfile and symbolIndices.
995995template <class ELFT >
996996static bool
997- processCallGraphRelocations (SmallVector<uint32_t , 32 > &symbolIndices,
997+ processCallGraphRelocations (Ctx &ctx, SmallVector<uint32_t , 32 > &symbolIndices,
998998 ArrayRef<typename ELFT::CGProfile> &cgProfile,
999999 ObjFile<ELFT> *inputObj) {
10001000 if (inputObj->cgProfileSectionIndex == SHN_UNDEF)
@@ -1046,7 +1046,7 @@ template <class ELFT> static void readCallGraphsFromObjectFiles(Ctx &ctx) {
10461046 ArrayRef<typename ELFT::CGProfile> cgProfile;
10471047 for (auto file : ctx.objectFiles ) {
10481048 auto *obj = cast<ObjFile<ELFT>>(file);
1049- if (!processCallGraphRelocations (symbolIndices, cgProfile, obj))
1049+ if (!processCallGraphRelocations (ctx, symbolIndices, cgProfile, obj))
10501050 continue ;
10511051
10521052 if (symbolIndices.size () != cgProfile.size () * 2 )
@@ -2378,13 +2378,12 @@ static void replaceCommonSymbols(Ctx &ctx) {
23782378
23792379// The section referred to by `s` is considered address-significant. Set the
23802380// 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.
23822384 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 ;
23882387}
23892388
23902389// Record sections that define symbols mentioned in --keep-unique <symbol>
@@ -2409,9 +2408,10 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24092408
24102409 // Symbols in the dynsym could be address-significant in other executables
24112410 // or DSOs, so we conservatively mark them as address-significant.
2411+ bool icfSafe = ctx.arg .icf == ICFLevel::Safe;
24122412 for (Symbol *sym : ctx.symtab ->getSymbols ())
24132413 if (sym->includeInDynsym ())
2414- markAddrsig (sym);
2414+ markAddrsig (icfSafe, sym);
24152415
24162416 // Visit the address-significance table in each object file and mark each
24172417 // referenced symbol as address-significant.
@@ -2428,14 +2428,14 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24282428 uint64_t symIndex = decodeULEB128 (cur, &size, contents.end (), &err);
24292429 if (err)
24302430 fatal (toString (f) + " : could not decode addrsig section: " + err);
2431- markAddrsig (syms[symIndex]);
2431+ markAddrsig (icfSafe, syms[symIndex]);
24322432 cur += size;
24332433 }
24342434 } else {
24352435 // If an object file does not have an address-significance table,
24362436 // conservatively mark all of its symbols as address-significant.
24372437 for (Symbol *s : syms)
2438- markAddrsig (s);
2438+ markAddrsig (icfSafe, s);
24392439 }
24402440 }
24412441}
@@ -2497,7 +2497,7 @@ static void readSymbolPartitionSection(Ctx &ctx, InputSectionBase *s) {
24972497 sym->partition = newPart.getNumber ();
24982498}
24992499
2500- static void markBuffersAsDontNeed (bool skipLinkedOutput) {
2500+ static void markBuffersAsDontNeed (Ctx &ctx, bool skipLinkedOutput) {
25012501 // With --thinlto-index-only, all buffers are nearly unused from now on
25022502 // (except symbol/section names used by infrequent passes). Mark input file
25032503 // buffers as MADV_DONTNEED so that these pages can be reused by the expensive
@@ -2535,7 +2535,7 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
25352535 lto->add (*file);
25362536
25372537 if (!ctx.bitcodeFiles .empty ())
2538- markBuffersAsDontNeed (skipLinkedOutput);
2538+ markBuffersAsDontNeed (ctx, skipLinkedOutput);
25392539
25402540 for (InputFile *file : lto->compile ()) {
25412541 auto *obj = cast<ObjFile<ELFT>>(file);
@@ -2569,7 +2569,8 @@ struct WrappedSymbol {
25692569// This function instantiates wrapper symbols. At this point, they seem
25702570// like they are not being used at all, so we explicitly set some flags so
25712571// 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) {
25732574 std::vector<WrappedSymbol> v;
25742575 DenseSet<StringRef> seen;
25752576
@@ -2620,7 +2621,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {
26202621 return v;
26212622}
26222623
2623- static void combineVersionedSymbol (Symbol &sym,
2624+ static void combineVersionedSymbol (Ctx &ctx, Symbol &sym,
26242625 DenseMap<Symbol *, Symbol *> &map) {
26252626 const char *suffix1 = sym.getVersionSuffix ();
26262627 if (suffix1[0 ] != ' @' || suffix1[1 ] == ' @' )
@@ -2687,7 +2688,7 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
26872688 if (ctx.arg .versionDefinitions .size () > 2 )
26882689 for (Symbol *sym : ctx.symtab ->getSymbols ())
26892690 if (sym->hasVersionSuffix )
2690- combineVersionedSymbol (*sym, map);
2691+ combineVersionedSymbol (ctx, *sym, map);
26912692
26922693 if (map.empty ())
26932694 return ;
@@ -2927,7 +2928,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29272928 }
29282929
29292930 // Archive members defining __wrap symbols may be extracted.
2930- std::vector<WrappedSymbol> wrapped = addWrappedSymbols (args);
2931+ std::vector<WrappedSymbol> wrapped = addWrappedSymbols (ctx, args);
29312932
29322933 // No more lazy bitcode can be extracted at this point. Do post parse work
29332934 // like checking duplicate symbols.
0 commit comments