[clang] 6377676 - Add default paths to support musl target

Sid Manning via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 11:40:17 PST 2020


Author: Sid Manning
Date: 2020-03-02T13:39:42-06:00
New Revision: 637767665141ae48c7a0558903bb29e03bf5ad6f

URL: https://github.com/llvm/llvm-project/commit/637767665141ae48c7a0558903bb29e03bf5ad6f
DIFF: https://github.com/llvm/llvm-project/commit/637767665141ae48c7a0558903bb29e03bf5ad6f.diff

LOG: Add default paths to support musl target

Pickup the default crt and libs when the target is musl.

Differential Revision: https://reviews.llvm.org/D75139

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Hexagon.cpp
    clang/test/Driver/hexagon-toolchain-elf.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 88523cd4bb1c..c069eefde9af 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,41 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
     UseG0 = G.getValue() == 0;
   }
 
-  //----------------------------------------------------------------------------
-  //
-  //----------------------------------------------------------------------------
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+    if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+      CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
+
+    if (!Args.hasArg(options::OPT_shared,
+                     options::OPT_nostartfiles,
+                     options::OPT_nostdlib))
+      CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/crt1.o"));
+    else if (Args.hasArg(options::OPT_shared) &&
+             !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
+      CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/Scrt1.o"));
+
+    CmdArgs.push_back(
+        Args.MakeArgString(StringRef("-L") + D.SysRoot + "/lib"));
+    Args.AddAllArgs(CmdArgs,
+                    {options::OPT_T_Group, options::OPT_e, options::OPT_s,
+                     options::OPT_t, options::OPT_u_Group});
+    AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
+
+    if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+      CmdArgs.push_back("-lclang_rt.builtins-hexagon");
+      CmdArgs.push_back("-lc");
+    }
+
+    return;
+  }
+
   //----------------------------------------------------------------------------
   // moslib
   //----------------------------------------------------------------------------
   std::vector<std::string> OsLibs;
   bool HasStandalone = false;
-
   for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) {
     A->claim();
     OsLibs.emplace_back(A->getValue());

diff  --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c
index 0a6c86424955..24daac05d612 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,69 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:          "-fno-use-init-array"
+// -----------------------------------------------------------------------------
+// Passing --musl
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK085:      "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
+// CHECK085:      "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK085:      "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// -----------------------------------------------------------------------------
+// Passing --musl --shared
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086:        "/hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o"
+// CHECK086:        "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:    /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK086-NOT:    -dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1
+// -----------------------------------------------------------------------------
+// Passing --musl -nostdlib
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK087 %s
+// CHECK087-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK087-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK087-NOT:   -lclang_rt.builtins-hexagon
+// CHECK087-NOT:   -lc
+// CHECK087:       "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// -----------------------------------------------------------------------------
+// Passing --musl -nostartfiles
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK088 %s
+// CHECK088-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK088-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK088:       "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK088:       "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// -----------------------------------------------------------------------------
+// Passing --musl -nodefaultlibs
+// -----------------------------------------------------------------------------
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK089 %s
+// CHECK089:       "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
+// CHECK089-NOT:   -lclang_rt.builtins-hexagon
+// CHECK089-NOT:   -lc
+// CHECK089:       "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"


        


More information about the cfe-commits mailing list