Skip to content

Expand =/$SYSROOT for INPUT/GROUP script commands#950

Open
parth-07 wants to merge 1 commit intoqualcomm:mainfrom
parth-07:SysrootExpansion
Open

Expand =/$SYSROOT for INPUT/GROUP script commands#950
parth-07 wants to merge 1 commit intoqualcomm:mainfrom
parth-07:SysrootExpansion

Conversation

@parth-07
Copy link
Contributor

This commit improves the script parser to expand
the = and $SYSROOT prefix in INPUT/GROUP inputs.

Resolves #927

@parth-07 parth-07 force-pushed the SysrootExpansion branch 3 times, most recently from b5640a0 to c91146e Compare March 18, 2026 09:33
Copy link
Contributor

@quic-seaswara quic-seaswara left a comment

Choose a reason for hiding this comment

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

This is very cool feature!

InputStrTok =
ThisScriptFile.createFileToken(Name.str(), ThisScriptFile.asNeeded());
ThisScriptFile.createFileToken(ExpandedName, ThisScriptFile.asNeeded());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be done in resolvePath

For example

ld.bfd --sysroot=/tmp/xxx/ =main.o

I could not find this expansion of $SYSROOT for input files, may be I am not using the right version of ld.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ld.bfd --sysroot=/tmp/xxx/ =main.o

Thank you for adding this comment. I did not know GNU ld supported this. GNU ld docs does not mention anywhere that = and $SYSROOT are expanded for filenames specified directly in the link command. In my local experiments with GNU ld 2.38, I am able to reproduce SYSROOT expansion for both =main.o and $SYSROOT/main.o. I am updating the patch to include this functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I have updated the documentation sysroot.rst.in as well.

RUN: %link %linkopts -o %t.out2 --sysroot=%t.dir -T %p/Inputs/script_sysroot.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=SYSROOT
RUN: %link %linkopts -o %t.out3 --sysroot=%t.dir -T %p/Inputs/group_equals.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=GROUP
RUN: %not %link %linkopts -o %t.out4 -T %p/Inputs/script_equals.t %t.main.o 2>&1 | %filecheck %s --check-prefix=NOSYSROOT
#END_TEST
Copy link
Contributor

Choose a reason for hiding this comment

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

Need verbose output to show how the files are resolved.

Also please annotate map file to show what files are being expanded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the verbose output for the sysroot marker expansion. Can you please help with how we should annotate the sysroot marker expansion in the map-file? Should we add a new section in the map-file with all files that had sysroot markers and their corresponding expansions?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the map file that shows LOAD with

LOAD <user passed in file> #expanded file information

Copy link
Contributor

Choose a reason for hiding this comment

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

Can be a follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make the map-file change as a follow-up.

void ScriptParser::addFile(StringRef Name) {
StrToken *InputStrTok = nullptr;
if (Name.consume_front("-l"))
InputStrTok = ThisScriptFile.createNameSpecToken(Name.str(),
Copy link
Contributor

Choose a reason for hiding this comment

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

What does ld for namespec files ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not find any difference in interpretation for namespec files with explicit sysroot in GNU ld.

This commit improves the script parser to expand
the = and $SYSROOT prefix in INPUT/GROUP inputs.

Resolves qualcomm#927

Signed-off-by: Parth Arora <partaror@qti.qualcomm.com>
RUN: %link %linkopts -o %t.out2 --sysroot=%t.dir -T %p/Inputs/script_sysroot.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=SYSROOT
RUN: %link %linkopts -o %t.out3 --sysroot=%t.dir -T %p/Inputs/group_equals.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=GROUP
RUN: %not %link %linkopts -o %t.out4 -T %p/Inputs/script_equals.t %t.main.o 2>&1 | %filecheck %s --check-prefix=NOSYSROOT
#END_TEST
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the map file that shows LOAD with

LOAD <user passed in file> #expanded file information

RUN: %link %linkopts -o %t.out2 --sysroot=%t.dir -T %p/Inputs/script_sysroot.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=SYSROOT
RUN: %link %linkopts -o %t.out3 --sysroot=%t.dir -T %p/Inputs/group_equals.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=GROUP
RUN: %not %link %linkopts -o %t.out4 -T %p/Inputs/script_equals.t %t.main.o 2>&1 | %filecheck %s --check-prefix=NOSYSROOT
#END_TEST
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be a follow up

bool InputFileAction::activate(InputBuilder &PBuilder) {
const LinkerConfig &Config = PBuilder.getLinkerConfig();
std::string ExpandedName = Input::expandSysrootMarkers(
Name, Config.directories(), *Config.getDiagEngine());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please open an issue to support these with reproduce.

}
if (!llvm::sys::fs::exists(ResolvedPath->native())) {
const sys::fs::Path *P = PSearchDirs.find(FileName, Input::Script);
const sys::fs::Path *P =
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to have it const ?

else
return Name.str();

std::string ExpandedPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

Default ExpandedPath = suffix.str()

if (Name.starts_with("="))
Suffix = Name.substr(1);
else if (Name.starts_with("$SYSROOT"))
Suffix = Name.substr(strlen("$SYSROOT"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is $SYSROOT a reserved word ?

What about linker script file patterns ? Does that support = ?

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.

= and $SYSROOT in INPUT|GROUP command does not expand to SYSROOT

2 participants