@@ -93,6 +93,7 @@ void elf::errorOrWarn(const Twine &msg) {
9393
9494void Ctx::reset () {
9595 driver = LinkerDriver ();
96+ script = nullptr ;
9697
9798 bufferStart = nullptr ;
9899 mainPart = nullptr ;
@@ -160,8 +161,9 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
160161 " --error-limit=0 to see all errors)" ;
161162
162163 config = ConfigWrapper ();
163- script = ScriptWrapper ();
164164
165+ LinkerScript script;
166+ elf::ctx.script = &script;
165167 elf::ctx.symAux .emplace_back ();
166168
167169 partitions.clear ();
@@ -463,7 +465,7 @@ static void checkOptions() {
463465 if (config->emachine != EM_AARCH64)
464466 error (" --execute-only is only supported on AArch64 targets" );
465467
466- if (config->singleRoRx && !script->hasSectionsCommand )
468+ if (config->singleRoRx && !ctx. script ->hasSectionsCommand )
467469 error (" --execute-only and --no-rosegment cannot be used together" );
468470 }
469471
@@ -2456,10 +2458,10 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
24562458 // Forbid partitions from being used on incompatible targets, and forbid them
24572459 // from being used together with various linker features that assume a single
24582460 // set of output sections.
2459- if (script->hasSectionsCommand )
2461+ if (ctx. script ->hasSectionsCommand )
24602462 error (toString (s->file ) +
24612463 " : partitions cannot be used with the SECTIONS command" );
2462- if (script->hasPhdrsCommands ())
2464+ if (ctx. script ->hasPhdrsCommands ())
24632465 error (toString (s->file ) +
24642466 " : partitions cannot be used with the PHDRS command" );
24652467 if (!config->sectionStartMap .empty ())
@@ -2873,7 +2875,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
28732875 // After potential archive member extraction involving ENTRY and
28742876 // -u/--undefined-glob, check whether PROVIDE symbols should be defined (the
28752877 // RHS may refer to definitions in just extracted object files).
2876- script->addScriptReferencedSymbolsToSymTable ();
2878+ ctx. script ->addScriptReferencedSymbolsToSymTable ();
28772879
28782880 // Prevent LTO from removing any definition referenced by -u.
28792881 for (StringRef name : config->undefined )
@@ -2939,7 +2941,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29392941 // We want to declare linker script's symbols early,
29402942 // so that we can version them.
29412943 // They also might be exported if referenced by DSOs.
2942- script->declareSymbols ();
2944+ ctx. script ->declareSymbols ();
29432945
29442946 // Handle --exclude-libs. This is before scanVersionScript() due to a
29452947 // workaround for Android ndk: for a defined versioned symbol in an archive
@@ -3158,13 +3160,13 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31583160 llvm::TimeTraceScope timeScope (" Assign sections" );
31593161
31603162 // Create output sections described by SECTIONS commands.
3161- script->processSectionCommands ();
3163+ ctx. script ->processSectionCommands ();
31623164
31633165 // Linker scripts control how input sections are assigned to output
31643166 // sections. Input sections that were not handled by scripts are called
31653167 // "orphans", and they are assigned to output sections by the default rule.
31663168 // Process that.
3167- script->addOrphanSections ();
3169+ ctx. script ->addOrphanSections ();
31683170 }
31693171
31703172 {
@@ -3174,9 +3176,9 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31743176 // merging MergeInputSections into a single MergeSyntheticSection. From this
31753177 // point onwards InputSectionDescription::sections should be used instead of
31763178 // sectionBases.
3177- for (SectionCommand *cmd : script->sectionCommands )
3179+ for (SectionCommand *cmd : ctx. script ->sectionCommands )
31783180 if (auto *osd = dyn_cast<OutputDesc>(cmd))
3179- osd->osec .finalizeInputSections (&script. s );
3181+ osd->osec .finalizeInputSections (ctx. script );
31803182 }
31813183
31823184 // Two input sections with different output sections should not be folded.
0 commit comments