[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

Brad Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 15 19:28:40 PDT 2023


https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/69095

>From 1840ed82beb90edcdf8b4eff3de93d595fbc041d Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sun, 15 Oct 2023 04:00:56 -0400
Subject: [PATCH] [Driver][DragonFly] Fixes for linker path and command-line
 option handling

Add in some other linker command line options that the other BSD's
handle and make use of AddFilePathLibArgs().
---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 12 ++++++------
 clang/test/Driver/dragonfly.c             | 10 ++++++++--
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp
index a58983aba5a12f2..a4163a5f595372e 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -56,7 +56,9 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
                                      const InputInfoList &Inputs,
                                      const ArgList &Args,
                                      const char *LinkingOutput) const {
-  const Driver &D = getToolChain().getDriver();
+  const toolchains::DragonFly &ToolChain =
+      static_cast<const toolchains::DragonFly &>(getToolChain());
+  const Driver &D = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
   if (!D.SysRoot.empty())
@@ -115,16 +117,14 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
           Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
-  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
+                            options::OPT_s, options::OPT_t, options::OPT_r});
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
                    options::OPT_r)) {
-    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");
       CmdArgs.push_back("/usr/lib/gcc80");
diff --git a/clang/test/Driver/dragonfly.c b/clang/test/Driver/dragonfly.c
index 8ba13c41d632c20..11d730f55bd9d69 100644
--- a/clang/test/Driver/dragonfly.c
+++ b/clang/test/Driver/dragonfly.c
@@ -2,7 +2,7 @@
 // RUN: FileCheck -input-file %t.log %s
 
 // 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: 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" "-L{{.*}}/../lib" "-L/usr/lib" "-L/usr/lib/gcc80" "{{.*}}.o" "-rpath" "{{.*}}gcc80{{.*}}" "-lc" "-lgcc" "{{.*}}crtend.o" "{{.*}}crtn.o"
 
 // Check x86_64-unknown-dragonfly, X86_64
 // RUN: %clang -### %s 2>&1 --target=x86_64-unknown-dragonfly \
@@ -15,7 +15,8 @@
 // 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: "-L[[SYSROOT]]{{/|\\\\}}usr{{/|\\\\}}lib" "-L[[SYSROOT]]{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}gcc80"
+// CHECK-LD-X86_64-SAME: "-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"
 
@@ -26,3 +27,8 @@
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: {{.*}}crt{{[^./]+}}.o
+
+// Check that the new linker flags are passed to DragonFly
+// RUN: %clang --target=x86_64-unknown-dragonfly -s -t -### %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-FLAGS %s
+// CHECK-LD-FLAGS: ld{{.*}}" "{{.*}}" "-s" "-t"



More information about the cfe-commits mailing list