@@ -850,7 +850,7 @@ static ICFLevel getICF(opt::InputArgList &args) {
850
850
return ICFLevel::All;
851
851
}
852
852
853
- static StripPolicy getStrip (opt::InputArgList &args) {
853
+ static StripPolicy getStrip (Ctx &ctx, opt::InputArgList &args) {
854
854
if (args.hasArg (OPT_relocatable))
855
855
return StripPolicy::None;
856
856
if (!ctx.arg .zSectionHeader )
@@ -953,7 +953,7 @@ static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) {
953
953
return {false , false };
954
954
}
955
955
956
- static void readCallGraph (MemoryBufferRef mb) {
956
+ static void readCallGraph (Ctx &ctx, MemoryBufferRef mb) {
957
957
// Build a map from symbol name to section
958
958
DenseMap<StringRef, Symbol *> map;
959
959
for (ELFFileBase *file : ctx.objectFiles )
@@ -1041,7 +1041,7 @@ processCallGraphRelocations(SmallVector<uint32_t, 32> &symbolIndices,
1041
1041
return !symbolIndices.empty ();
1042
1042
}
1043
1043
1044
- template <class ELFT > static void readCallGraphsFromObjectFiles () {
1044
+ template <class ELFT > static void readCallGraphsFromObjectFiles (Ctx &ctx ) {
1045
1045
SmallVector<uint32_t , 32 > symbolIndices;
1046
1046
ArrayRef<typename ELFT::CGProfile> cgProfile;
1047
1047
for (auto file : ctx.objectFiles ) {
@@ -1070,7 +1070,8 @@ template <class ELFT> static void readCallGraphsFromObjectFiles() {
1070
1070
}
1071
1071
1072
1072
template <class ELFT >
1073
- static void ltoValidateAllVtablesHaveTypeInfos (opt::InputArgList &args) {
1073
+ static void ltoValidateAllVtablesHaveTypeInfos (Ctx &ctx,
1074
+ opt::InputArgList &args) {
1074
1075
DenseSet<StringRef> typeInfoSymbols;
1075
1076
SmallSetVector<StringRef, 0 > vtableSymbols;
1076
1077
auto processVtableAndTypeInfoSymbols = [&](StringRef name) {
@@ -1184,7 +1185,8 @@ getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
1184
1185
}
1185
1186
1186
1187
// 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) {
1188
1190
SetVector<StringRef, SmallVector<StringRef, 0 >> names;
1189
1191
for (StringRef s : args::getLines (mb))
1190
1192
if (!names.insert (s) && ctx.arg .warnSymbolOrdering )
@@ -1193,7 +1195,7 @@ static SmallVector<StringRef, 0> getSymbolOrderingFile(MemoryBufferRef mb) {
1193
1195
return names.takeVector ();
1194
1196
}
1195
1197
1196
- static bool getIsRela (opt::InputArgList &args) {
1198
+ static bool getIsRela (Ctx &ctx, opt::InputArgList &args) {
1197
1199
// The psABI specifies the default relocation entry format.
1198
1200
bool rela = is_contained ({EM_AARCH64, EM_AMDGPU, EM_HEXAGON, EM_LOONGARCH,
1199
1201
EM_PPC, EM_PPC64, EM_RISCV, EM_S390, EM_X86_64},
@@ -1212,7 +1214,7 @@ static bool getIsRela(opt::InputArgList &args) {
1212
1214
return rela;
1213
1215
}
1214
1216
1215
- static void parseClangOption (StringRef opt, const Twine &msg) {
1217
+ static void parseClangOption (Ctx &ctx, StringRef opt, const Twine &msg) {
1216
1218
std::string err;
1217
1219
raw_string_ostream os (err);
1218
1220
@@ -1228,7 +1230,7 @@ static bool isValidReportString(StringRef arg) {
1228
1230
}
1229
1231
1230
1232
// 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) {
1232
1234
SmallVector<StringRef, 0 > fields;
1233
1235
line.split (fields, ' =' );
1234
1236
if (fields.size () != 2 || fields[1 ].empty ()) {
@@ -1440,7 +1442,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1440
1442
args::getInteger (args, OPT_split_stack_adjust_size, 16384 );
1441
1443
ctx.arg .zSectionHeader =
1442
1444
getZFlag (args, " sectionheader" , " nosectionheader" , true );
1443
- ctx.arg .strip = getStrip (args); // needs zSectionHeader
1445
+ ctx.arg .strip = getStrip (ctx, args); // needs zSectionHeader
1444
1446
ctx.arg .sysroot = args.getLastArgValue (OPT_sysroot);
1445
1447
ctx.arg .target1Rel = args.hasFlag (OPT_target1_rel, OPT_target1_abs, false );
1446
1448
ctx.arg .target2 = getTarget2 (args);
@@ -1535,7 +1537,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1535
1537
1536
1538
for (opt::Arg *arg : args.filtered (OPT_remap_inputs)) {
1537
1539
StringRef value (arg->getValue ());
1538
- remapInputs (value, arg->getSpelling ());
1540
+ remapInputs (ctx, value, arg->getSpelling ());
1539
1541
}
1540
1542
for (opt::Arg *arg : args.filtered (OPT_remap_inputs_file)) {
1541
1543
StringRef filename (arg->getValue ());
@@ -1544,7 +1546,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1544
1546
continue ;
1545
1547
// Parse 'from-glob=to-file' lines, ignoring #-led comments.
1546
1548
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 )))
1548
1550
break ;
1549
1551
}
1550
1552
@@ -1637,11 +1639,12 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1637
1639
1638
1640
// Parse LTO options.
1639
1641
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 ())),
1641
1643
arg->getSpelling ());
1642
1644
1643
1645
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 ());
1645
1648
1646
1649
// GCC collect2 passes -plugin-opt=path/to/lto-wrapper with an absolute or
1647
1650
// relative path. Just ignore. If not ended with "lto-wrapper" (or
@@ -1658,7 +1661,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1658
1661
1659
1662
// Parse -mllvm options.
1660
1663
for (const auto *arg : args.filtered (OPT_mllvm)) {
1661
- parseClangOption (arg->getValue (), arg->getSpelling ());
1664
+ parseClangOption (ctx, arg->getValue (), arg->getSpelling ());
1662
1665
ctx.arg .mllvmOpts .emplace_back (arg->getValue ());
1663
1666
}
1664
1667
@@ -1758,7 +1761,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1758
1761
error (" --symbol-ordering-file and --call-graph-order-file "
1759
1762
" may not be used together" );
1760
1763
if (std::optional<MemoryBufferRef> buffer = readFile (arg->getValue ())) {
1761
- ctx.arg .symbolOrderingFile = getSymbolOrderingFile (*buffer);
1764
+ ctx.arg .symbolOrderingFile = getSymbolOrderingFile (ctx, *buffer);
1762
1765
// Also need to disable CallGraphProfileSort to prevent
1763
1766
// LLD order symbols with CGProfile
1764
1767
ctx.arg .callGraphProfileSort = CGProfileSortKind::None;
@@ -1851,7 +1854,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args) {
1851
1854
// We pick the format for dynamic relocations according to the psABI for each
1852
1855
// processor, but a contrary choice can be made if the dynamic loader
1853
1856
// supports.
1854
- ctx.arg .isRela = getIsRela (args);
1857
+ ctx.arg .isRela = getIsRela (ctx, args);
1855
1858
1856
1859
// If the output uses REL relocations we must store the dynamic relocation
1857
1860
// addends to the output sections. We also store addends for RELA relocations
@@ -2146,7 +2149,7 @@ static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &args) {
2146
2149
// A special library name "ALL" means all archive files.
2147
2150
//
2148
2151
// 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) {
2150
2153
DenseSet<StringRef> libs = getExcludeLibs (args);
2151
2154
bool all = libs.count (" ALL" );
2152
2155
@@ -2441,7 +2444,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
2441
2444
// are used to control which partition a symbol is allocated to. See
2442
2445
// https://lld.llvm.org/Partitions.html for more details on partitions.
2443
2446
template <typename ELFT>
2444
- static void readSymbolPartitionSection (InputSectionBase *s) {
2447
+ static void readSymbolPartitionSection (Ctx &ctx, InputSectionBase *s) {
2445
2448
// Read the relocation that refers to the partition's entry point symbol.
2446
2449
Symbol *sym;
2447
2450
const RelsOrRelas<ELFT> rels = s->template relsOrRelas <ELFT>();
@@ -2961,7 +2964,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
2961
2964
// 'has undefined version' error in -shared --exclude-libs=ALL mode (PR36295).
2962
2965
// GNU ld errors in this case.
2963
2966
if (args.hasArg (OPT_exclude_libs))
2964
- excludeLibs (args);
2967
+ excludeLibs (ctx, args);
2965
2968
2966
2969
// Create elfHeader early. We need a dummy section in
2967
2970
// addReservedSymbols to mark the created symbols as not absolute.
@@ -2994,7 +2997,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
2994
2997
2995
2998
// Handle --lto-validate-all-vtables-have-type-infos.
2996
2999
if (ctx.arg .ltoValidateAllVtablesHaveTypeInfos )
2997
- ltoValidateAllVtablesHaveTypeInfos<ELFT>(args);
3000
+ ltoValidateAllVtablesHaveTypeInfos<ELFT>(ctx, args);
2998
3001
2999
3002
// Do link-time optimization if given files are LLVM bitcode files.
3000
3003
// This compiles bitcode files into real object files.
@@ -3045,7 +3048,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
3045
3048
// libcalls symbols defined in an excluded archive. This may override
3046
3049
// versionId set by scanVersionScript().
3047
3050
if (args.hasArg (OPT_exclude_libs))
3048
- excludeLibs (args);
3051
+ excludeLibs (ctx, args);
3049
3052
3050
3053
// Record [__acle_se_<sym>, <sym>] pairs for later processing.
3051
3054
processArmCmseSymbols ();
@@ -3079,10 +3082,10 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
3079
3082
{
3080
3083
llvm::TimeTraceScope timeScope (" Strip sections" );
3081
3084
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) {
3083
3086
if (s->type != SHT_LLVM_SYMPART)
3084
3087
return false ;
3085
- readSymbolPartitionSection<ELFT>(s);
3088
+ readSymbolPartitionSection<ELFT>(ctx, s);
3086
3089
return true ;
3087
3090
});
3088
3091
}
@@ -3204,8 +3207,8 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
3204
3207
if (ctx.arg .callGraphProfileSort != CGProfileSortKind::None) {
3205
3208
if (auto *arg = args.getLastArg (OPT_call_graph_ordering_file))
3206
3209
if (std::optional<MemoryBufferRef> buffer = readFile (arg->getValue ()))
3207
- readCallGraph (*buffer);
3208
- readCallGraphsFromObjectFiles<ELFT>();
3210
+ readCallGraph (ctx, *buffer);
3211
+ readCallGraphsFromObjectFiles<ELFT>(ctx );
3209
3212
}
3210
3213
3211
3214
// Write the result to the file.
0 commit comments