@@ -850,7 +850,7 @@ static ICFLevel getICF(opt::InputArgList &args) {
850850 return ICFLevel::All;
851851}
852852
853- static StripPolicy getStrip (opt::InputArgList &args) {
853+ static StripPolicy getStrip (Ctx &ctx, opt::InputArgList &args) {
854854 if (args.hasArg (OPT_relocatable))
855855 return StripPolicy::None;
856856 if (!ctx.arg .zSectionHeader )
@@ -953,7 +953,7 @@ static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) {
953953 return {false , false };
954954}
955955
956- static void readCallGraph (MemoryBufferRef mb) {
956+ static void readCallGraph (Ctx &ctx, MemoryBufferRef mb) {
957957 // Build a map from symbol name to section
958958 DenseMap<StringRef, Symbol *> map;
959959 for (ELFFileBase *file : ctx.objectFiles )
@@ -1041,7 +1041,7 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
10411041 return !symbolIndices.empty ();
10421042}
10431043
1044- template <class ELFT > static void readCallGraphsFromObjectFiles () {
1044+ template <class ELFT > static void readCallGraphsFromObjectFiles (Ctx &ctx ) {
10451045 SmallVector<uint32_t , 32 > symbolIndices;
10461046 ArrayRef<typename ELFT::CGProfile> cgProfile;
10471047 for (auto file : ctx.objectFiles ) {
@@ -1070,7 +1070,8 @@ template <class ELFT> static void readCallGraphsFromObjectFiles() {
10701070}
10711071
10721072template <class ELFT >
1073- static void ltoValidateAllVtablesHaveTypeInfos (opt::InputArgList &args) {
1073+ static void ltoValidateAllVtablesHaveTypeInfos (Ctx &ctx,
1074+ opt::InputArgList &args) {
10741075 DenseSet<StringRef> typeInfoSymbols;
10751076 SmallSetVector<StringRef, 0 > vtableSymbols;
10761077 auto processVtableAndTypeInfoSymbols = [&](StringRef name) {
@@ -1184,7 +1185,8 @@ getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
11841185}
11851186
11861187// Parse the symbol ordering file and warn for any duplicate entries.
1187- static SmallVector<StringRef, 0 > getSymbolOrderingFile (MemoryBufferRef mb) {
1188+ static SmallVector<StringRef, 0 > getSymbolOrderingFile (Ctx &ctx,
1189+ MemoryBufferRef mb) {
11881190 SetVector<StringRef, SmallVector<StringRef, 0 >> names;
11891191 for (StringRef s : args::getLines (mb))
11901192 if (!names.insert (s) && ctx.arg .warnSymbolOrdering )
@@ -1193,7 +1195,7 @@ static SmallVector<StringRef, 0> getSymbolOrderingFile(MemoryBufferRef mb) {
11931195 return names.takeVector ();
11941196}
11951197
1196- static bool getIsRela (opt::InputArgList &args) {
1198+ static bool getIsRela (Ctx &ctx, opt::InputArgList &args) {
11971199 // The psABI specifies the default relocation entry format.
11981200 bool rela = is_contained ({EM_AARCH64, EM_AMDGPU, EM_HEXAGON, EM_LOONGARCH,
11991201 EM_PPC, EM_PPC64, EM_RISCV, EM_S390, EM_X86_64},
@@ -1212,7 +1214,7 @@ static bool getIsRela(opt::InputArgList &args) {
12121214 return rela;
12131215}
12141216
1215- static void parseClangOption (StringRef opt, const Twine &msg) {
1217+ static void parseClangOption (Ctx &ctx, StringRef opt, const Twine &msg) {
12161218 std::string err;
12171219 raw_string_ostream os (err);
12181220
@@ -1228,7 +1230,7 @@ static bool isValidReportString(StringRef arg) {
12281230}
12291231
12301232// Process a remap pattern 'from-glob=to-file'.
1231- static bool remapInputs (StringRef line, const Twine &location) {
1233+ static bool remapInputs (Ctx &ctx, StringRef line, const Twine &location) {
12321234 SmallVector<StringRef, 0 > fields;
12331235 line.split (fields, ' =' );
12341236 if (fields.size () != 2 || fields[1 ].empty ()) {
@@ -1440,7 +1442,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14401442 args::getInteger (args, OPT_split_stack_adjust_size, 16384 );
14411443 ctx.arg .zSectionHeader =
14421444 getZFlag (args, " sectionheader" , " nosectionheader" , true );
1443- ctx.arg .strip = getStrip (args); // needs zSectionHeader
1445+ ctx.arg .strip = getStrip (ctx, args); // needs zSectionHeader
14441446 ctx.arg .sysroot = args.getLastArgValue (OPT_sysroot);
14451447 ctx.arg .target1Rel = args.hasFlag (OPT_target1_rel, OPT_target1_abs, false );
14461448 ctx.arg .target2 = getTarget2 (args);
@@ -1535,7 +1537,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
15351537
15361538 for (opt::Arg *arg : args.filtered (OPT_remap_inputs)) {
15371539 StringRef value (arg->getValue ());
1538- remapInputs (value, arg->getSpelling ());
1540+ remapInputs (ctx, value, arg->getSpelling ());
15391541 }
15401542 for (opt::Arg *arg : args.filtered (OPT_remap_inputs_file)) {
15411543 StringRef filename (arg->getValue ());
@@ -1544,7 +1546,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
15441546 continue ;
15451547 // Parse 'from-glob=to-file' lines, ignoring #-led comments.
15461548 for (auto [lineno, line] : llvm::enumerate (args::getLines (*buffer)))
1547- if (remapInputs (line, filename + " :" + Twine (lineno + 1 )))
1549+ if (remapInputs (ctx, line, filename + " :" + Twine (lineno + 1 )))
15481550 break ;
15491551 }
15501552
@@ -1637,11 +1639,12 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16371639
16381640 // Parse LTO options.
16391641 if (auto *arg = args.getLastArg (OPT_plugin_opt_mcpu_eq))
1640- parseClangOption (saver ().save (" -mcpu=" + StringRef (arg->getValue ())),
1642+ parseClangOption (ctx, saver ().save (" -mcpu=" + StringRef (arg->getValue ())),
16411643 arg->getSpelling ());
16421644
16431645 for (opt::Arg *arg : args.filtered (OPT_plugin_opt_eq_minus))
1644- parseClangOption (std::string (" -" ) + arg->getValue (), arg->getSpelling ());
1646+ parseClangOption (ctx, std::string (" -" ) + arg->getValue (),
1647+ arg->getSpelling ());
16451648
16461649 // GCC collect2 passes -plugin-opt=path/to/lto-wrapper with an absolute or
16471650 // relative path. Just ignore. If not ended with "lto-wrapper" (or
@@ -1658,7 +1661,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16581661
16591662 // Parse -mllvm options.
16601663 for (const auto *arg : args.filtered (OPT_mllvm)) {
1661- parseClangOption (arg->getValue (), arg->getSpelling ());
1664+ parseClangOption (ctx, arg->getValue (), arg->getSpelling ());
16621665 ctx.arg .mllvmOpts .emplace_back (arg->getValue ());
16631666 }
16641667
@@ -1758,7 +1761,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
17581761 error (" --symbol-ordering-file and --call-graph-order-file "
17591762 " may not be used together" );
17601763 if (std::optional<MemoryBufferRef> buffer = readFile (arg->getValue ())) {
1761- ctx.arg .symbolOrderingFile = getSymbolOrderingFile (*buffer);
1764+ ctx.arg .symbolOrderingFile = getSymbolOrderingFile (ctx, *buffer);
17621765 // Also need to disable CallGraphProfileSort to prevent
17631766 // LLD order symbols with CGProfile
17641767 ctx.arg .callGraphProfileSort = CGProfileSortKind::None;
@@ -1851,7 +1854,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args) {
18511854 // We pick the format for dynamic relocations according to the psABI for each
18521855 // processor, but a contrary choice can be made if the dynamic loader
18531856 // supports.
1854- ctx.arg .isRela = getIsRela (args);
1857+ ctx.arg .isRela = getIsRela (ctx, args);
18551858
18561859 // If the output uses REL relocations we must store the dynamic relocation
18571860 // addends to the output sections. We also store addends for RELA relocations
@@ -2146,7 +2149,7 @@ static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &args) {
21462149// A special library name "ALL" means all archive files.
21472150//
21482151// This is not a popular option, but some programs such as bionic libc use it.
2149- static void excludeLibs (opt::InputArgList &args) {
2152+ static void excludeLibs (Ctx &ctx, opt::InputArgList &args) {
21502153 DenseSet<StringRef> libs = getExcludeLibs (args);
21512154 bool all = libs.count (" ALL" );
21522155
@@ -2441,7 +2444,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24412444// are used to control which partition a symbol is allocated to. See
24422445// https://lld.llvm.org/Partitions.html for more details on partitions.
24432446template <typename ELFT>
2444- static void readSymbolPartitionSection (InputSectionBase *s) {
2447+ static void readSymbolPartitionSection (Ctx &ctx, InputSectionBase *s) {
24452448 // Read the relocation that refers to the partition's entry point symbol.
24462449 Symbol *sym;
24472450 const RelsOrRelas<ELFT> rels = s->template relsOrRelas <ELFT>();
@@ -2961,7 +2964,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29612964 // 'has undefined version' error in -shared --exclude-libs=ALL mode (PR36295).
29622965 // GNU ld errors in this case.
29632966 if (args.hasArg (OPT_exclude_libs))
2964- excludeLibs (args);
2967+ excludeLibs (ctx, args);
29652968
29662969 // Create elfHeader early. We need a dummy section in
29672970 // addReservedSymbols to mark the created symbols as not absolute.
@@ -2994,7 +2997,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29942997
29952998 // Handle --lto-validate-all-vtables-have-type-infos.
29962999 if (ctx.arg .ltoValidateAllVtablesHaveTypeInfos )
2997- ltoValidateAllVtablesHaveTypeInfos<ELFT>(args);
3000+ ltoValidateAllVtablesHaveTypeInfos<ELFT>(ctx, args);
29983001
29993002 // Do link-time optimization if given files are LLVM bitcode files.
30003003 // This compiles bitcode files into real object files.
@@ -3045,7 +3048,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
30453048 // libcalls symbols defined in an excluded archive. This may override
30463049 // versionId set by scanVersionScript().
30473050 if (args.hasArg (OPT_exclude_libs))
3048- excludeLibs (args);
3051+ excludeLibs (ctx, args);
30493052
30503053 // Record [__acle_se_<sym>, <sym>] pairs for later processing.
30513054 processArmCmseSymbols ();
@@ -3079,10 +3082,10 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
30793082 {
30803083 llvm::TimeTraceScope timeScope (" Strip sections" );
30813084 if (ctx.hasSympart .load (std::memory_order_relaxed)) {
3082- llvm::erase_if (ctx.inputSections , [](InputSectionBase *s) {
3085+ llvm::erase_if (ctx.inputSections , [&ctx = ctx ](InputSectionBase *s) {
30833086 if (s->type != SHT_LLVM_SYMPART)
30843087 return false ;
3085- readSymbolPartitionSection<ELFT>(s);
3088+ readSymbolPartitionSection<ELFT>(ctx, s);
30863089 return true ;
30873090 });
30883091 }
@@ -3204,8 +3207,8 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
32043207 if (ctx.arg .callGraphProfileSort != CGProfileSortKind::None) {
32053208 if (auto *arg = args.getLastArg (OPT_call_graph_ordering_file))
32063209 if (std::optional<MemoryBufferRef> buffer = readFile (arg->getValue ()))
3207- readCallGraph (*buffer);
3208- readCallGraphsFromObjectFiles<ELFT>();
3210+ readCallGraph (ctx, *buffer);
3211+ readCallGraphsFromObjectFiles<ELFT>(ctx );
32093212 }
32103213
32113214 // Write the result to the file.
0 commit comments