-
Notifications
You must be signed in to change notification settings - Fork 55
Expand =/$SYSROOT for INPUT/GROUP script commands #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -739,14 +739,31 @@ void ScriptParser::readAsNeeded() { | |
| ThisScriptFile.setAsNeeded(false); | ||
| } | ||
|
|
||
| std::string ScriptParser::expandSysrootMarkers(StringRef Name) const { | ||
| StringRef Suffix; | ||
| if (Name.starts_with("=")) | ||
| Suffix = Name.substr(1); | ||
| else if (Name.starts_with("$SYSROOT")) | ||
| Suffix = Name.substr(8); // strlen("$SYSROOT") == 8 | ||
| else | ||
| return Name.str(); | ||
|
|
||
| auto &SearchDirs = ThisConfig.directories(); | ||
| if (SearchDirs.hasSysRoot()) | ||
| return (SearchDirs.sysroot().native() + Suffix).str(); | ||
| return Suffix.str(); | ||
| } | ||
|
|
||
| void ScriptParser::addFile(StringRef Name) { | ||
| StrToken *InputStrTok = nullptr; | ||
| if (Name.consume_front("-l")) | ||
| InputStrTok = ThisScriptFile.createNameSpecToken(Name.str(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does ld for namespec files ? |
||
| ThisScriptFile.asNeeded()); | ||
| else | ||
| else { | ||
| std::string ExpandedName = expandSysrootMarkers(Name); | ||
| InputStrTok = | ||
| ThisScriptFile.createFileToken(Name.str(), ThisScriptFile.asNeeded()); | ||
| ThisScriptFile.createFileToken(ExpandedName, ThisScriptFile.asNeeded()); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ThisScriptFile.getCurrentStringList()->pushBack(InputStrTok); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| int foo() { return 1; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| GROUP(=/lib64/lib1.so) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add GROUP($SYSROOT) as well? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| int main() { return 0; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| INPUT(=/lib64/lib1.so) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| INPUT($SYSROOT/lib64/lib1.so) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #---SysrootExpansion.test---------------- Linker Script ----------------# | ||
| #BEGIN_COMMENT | ||
| # Validate sysroot expansion for "=" and "$SYSROOT" markers in INPUT/GROUP | ||
| # script commands. | ||
| # When a path starts with "=" or "$SYSROOT", it should be expanded to the | ||
| # sysroot path regardless of where the linker script is located. | ||
| #END_COMMENT | ||
| #START_TEST | ||
|
|
||
| RUN: rm -rf %t.dir && mkdir -p %t.dir/lib64 | ||
| RUN: %clang %clangopts -o %t.1.o %p/Inputs/1.c -c -fPIC | ||
| RUN: %clang %clangopts -o %t.main.o %p/Inputs/main.c -c | ||
| RUN: %link %linkopts -o %t.dir/lib64/lib1.so -shared %t.1.o | ||
| RUN: %link %linkopts -o %t.out1 --sysroot=%t.dir -T %p/Inputs/script_equals.t %t.main.o --verbose 2>&1 | %filecheck %s --check-prefix=EQUALS | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| EQUALS: Verbose: Mapping input file '{{.*}}dir/lib64/lib1.so' into memory | ||
| SYSROOT: Verbose: Mapping input file '{{.*}}dir/lib64/lib1.so' into memory | ||
| GROUP: Verbose: Mapping input file '{{.*}}dir/lib64/lib1.so' into memory | ||
| NOSYSROOT: Fatal: cannot read file /lib64/lib1.so | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name.substr(strlen("$SYSROOT")) or create a function to get the suffix.