Skip to content

[Reproduce] Support linker scripts resolved through -L - #1763

Open
Rachit Mehta (rachitmeht) wants to merge 1 commit into
qualcomm:mainfrom
rachitmeht:fix/reproduce-linker-script-search-path
Open

[Reproduce] Support linker scripts resolved through -L#1763
Rachit Mehta (rachitmeht) wants to merge 1 commit into
qualcomm:mainfrom
rachitmeht:fix/reproduce-linker-script-search-path

Conversation

@rachitmeht

Copy link
Copy Markdown

Capture linker scripts during early activation and rewrite -T paths to their mapped paths in reproduce response files. Add a regression test covering linker scripts found through a -L search directory.

Resolves #1454

Capture linker scripts during early activation and rewrite -T paths to their mapped paths in reproduce response files. Add a regression test covering linker scripts found through a -L search directory.

Resolves qualcomm#1454

Signed-off-by: Rachit Mehta <rachmeht@qti.qualcomm.com>
@rachitmeht
Rachit Mehta (rachitmeht) force-pushed the fix/reproduce-linker-script-search-path branch from 3c0de8a to fe25f35 Compare August 25, 2026 10:25

// Capture scripts during early activation so the response file can rewrite
// -T paths that were resolved through a -L search directory.
addInputFileToTar(input, eld::MappingFile::LinkerScript);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being called for both early activation and late activation, right?

Why can't the response file rewrite -T paths that were resolved through -L subdirectory if we capture the information later in full activation?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, addInputFileToTar() may be called during both early and full activation. For a normal successful link, full activation usually happens and may capture the script later. The reason for keeping the early capture is to cover the broader --reproduce-on-fail case: any earlier input error, script error or interruption can prevent full activation from being reached.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for keeping the early capture is to cover the broader --reproduce-on-fail case: any earlier input error, script error or interruption can prevent full activation from being reached.

Then can you fix the comments above addInputFileToTar here? The comments suggests that early activation is somehow required when script is found in -L subdirectory.

return false;
os << arg->getSpelling() << ' ' << *path << ' ';
bool rewritten = false;
for (size_t i = lastScriptId + 1; i < actions.size(); ++i) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to determine the script's InputFile positionally? Why does outputTar->rewritePath(...) does not work here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputTar->rewritePath("script.t") does not find the mapping created for
"/work/A/lib/script.t" and falls back to "script.t"

So, The ScriptAction lookup is needed to obtain the mapped resolved path.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positionally determining InputFile will allow us to have args with same name but may resolve to different files. like
-L dir1 -T script.t -L dir2 -T script.t

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputTar->rewritePath("script.t") does not find the mapping created for
"/work/A/lib/script.t" and falls back to "script.t"

Yes, that is the core issue that needs to be fixed.

What is the benefit of determining the InputFile positionally and making the code and the flow more complex as opposed to fixing outputTar->rewritePath(...) to function correctly here?

Positionally determining InputFile will allow us to have args with same name but may resolve to different files. like -L dir1 -T script.t -L dir2 -T script.t

Can you verify whether the 2 script.t here would resolve to different scripts if dir1 and dir2 both contains script.t?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified, the 2 script.t will resolve to the first -L dir only. I was influenced by how we handle namespecs here.
I agree this approach doesn't fix outputTar->rewritePath(...).
But if we fix that we must handle LinkerScript seperately in that function to give correct path. The current fix effectively does that.
Will that be better design?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we fix that we must handle LinkerScript seperately in that function to give correct path. The current fix effectively does that.

Why would we need to handle LinkerScript separately in that function? Can you think of a solution that fixes this problem in a more general way?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, The issue will be for every script ( version script & LinkerScript ) which excecutes ScriptAction::Activate()
Because it changes the file name by

    Path = Res->native();
  }
  setFileName(Path);

So, the MappedPath contains the wrong Name for scripts came through -L.

But processReproduceOption() calls rewritePath() with the original argument spelling from the command line. Since rewritePath() only receives a string and does an exact lookup in
InputMap, it cannot know that script.t should correspond to /path/from/-L/script.t.

So we can either:
have conditional handling of these scripts before calling rewritePath(), or
we can have a different Reproduce Specific map which will have the original file name. (we only need to store original map in ScriptAction:: Activate())

RUN: %link --no-threads -L %t.lib -T script.t %t.main.o -o %t.out --reproduce %t.tar --dump-response-file %t.response
RUN: %filecheck %s < %t.response
RUN: %mkdir %t.reproduce
RUN: %tar %gnutaropts -xf %t.tar -C %t.reproduce --strip-components=1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tar .... -C is not compatible with Windows. you can cd into %t.reproduce first that way you don't need -C

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reproduce does not work when linker script is found within a -L directory

3 participants