@@ -600,7 +600,7 @@ static uint8_t getZStartStopVisibility(opt::InputArgList &args) {
600
600
return ret;
601
601
}
602
602
603
- static GcsPolicy getZGcs (opt::InputArgList &args) {
603
+ static GcsPolicy getZGcs (Ctx &ctx, opt::InputArgList &args) {
604
604
GcsPolicy ret = GcsPolicy::Implicit;
605
605
for (auto *arg : args.filtered (OPT_z)) {
606
606
std::pair<StringRef, StringRef> kv = StringRef (arg->getValue ()).split (' =' );
@@ -620,7 +620,7 @@ static GcsPolicy getZGcs(opt::InputArgList &args) {
620
620
}
621
621
622
622
// Report a warning for an unknown -z option.
623
- static void checkZOptions (opt::InputArgList &args) {
623
+ static void checkZOptions (Ctx &ctx, opt::InputArgList &args) {
624
624
// This function is called before getTarget(), when certain options are not
625
625
// initialized yet. Claim them here.
626
626
args::getZOptionValue (args, OPT_z, " max-page-size" , 0 );
@@ -639,7 +639,7 @@ LinkerDriver::LinkerDriver(Ctx &ctx) : ctx(ctx) {}
639
639
640
640
void LinkerDriver::linkerMain (ArrayRef<const char *> argsArr) {
641
641
ELFOptTable parser;
642
- opt::InputArgList args = parser.parse (argsArr.slice (1 ));
642
+ opt::InputArgList args = parser.parse (ctx, argsArr.slice (1 ));
643
643
644
644
// Interpret these flags early because error()/warn() depend on them.
645
645
errorHandler ().errorLimit = args::getInteger (args, OPT_error_limit, 20 );
@@ -689,7 +689,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
689
689
}
690
690
691
691
readConfigs (ctx, args);
692
- checkZOptions (args);
692
+ checkZOptions (ctx, args);
693
693
694
694
// The behavior of -v or --version is a bit strange, but this is
695
695
// needed for compatibility with GNU linkers.
@@ -790,7 +790,7 @@ static void setUnresolvedSymbolPolicy(Ctx &ctx, opt::InputArgList &args) {
790
790
diagShlib ? errorOrWarn : UnresolvedPolicy::Ignore;
791
791
}
792
792
793
- static Target2Policy getTarget2 (opt::InputArgList &args) {
793
+ static Target2Policy getTarget2 (Ctx &ctx, opt::InputArgList &args) {
794
794
StringRef s = args.getLastArgValue (OPT_target2, " got-rel" );
795
795
if (s == " rel" )
796
796
return Target2Policy::Rel;
@@ -802,7 +802,7 @@ static Target2Policy getTarget2(opt::InputArgList &args) {
802
802
return Target2Policy::GotRel;
803
803
}
804
804
805
- static bool isOutputFormatBinary (opt::InputArgList &args) {
805
+ static bool isOutputFormatBinary (Ctx &ctx, opt::InputArgList &args) {
806
806
StringRef s = args.getLastArgValue (OPT_oformat, " elf" );
807
807
if (s == " binary" )
808
808
return true ;
@@ -882,7 +882,8 @@ static StripPolicy getStrip(Ctx &ctx, opt::InputArgList &args) {
882
882
return StripPolicy::Debug;
883
883
}
884
884
885
- static uint64_t parseSectionAddress (StringRef s, opt::InputArgList &args,
885
+ static uint64_t parseSectionAddress (Ctx &ctx, StringRef s,
886
+ opt::InputArgList &args,
886
887
const opt::Arg &arg) {
887
888
uint64_t va = 0 ;
888
889
s.consume_front (" 0x" );
@@ -891,25 +892,26 @@ static uint64_t parseSectionAddress(StringRef s, opt::InputArgList &args,
891
892
return va;
892
893
}
893
894
894
- static StringMap<uint64_t > getSectionStartMap (opt::InputArgList &args) {
895
+ static StringMap<uint64_t > getSectionStartMap (Ctx &ctx,
896
+ opt::InputArgList &args) {
895
897
StringMap<uint64_t > ret;
896
898
for (auto *arg : args.filtered (OPT_section_start)) {
897
899
StringRef name;
898
900
StringRef addr;
899
901
std::tie (name, addr) = StringRef (arg->getValue ()).split (' =' );
900
- ret[name] = parseSectionAddress (addr, args, *arg);
902
+ ret[name] = parseSectionAddress (ctx, addr, args, *arg);
901
903
}
902
904
903
905
if (auto *arg = args.getLastArg (OPT_Ttext))
904
- ret[" .text" ] = parseSectionAddress (arg->getValue (), args, *arg);
906
+ ret[" .text" ] = parseSectionAddress (ctx, arg->getValue (), args, *arg);
905
907
if (auto *arg = args.getLastArg (OPT_Tdata))
906
- ret[" .data" ] = parseSectionAddress (arg->getValue (), args, *arg);
908
+ ret[" .data" ] = parseSectionAddress (ctx, arg->getValue (), args, *arg);
907
909
if (auto *arg = args.getLastArg (OPT_Tbss))
908
- ret[" .bss" ] = parseSectionAddress (arg->getValue (), args, *arg);
910
+ ret[" .bss" ] = parseSectionAddress (ctx, arg->getValue (), args, *arg);
909
911
return ret;
910
912
}
911
913
912
- static SortSectionPolicy getSortSection (opt::InputArgList &args) {
914
+ static SortSectionPolicy getSortSection (Ctx &ctx, opt::InputArgList &args) {
913
915
StringRef s = args.getLastArgValue (OPT_sort_section);
914
916
if (s == " alignment" )
915
917
return SortSectionPolicy::Alignment;
@@ -920,7 +922,8 @@ static SortSectionPolicy getSortSection(opt::InputArgList &args) {
920
922
return SortSectionPolicy::Default;
921
923
}
922
924
923
- static OrphanHandlingPolicy getOrphanHandling (opt::InputArgList &args) {
925
+ static OrphanHandlingPolicy getOrphanHandling (Ctx &ctx,
926
+ opt::InputArgList &args) {
924
927
StringRef s = args.getLastArgValue (OPT_orphan_handling, " place" );
925
928
if (s == " warn" )
926
929
return OrphanHandlingPolicy::Warn;
@@ -935,7 +938,7 @@ static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &args) {
935
938
// synonym for "sha1" because all our hash functions including
936
939
// --build-id=sha1 are actually tree hashes for performance reasons.
937
940
static std::pair<BuildIdKind, SmallVector<uint8_t , 0 >>
938
- getBuildId (opt::InputArgList &args) {
941
+ getBuildId (Ctx &ctx, opt::InputArgList &args) {
939
942
auto *arg = args.getLastArg (OPT_build_id);
940
943
if (!arg)
941
944
return {BuildIdKind::None, {}};
@@ -957,7 +960,8 @@ getBuildId(opt::InputArgList &args) {
957
960
return {BuildIdKind::None, {}};
958
961
}
959
962
960
- static std::pair<bool , bool > getPackDynRelocs (opt::InputArgList &args) {
963
+ static std::pair<bool , bool > getPackDynRelocs (Ctx &ctx,
964
+ opt::InputArgList &args) {
961
965
StringRef s = args.getLastArgValue (OPT_pack_dyn_relocs, " none" );
962
966
if (s == " android" )
963
967
return {true , false };
@@ -1152,7 +1156,8 @@ static void ltoValidateAllVtablesHaveTypeInfos(Ctx &ctx,
1152
1156
}
1153
1157
}
1154
1158
1155
- static CGProfileSortKind getCGProfileSortKind (opt::InputArgList &args) {
1159
+ static CGProfileSortKind getCGProfileSortKind (Ctx &ctx,
1160
+ opt::InputArgList &args) {
1156
1161
StringRef s = args.getLastArgValue (OPT_call_graph_profile_sort, " cdsort" );
1157
1162
if (s == " hfsort" )
1158
1163
return CGProfileSortKind::Hfsort;
@@ -1163,7 +1168,8 @@ static CGProfileSortKind getCGProfileSortKind(opt::InputArgList &args) {
1163
1168
return CGProfileSortKind::None;
1164
1169
}
1165
1170
1166
- static DebugCompressionType getCompressionType (StringRef s, StringRef option) {
1171
+ static DebugCompressionType getCompressionType (Ctx &ctx, StringRef s,
1172
+ StringRef option) {
1167
1173
DebugCompressionType type = StringSwitch<DebugCompressionType>(s)
1168
1174
.Case (" zlib" , DebugCompressionType::Zlib)
1169
1175
.Case (" zstd" , DebugCompressionType::Zstd)
@@ -1184,8 +1190,8 @@ static StringRef getAliasSpelling(opt::Arg *arg) {
1184
1190
return arg->getSpelling ();
1185
1191
}
1186
1192
1187
- static std::pair<StringRef, StringRef> getOldNewOptions (opt::InputArgList &args,
1188
- unsigned id) {
1193
+ static std::pair<StringRef, StringRef>
1194
+ getOldNewOptions (Ctx &ctx, opt::InputArgList &args, unsigned id) {
1189
1195
auto *arg = args.getLastArg (id);
1190
1196
if (!arg)
1191
1197
return {" " , " " };
@@ -1200,8 +1206,8 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
1200
1206
1201
1207
// Parse options of the form "old;new[;extra]".
1202
1208
static std::tuple<StringRef, StringRef, StringRef>
1203
- getOldNewOptionsExtra (opt::InputArgList &args, unsigned id) {
1204
- auto [oldDir, second] = getOldNewOptions (args, id);
1209
+ getOldNewOptionsExtra (Ctx &ctx, opt::InputArgList &args, unsigned id) {
1210
+ auto [oldDir, second] = getOldNewOptions (ctx, args, id);
1205
1211
auto [newDir, extraDir] = second.split (' ;' );
1206
1212
return {oldDir, newDir, extraDir};
1207
1213
}
@@ -1303,13 +1309,13 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1303
1309
else if (arg->getOption ().matches (OPT_Bsymbolic))
1304
1310
ctx.arg .bsymbolic = BsymbolicKind::All;
1305
1311
}
1306
- ctx.arg .callGraphProfileSort = getCGProfileSortKind (args);
1312
+ ctx.arg .callGraphProfileSort = getCGProfileSortKind (ctx, args);
1307
1313
ctx.arg .checkSections =
1308
1314
args.hasFlag (OPT_check_sections, OPT_no_check_sections, true );
1309
1315
ctx.arg .chroot = args.getLastArgValue (OPT_chroot);
1310
1316
if (auto *arg = args.getLastArg (OPT_compress_debug_sections)) {
1311
1317
ctx.arg .compressDebugSections =
1312
- getCompressionType (arg->getValue (), " --compress-debug-sections" );
1318
+ getCompressionType (ctx, arg->getValue (), " --compress-debug-sections" );
1313
1319
}
1314
1320
ctx.arg .cref = args.hasArg (OPT_cref);
1315
1321
ctx.arg .optimizeBBJumps =
@@ -1406,7 +1412,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1406
1412
ctx.arg .nmagic = args.hasFlag (OPT_nmagic, OPT_no_nmagic, false );
1407
1413
ctx.arg .noinhibitExec = args.hasArg (OPT_noinhibit_exec);
1408
1414
ctx.arg .nostdlib = args.hasArg (OPT_nostdlib);
1409
- ctx.arg .oFormatBinary = isOutputFormatBinary (args);
1415
+ ctx.arg .oFormatBinary = isOutputFormatBinary (ctx, args);
1410
1416
ctx.arg .omagic = args.hasFlag (OPT_omagic, OPT_no_omagic, false );
1411
1417
ctx.arg .optRemarksFilename = args.getLastArgValue (OPT_opt_remarks_filename);
1412
1418
ctx.arg .optStatsFilename = args.getLastArgValue (OPT_plugin_opt_stats_file);
@@ -1426,7 +1432,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1426
1432
ctx.arg .optRemarksWithHotness = args.hasArg (OPT_opt_remarks_with_hotness);
1427
1433
ctx.arg .optRemarksFormat = args.getLastArgValue (OPT_opt_remarks_format);
1428
1434
ctx.arg .optimize = args::getInteger (args, OPT_O, 1 );
1429
- ctx.arg .orphanHandling = getOrphanHandling (args);
1435
+ ctx.arg .orphanHandling = getOrphanHandling (ctx, args);
1430
1436
ctx.arg .outputFile = args.getLastArgValue (OPT_o);
1431
1437
ctx.arg .packageMetadata = args.getLastArgValue (OPT_package_metadata);
1432
1438
ctx.arg .pie = args.hasFlag (OPT_pie, OPT_no_pie, false );
@@ -1460,19 +1466,19 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1460
1466
}
1461
1467
1462
1468
ctx.arg .searchPaths = args::getStrings (args, OPT_library_path);
1463
- ctx.arg .sectionStartMap = getSectionStartMap (args);
1469
+ ctx.arg .sectionStartMap = getSectionStartMap (ctx, args);
1464
1470
ctx.arg .shared = args.hasArg (OPT_shared);
1465
1471
ctx.arg .singleRoRx = !args.hasFlag (OPT_rosegment, OPT_no_rosegment, true );
1466
1472
ctx.arg .soName = args.getLastArgValue (OPT_soname);
1467
- ctx.arg .sortSection = getSortSection (args);
1473
+ ctx.arg .sortSection = getSortSection (ctx, args);
1468
1474
ctx.arg .splitStackAdjustSize =
1469
1475
args::getInteger (args, OPT_split_stack_adjust_size, 16384 );
1470
1476
ctx.arg .zSectionHeader =
1471
1477
getZFlag (args, " sectionheader" , " nosectionheader" , true );
1472
1478
ctx.arg .strip = getStrip (ctx, args); // needs zSectionHeader
1473
1479
ctx.arg .sysroot = args.getLastArgValue (OPT_sysroot);
1474
1480
ctx.arg .target1Rel = args.hasFlag (OPT_target1_rel, OPT_target1_abs, false );
1475
- ctx.arg .target2 = getTarget2 (args);
1481
+ ctx.arg .target2 = getTarget2 (ctx, args);
1476
1482
ctx.arg .thinLTOCacheDir = args.getLastArgValue (OPT_thinlto_cache_dir);
1477
1483
ctx.arg .thinLTOCachePolicy = CHECK (
1478
1484
parseCachePruningPolicy (args.getLastArgValue (OPT_thinlto_cache_policy)),
@@ -1485,10 +1491,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1485
1491
args.hasArg (OPT_thinlto_index_only_eq);
1486
1492
ctx.arg .thinLTOIndexOnlyArg = args.getLastArgValue (OPT_thinlto_index_only_eq);
1487
1493
ctx.arg .thinLTOObjectSuffixReplace =
1488
- getOldNewOptions (args, OPT_thinlto_object_suffix_replace_eq);
1494
+ getOldNewOptions (ctx, args, OPT_thinlto_object_suffix_replace_eq);
1489
1495
std::tie (ctx.arg .thinLTOPrefixReplaceOld , ctx.arg .thinLTOPrefixReplaceNew ,
1490
1496
ctx.arg .thinLTOPrefixReplaceNativeObject ) =
1491
- getOldNewOptionsExtra (args, OPT_thinlto_prefix_replace_eq);
1497
+ getOldNewOptionsExtra (ctx, args, OPT_thinlto_prefix_replace_eq);
1492
1498
if (ctx.arg .thinLTOEmitIndexFiles && !ctx.arg .thinLTOIndexOnly ) {
1493
1499
if (args.hasArg (OPT_thinlto_object_suffix_replace_eq))
1494
1500
ErrAlways (ctx) << " --thinlto-object-suffix-replace is not supported with "
@@ -1525,7 +1531,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1525
1531
ctx.arg .zCopyreloc = getZFlag (args, " copyreloc" , " nocopyreloc" , true );
1526
1532
ctx.arg .zForceBti = hasZOption (args, " force-bti" );
1527
1533
ctx.arg .zForceIbt = hasZOption (args, " force-ibt" );
1528
- ctx.arg .zGcs = getZGcs (args);
1534
+ ctx.arg .zGcs = getZGcs (ctx, args);
1529
1535
ctx.arg .zGlobal = hasZOption (args, " global" );
1530
1536
ctx.arg .zGnustack = getZGnuStack (args);
1531
1537
ctx.arg .zHazardplt = hasZOption (args, " hazardplt" );
@@ -1627,7 +1633,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1627
1633
continue ;
1628
1634
}
1629
1635
auto [typeStr, levelStr] = fields[1 ].split (' :' );
1630
- auto type = getCompressionType (typeStr, arg->getSpelling ());
1636
+ auto type = getCompressionType (ctx, typeStr, arg->getSpelling ());
1631
1637
unsigned level = 0 ;
1632
1638
if (fields[1 ].size () != typeStr.size () &&
1633
1639
!llvm::to_integer (levelStr, level)) {
@@ -1781,14 +1787,14 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1781
1787
if (ctx.arg .nmagic || ctx.arg .omagic || ctx.arg .relocatable )
1782
1788
ctx.arg .zRelro = false ;
1783
1789
1784
- std::tie (ctx.arg .buildId , ctx.arg .buildIdVector ) = getBuildId (args);
1790
+ std::tie (ctx.arg .buildId , ctx.arg .buildIdVector ) = getBuildId (ctx, args);
1785
1791
1786
1792
if (getZFlag (args, " pack-relative-relocs" , " nopack-relative-relocs" , false )) {
1787
1793
ctx.arg .relrGlibc = true ;
1788
1794
ctx.arg .relrPackDynRelocs = true ;
1789
1795
} else {
1790
1796
std::tie (ctx.arg .androidPackDynRelocs , ctx.arg .relrPackDynRelocs ) =
1791
- getPackDynRelocs (args);
1797
+ getPackDynRelocs (ctx, args);
1792
1798
}
1793
1799
1794
1800
if (auto *arg = args.getLastArg (OPT_symbol_ordering_file)){
@@ -1949,7 +1955,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args) {
1949
1955
}
1950
1956
}
1951
1957
1952
- static bool isFormatBinary (StringRef s) {
1958
+ static bool isFormatBinary (Ctx &ctx, StringRef s) {
1953
1959
if (s == " binary" )
1954
1960
return true ;
1955
1961
if (s == " elf" || s == " default" )
@@ -2006,7 +2012,7 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
2006
2012
ctx.arg .asNeeded = true ;
2007
2013
break ;
2008
2014
case OPT_format:
2009
- ctx.arg .formatBinary = isFormatBinary (arg->getValue ());
2015
+ ctx.arg .formatBinary = isFormatBinary (ctx, arg->getValue ());
2010
2016
break ;
2011
2017
case OPT_no_as_needed:
2012
2018
ctx.arg .asNeeded = false ;
0 commit comments