Skip to content

Commit

Permalink
[Driver] Also respect SysRoot for the system library paths on DragonF…
Browse files Browse the repository at this point in the history
…ly (#66056)
  • Loading branch information
brad0 committed Sep 15, 2023
1 parent e9f044a commit 1e40dfc
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clang/lib/Driver/ToolChains/DragonFly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions clang/test/Driver/dragonfly.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
// 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" "-rpath" "/usr/lib/gcc80" "-lc" "-lgcc" "--as-needed" "-lgcc_pic" "--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
Expand Down

0 comments on commit 1e40dfc

Please sign in to comment.