-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[Driver] Also respect SysRoot for the system library paths on DragonFly #66056
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
clang
Clang issues not falling into any other category
clang:driver
'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
labels
Sep 12, 2023
@llvm/pr-subscribers-clang-driver ChangesNoneFull diff: https://github.com/llvm/llvm-project/pull/66056.diff 9 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp index 46f98f9efca2330..82c975990a32511 100644 --- a/clang/lib/Driver/ToolChains/DragonFly.cpp +++ b/clang/lib/Driver/ToolChains/DragonFly.cpp @@ -123,7 +123,9 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, options::OPT_r)) { - CmdArgs.push_back("-L/usr/lib/gcc80"); + SmallString<128> Dir(D.SysRoot); + llvm::sys::path::append(Dir, "/usr/lib/gcc80"); + CmdArgs.push_back(Args.MakeArgString("-L" + Dir)); if (!Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-rpath"); @@ -192,8 +194,8 @@ DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, getProgramPaths().push_back(getDriver().Dir); getFilePaths().push_back(getDriver().Dir + "/../lib"); - getFilePaths().push_back("/usr/lib"); - getFilePaths().push_back("/usr/lib/gcc80"); + getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib")); + getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/gcc80")); } void DragonFly::AddClangSystemIncludeArgs( diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c index 477dbfe6abf43fa..a826addd7ef8015 100644 --- a/clang/test/Driver/dragonfly.c +++ b/clang/test/Driver/dragonfly.c @@ -4,6 +4,27 @@ // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly" // CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" "{{.*}}crtn.o" +// Check x86_64-unknown-dragonfly, X86_64 +// RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_dragonfly_tree \ +// RUN: | FileCheck --check-prefix=CHECK-LD-X86_64 %s +// CHECK-LD-X86_64: "-cc1" "-triple" "x86_64-unknown-dragonfly" +// CHECK-LD-X86_64-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-LD-X86_64: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/crt1.o" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/crti.o" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/gcc80/crtbegin.o" +// CHECK-LD-X86_64-SAME: "-L[[SYSROOT]]/usr/lib/gcc80" +// CHECK-LD-X86_64-SAME: "-rpath" "/usr/lib/gcc80" +// CHECK-LD-X86_64-SAME: "-lc" +// CHECK-LD-X86_64-SAME: "-lgcc" +// CHECK-LD-X86_64-SAME: "--as-needed" +// CHECK-LD-X86_64-SAME: "-lgcc_pic" +// CHECK-LD-X86_64-SAME: "--no-as-needed" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/gcc80/crtend.o" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/crtn.o" + // -r suppresses -dynamic-linker, default -l and crt*.o like -nostdlib. // RUN: %clang -### %s --target=x86_64-pc-dragonfly -r \ // RUN: 2>&1 | FileCheck %s --check-prefix=RELOCATABLE |
@llvm/pr-subscribers-clang ChangesNoneFull diff: https://github.com/llvm/llvm-project/pull/66056.diff 9 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp index 46f98f9efca2330..82c975990a32511 100644 --- a/clang/lib/Driver/ToolChains/DragonFly.cpp +++ b/clang/lib/Driver/ToolChains/DragonFly.cpp @@ -123,7 +123,9 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, options::OPT_r)) { - CmdArgs.push_back("-L/usr/lib/gcc80"); + SmallString<128> Dir(D.SysRoot); + llvm::sys::path::append(Dir, "/usr/lib/gcc80"); + CmdArgs.push_back(Args.MakeArgString("-L" + Dir)); if (!Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-rpath"); @@ -192,8 +194,8 @@ DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple, getProgramPaths().push_back(getDriver().Dir); getFilePaths().push_back(getDriver().Dir + "/../lib"); - getFilePaths().push_back("/usr/lib"); - getFilePaths().push_back("/usr/lib/gcc80"); + getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib")); + getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib/gcc80")); } void DragonFly::AddClangSystemIncludeArgs( diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o b/clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o new file mode 100644 index 000000000000000..e69de29bb2d1d64 diff --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c index 477dbfe6abf43fa..a826addd7ef8015 100644 --- a/clang/test/Driver/dragonfly.c +++ b/clang/test/Driver/dragonfly.c @@ -4,6 +4,27 @@ // CHECK: "-cc1" "-triple" "x86_64-pc-dragonfly" // CHECK: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/usr/libexec/ld-elf.so.{{.*}}" "--hash-style=gnu" "--enable-new-dtags" "-o" "a.out" "{{.*}}crt1.o" "{{.*}}crti.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-L{{.*}}gcc{{.*}}" "-rpath" "{{.*}}gcc{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" "{{.*}}crtn.o" +// Check x86_64-unknown-dragonfly, X86_64 +// RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_dragonfly_tree \ +// RUN: | FileCheck --check-prefix=CHECK-LD-X86_64 %s +// CHECK-LD-X86_64: "-cc1" "-triple" "x86_64-unknown-dragonfly" +// CHECK-LD-X86_64-SAME: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-LD-X86_64: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/crt1.o" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/crti.o" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/gcc80/crtbegin.o" +// CHECK-LD-X86_64-SAME: "-L[[SYSROOT]]/usr/lib/gcc80" +// CHECK-LD-X86_64-SAME: "-rpath" "/usr/lib/gcc80" +// CHECK-LD-X86_64-SAME: "-lc" +// CHECK-LD-X86_64-SAME: "-lgcc" +// CHECK-LD-X86_64-SAME: "--as-needed" +// CHECK-LD-X86_64-SAME: "-lgcc_pic" +// CHECK-LD-X86_64-SAME: "--no-as-needed" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/gcc80/crtend.o" +// CHECK-LD-X86_64-SAME: "[[SYSROOT]]/usr/lib/crtn.o" + // -r suppresses -dynamic-linker, default -l and crt*.o like -nostdlib. // RUN: %clang -### %s --target=x86_64-pc-dragonfly -r \ // RUN: 2>&1 | FileCheck %s --check-prefix=RELOCATABLE |
MaskRay
reviewed
Sep 12, 2023
brad0
force-pushed
the
clang_driver_dragonfly_sysroot
branch
from
September 12, 2023 19:39
df6d22f
to
e81fa98
Compare
MaskRay
approved these changes
Sep 12, 2023
brad0
force-pushed
the
clang_driver_dragonfly_sysroot
branch
from
September 15, 2023 00:53
e81fa98
to
91ee019
Compare
Fixed the test so it also passes on Windows. |
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:driver
'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.