[clang] [Driver] Also respect SysRoot for the system library paths on DragonFly (PR #66056)
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 01:45:42 PDT 2023
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/66056:
None
>From df6d22fb217837a0b0d00b8905b077347fca6143 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Tue, 12 Sep 2023 04:43:49 -0400
Subject: [PATCH] [Driver] Also respect SysRoot for the system library paths on
DragonFly
---
clang/lib/Driver/ToolChains/DragonFly.cpp | 8 ++++---
.../basic_dragonfly_tree/usr/lib/crt1.o | 0
.../basic_dragonfly_tree/usr/lib/crti.o | 0
.../basic_dragonfly_tree/usr/lib/crtn.o | 0
.../usr/lib/gcc80/crtbegin.o | 0
.../usr/lib/gcc80/crtbeginS.o | 0
.../usr/lib/gcc80/crtend.o | 0
.../usr/lib/gcc80/crtendS.o | 0
clang/test/Driver/dragonfly.c | 21 +++++++++++++++++++
9 files changed, 26 insertions(+), 3 deletions(-)
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crt1.o
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crti.o
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/crtn.o
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbegin.o
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtbeginS.o
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtend.o
create mode 100644 clang/test/Driver/Inputs/basic_dragonfly_tree/usr/lib/gcc80/crtendS.o
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
More information about the cfe-commits
mailing list