@@ -600,7 +600,7 @@ static uint8_t getZStartStopVisibility(opt::InputArgList &args) {
600600 return ret;
601601}
602602
603- static GcsPolicy getZGcs (opt::InputArgList &args) {
603+ static GcsPolicy getZGcs (Ctx &ctx, opt::InputArgList &args) {
604604 GcsPolicy ret = GcsPolicy::Implicit;
605605 for (auto *arg : args.filtered (OPT_z)) {
606606 std::pair<StringRef, StringRef> kv = StringRef (arg->getValue ()).split (' =' );
@@ -620,7 +620,7 @@ static GcsPolicy getZGcs(opt::InputArgList &args) {
620620}
621621
622622// Report a warning for an unknown -z option.
623- static void checkZOptions (opt::InputArgList &args) {
623+ static void checkZOptions (Ctx &ctx, opt::InputArgList &args) {
624624 // This function is called before getTarget(), when certain options are not
625625 // initialized yet. Claim them here.
626626 args::getZOptionValue (args, OPT_z, " max-page-size" , 0 );
@@ -639,7 +639,7 @@ LinkerDriver::LinkerDriver(Ctx &ctx) : ctx(ctx) {}
639639
640640void LinkerDriver::linkerMain (ArrayRef<const char *> argsArr) {
641641 ELFOptTable parser;
642- opt::InputArgList args = parser.parse (argsArr.slice (1 ));
642+ opt::InputArgList args = parser.parse (ctx, argsArr.slice (1 ));
643643
644644 // Interpret these flags early because error()/warn() depend on them.
645645 errorHandler ().errorLimit = args::getInteger (args, OPT_error_limit, 20 );
@@ -689,7 +689,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
689689 }
690690
691691 readConfigs (ctx, args);
692- checkZOptions (args);
692+ checkZOptions (ctx, args);
693693
694694 // The behavior of -v or --version is a bit strange, but this is
695695 // needed for compatibility with GNU linkers.
@@ -790,7 +790,7 @@ static void setUnresolvedSymbolPolicy(Ctx &ctx, opt::InputArgList &args) {
790790 diagShlib ? errorOrWarn : UnresolvedPolicy::Ignore;
791791}
792792
793- static Target2Policy getTarget2 (opt::InputArgList &args) {
793+ static Target2Policy getTarget2 (Ctx &ctx, opt::InputArgList &args) {
794794 StringRef s = args.getLastArgValue (OPT_target2, " got-rel" );
795795 if (s == " rel" )
796796 return Target2Policy::Rel;
@@ -802,7 +802,7 @@ static Target2Policy getTarget2(opt::InputArgList &args) {
802802 return Target2Policy::GotRel;
803803}
804804
805- static bool isOutputFormatBinary (opt::InputArgList &args) {
805+ static bool isOutputFormatBinary (Ctx &ctx, opt::InputArgList &args) {
806806 StringRef s = args.getLastArgValue (OPT_oformat, " elf" );
807807 if (s == " binary" )
808808 return true ;
@@ -882,7 +882,8 @@ static StripPolicy getStrip(Ctx &ctx, opt::InputArgList &args) {
882882 return StripPolicy::Debug;
883883}
884884
885- static uint64_t parseSectionAddress (StringRef s, opt::InputArgList &args,
885+ static uint64_t parseSectionAddress (Ctx &ctx, StringRef s,
886+ opt::InputArgList &args,
886887 const opt::Arg &arg) {
887888 uint64_t va = 0 ;
888889 s.consume_front (" 0x" );
@@ -891,25 +892,26 @@ static uint64_t parseSectionAddress(StringRef s, opt::InputArgList &args,
891892 return va;
892893}
893894
894- static StringMap<uint64_t > getSectionStartMap (opt::InputArgList &args) {
895+ static StringMap<uint64_t > getSectionStartMap (Ctx &ctx,
896+ opt::InputArgList &args) {
895897 StringMap<uint64_t > ret;
896898 for (auto *arg : args.filtered (OPT_section_start)) {
897899 StringRef name;
898900 StringRef addr;
899901 std::tie (name, addr) = StringRef (arg->getValue ()).split (' =' );
900- ret[name] = parseSectionAddress (addr, args, *arg);
902+ ret[name] = parseSectionAddress (ctx, addr, args, *arg);
901903 }
902904
903905 if (auto *arg = args.getLastArg (OPT_Ttext))
904- ret[" .text" ] = parseSectionAddress (arg->getValue (), args, *arg);
906+ ret[" .text" ] = parseSectionAddress (ctx, arg->getValue (), args, *arg);
905907 if (auto *arg = args.getLastArg (OPT_Tdata))
906- ret[" .data" ] = parseSectionAddress (arg->getValue (), args, *arg);
908+ ret[" .data" ] = parseSectionAddress (ctx, arg->getValue (), args, *arg);
907909 if (auto *arg = args.getLastArg (OPT_Tbss))
908- ret[" .bss" ] = parseSectionAddress (arg->getValue (), args, *arg);
910+ ret[" .bss" ] = parseSectionAddress (ctx, arg->getValue (), args, *arg);
909911 return ret;
910912}
911913
912- static SortSectionPolicy getSortSection (opt::InputArgList &args) {
914+ static SortSectionPolicy getSortSection (Ctx &ctx, opt::InputArgList &args) {
913915 StringRef s = args.getLastArgValue (OPT_sort_section);
914916 if (s == " alignment" )
915917 return SortSectionPolicy::Alignment;
@@ -920,7 +922,8 @@ static SortSectionPolicy getSortSection(opt::InputArgList &args) {
920922 return SortSectionPolicy::Default;
921923}
922924
923- static OrphanHandlingPolicy getOrphanHandling (opt::InputArgList &args) {
925+ static OrphanHandlingPolicy getOrphanHandling (Ctx &ctx,
926+ opt::InputArgList &args) {
924927 StringRef s = args.getLastArgValue (OPT_orphan_handling, " place" );
925928 if (s == " warn" )
926929 return OrphanHandlingPolicy::Warn;
@@ -935,7 +938,7 @@ static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &args) {
935938// synonym for "sha1" because all our hash functions including
936939// --build-id=sha1 are actually tree hashes for performance reasons.
937940static std::pair<BuildIdKind, SmallVector<uint8_t , 0 >>
938- getBuildId (opt::InputArgList &args) {
941+ getBuildId (Ctx &ctx, opt::InputArgList &args) {
939942 auto *arg = args.getLastArg (OPT_build_id);
940943 if (!arg)
941944 return {BuildIdKind::None, {}};
@@ -957,7 +960,8 @@ getBuildId(opt::InputArgList &args) {
957960 return {BuildIdKind::None, {}};
958961}
959962
960- static std::pair<bool , bool > getPackDynRelocs (opt::InputArgList &args) {
963+ static std::pair<bool , bool > getPackDynRelocs (Ctx &ctx,
964+ opt::InputArgList &args) {
961965 StringRef s = args.getLastArgValue (OPT_pack_dyn_relocs, " none" );
962966 if (s == " android" )
963967 return {true , false };
@@ -1152,7 +1156,8 @@ static void ltoValidateAllVtablesHaveTypeInfos(Ctx &ctx,
11521156 }
11531157}
11541158
1155- static CGProfileSortKind getCGProfileSortKind (opt::InputArgList &args) {
1159+ static CGProfileSortKind getCGProfileSortKind (Ctx &ctx,
1160+ opt::InputArgList &args) {
11561161 StringRef s = args.getLastArgValue (OPT_call_graph_profile_sort, " cdsort" );
11571162 if (s == " hfsort" )
11581163 return CGProfileSortKind::Hfsort;
@@ -1163,7 +1168,8 @@ static CGProfileSortKind getCGProfileSortKind(opt::InputArgList &args) {
11631168 return CGProfileSortKind::None;
11641169}
11651170
1166- static DebugCompressionType getCompressionType (StringRef s, StringRef option) {
1171+ static DebugCompressionType getCompressionType (Ctx &ctx, StringRef s,
1172+ StringRef option) {
11671173 DebugCompressionType type = StringSwitch<DebugCompressionType>(s)
11681174 .Case (" zlib" , DebugCompressionType::Zlib)
11691175 .Case (" zstd" , DebugCompressionType::Zstd)
@@ -1184,8 +1190,8 @@ static StringRef getAliasSpelling(opt::Arg *arg) {
11841190 return arg->getSpelling ();
11851191}
11861192
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) {
11891195 auto *arg = args.getLastArg (id);
11901196 if (!arg)
11911197 return {" " , " " };
@@ -1200,8 +1206,8 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
12001206
12011207// Parse options of the form "old;new[;extra]".
12021208static 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);
12051211 auto [newDir, extraDir] = second.split (' ;' );
12061212 return {oldDir, newDir, extraDir};
12071213}
@@ -1303,13 +1309,13 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
13031309 else if (arg->getOption ().matches (OPT_Bsymbolic))
13041310 ctx.arg .bsymbolic = BsymbolicKind::All;
13051311 }
1306- ctx.arg .callGraphProfileSort = getCGProfileSortKind (args);
1312+ ctx.arg .callGraphProfileSort = getCGProfileSortKind (ctx, args);
13071313 ctx.arg .checkSections =
13081314 args.hasFlag (OPT_check_sections, OPT_no_check_sections, true );
13091315 ctx.arg .chroot = args.getLastArgValue (OPT_chroot);
13101316 if (auto *arg = args.getLastArg (OPT_compress_debug_sections)) {
13111317 ctx.arg .compressDebugSections =
1312- getCompressionType (arg->getValue (), " --compress-debug-sections" );
1318+ getCompressionType (ctx, arg->getValue (), " --compress-debug-sections" );
13131319 }
13141320 ctx.arg .cref = args.hasArg (OPT_cref);
13151321 ctx.arg .optimizeBBJumps =
@@ -1406,7 +1412,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14061412 ctx.arg .nmagic = args.hasFlag (OPT_nmagic, OPT_no_nmagic, false );
14071413 ctx.arg .noinhibitExec = args.hasArg (OPT_noinhibit_exec);
14081414 ctx.arg .nostdlib = args.hasArg (OPT_nostdlib);
1409- ctx.arg .oFormatBinary = isOutputFormatBinary (args);
1415+ ctx.arg .oFormatBinary = isOutputFormatBinary (ctx, args);
14101416 ctx.arg .omagic = args.hasFlag (OPT_omagic, OPT_no_omagic, false );
14111417 ctx.arg .optRemarksFilename = args.getLastArgValue (OPT_opt_remarks_filename);
14121418 ctx.arg .optStatsFilename = args.getLastArgValue (OPT_plugin_opt_stats_file);
@@ -1426,7 +1432,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14261432 ctx.arg .optRemarksWithHotness = args.hasArg (OPT_opt_remarks_with_hotness);
14271433 ctx.arg .optRemarksFormat = args.getLastArgValue (OPT_opt_remarks_format);
14281434 ctx.arg .optimize = args::getInteger (args, OPT_O, 1 );
1429- ctx.arg .orphanHandling = getOrphanHandling (args);
1435+ ctx.arg .orphanHandling = getOrphanHandling (ctx, args);
14301436 ctx.arg .outputFile = args.getLastArgValue (OPT_o);
14311437 ctx.arg .packageMetadata = args.getLastArgValue (OPT_package_metadata);
14321438 ctx.arg .pie = args.hasFlag (OPT_pie, OPT_no_pie, false );
@@ -1460,19 +1466,19 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14601466 }
14611467
14621468 ctx.arg .searchPaths = args::getStrings (args, OPT_library_path);
1463- ctx.arg .sectionStartMap = getSectionStartMap (args);
1469+ ctx.arg .sectionStartMap = getSectionStartMap (ctx, args);
14641470 ctx.arg .shared = args.hasArg (OPT_shared);
14651471 ctx.arg .singleRoRx = !args.hasFlag (OPT_rosegment, OPT_no_rosegment, true );
14661472 ctx.arg .soName = args.getLastArgValue (OPT_soname);
1467- ctx.arg .sortSection = getSortSection (args);
1473+ ctx.arg .sortSection = getSortSection (ctx, args);
14681474 ctx.arg .splitStackAdjustSize =
14691475 args::getInteger (args, OPT_split_stack_adjust_size, 16384 );
14701476 ctx.arg .zSectionHeader =
14711477 getZFlag (args, " sectionheader" , " nosectionheader" , true );
14721478 ctx.arg .strip = getStrip (ctx, args); // needs zSectionHeader
14731479 ctx.arg .sysroot = args.getLastArgValue (OPT_sysroot);
14741480 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);
14761482 ctx.arg .thinLTOCacheDir = args.getLastArgValue (OPT_thinlto_cache_dir);
14771483 ctx.arg .thinLTOCachePolicy = CHECK (
14781484 parseCachePruningPolicy (args.getLastArgValue (OPT_thinlto_cache_policy)),
@@ -1485,10 +1491,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
14851491 args.hasArg (OPT_thinlto_index_only_eq);
14861492 ctx.arg .thinLTOIndexOnlyArg = args.getLastArgValue (OPT_thinlto_index_only_eq);
14871493 ctx.arg .thinLTOObjectSuffixReplace =
1488- getOldNewOptions (args, OPT_thinlto_object_suffix_replace_eq);
1494+ getOldNewOptions (ctx, args, OPT_thinlto_object_suffix_replace_eq);
14891495 std::tie (ctx.arg .thinLTOPrefixReplaceOld , ctx.arg .thinLTOPrefixReplaceNew ,
14901496 ctx.arg .thinLTOPrefixReplaceNativeObject ) =
1491- getOldNewOptionsExtra (args, OPT_thinlto_prefix_replace_eq);
1497+ getOldNewOptionsExtra (ctx, args, OPT_thinlto_prefix_replace_eq);
14921498 if (ctx.arg .thinLTOEmitIndexFiles && !ctx.arg .thinLTOIndexOnly ) {
14931499 if (args.hasArg (OPT_thinlto_object_suffix_replace_eq))
14941500 ErrAlways (ctx) << " --thinlto-object-suffix-replace is not supported with "
@@ -1525,7 +1531,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
15251531 ctx.arg .zCopyreloc = getZFlag (args, " copyreloc" , " nocopyreloc" , true );
15261532 ctx.arg .zForceBti = hasZOption (args, " force-bti" );
15271533 ctx.arg .zForceIbt = hasZOption (args, " force-ibt" );
1528- ctx.arg .zGcs = getZGcs (args);
1534+ ctx.arg .zGcs = getZGcs (ctx, args);
15291535 ctx.arg .zGlobal = hasZOption (args, " global" );
15301536 ctx.arg .zGnustack = getZGnuStack (args);
15311537 ctx.arg .zHazardplt = hasZOption (args, " hazardplt" );
@@ -1627,7 +1633,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16271633 continue ;
16281634 }
16291635 auto [typeStr, levelStr] = fields[1 ].split (' :' );
1630- auto type = getCompressionType (typeStr, arg->getSpelling ());
1636+ auto type = getCompressionType (ctx, typeStr, arg->getSpelling ());
16311637 unsigned level = 0 ;
16321638 if (fields[1 ].size () != typeStr.size () &&
16331639 !llvm::to_integer (levelStr, level)) {
@@ -1781,14 +1787,14 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
17811787 if (ctx.arg .nmagic || ctx.arg .omagic || ctx.arg .relocatable )
17821788 ctx.arg .zRelro = false ;
17831789
1784- std::tie (ctx.arg .buildId , ctx.arg .buildIdVector ) = getBuildId (args);
1790+ std::tie (ctx.arg .buildId , ctx.arg .buildIdVector ) = getBuildId (ctx, args);
17851791
17861792 if (getZFlag (args, " pack-relative-relocs" , " nopack-relative-relocs" , false )) {
17871793 ctx.arg .relrGlibc = true ;
17881794 ctx.arg .relrPackDynRelocs = true ;
17891795 } else {
17901796 std::tie (ctx.arg .androidPackDynRelocs , ctx.arg .relrPackDynRelocs ) =
1791- getPackDynRelocs (args);
1797+ getPackDynRelocs (ctx, args);
17921798 }
17931799
17941800 if (auto *arg = args.getLastArg (OPT_symbol_ordering_file)){
@@ -1949,7 +1955,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args) {
19491955 }
19501956}
19511957
1952- static bool isFormatBinary (StringRef s) {
1958+ static bool isFormatBinary (Ctx &ctx, StringRef s) {
19531959 if (s == " binary" )
19541960 return true ;
19551961 if (s == " elf" || s == " default" )
@@ -2006,7 +2012,7 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
20062012 ctx.arg .asNeeded = true ;
20072013 break ;
20082014 case OPT_format:
2009- ctx.arg .formatBinary = isFormatBinary (arg->getValue ());
2015+ ctx.arg .formatBinary = isFormatBinary (ctx, arg->getValue ());
20102016 break ;
20112017 case OPT_no_as_needed:
20122018 ctx.arg .asNeeded = false ;
0 commit comments