[clang] d481e59 - [hexagon] Add default paths to support musl target

Sid Manning via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 06:43:37 PST 2020


Author: Sid Manning
Date: 2020-03-03T08:43:10-06:00
New Revision: d481e59863ac0eaca813a972f0dc79b763012d30

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

LOG: [hexagon] Add default paths to support musl target

Pickup the default crt and libs when the target is musl.
Resubmitting after updating the testcase.

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..1e2e7c84b006 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,39 @@ 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..93c9da2250f5 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,70 @@
 // 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:   -fuse-ld=lld \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK085:      "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK085:      "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
+// CHECK085:      "-lclang_rt.builtins-hexagon" "-lc"
+// -----------------------------------------------------------------------------
+// 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-NOT:    -dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1
+// CHECK086:        "/hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o"
+// CHECK086:        "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:    /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// -----------------------------------------------------------------------------
+// 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:       "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK087-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK087-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK087-NOT:   -lclang_rt.builtins-hexagon
+// CHECK087-NOT:   -lc
+// -----------------------------------------------------------------------------
+// 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:       "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK088-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
+// CHECK088-NOT:   /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
+// CHECK088:       "-lclang_rt.builtins-hexagon" "-lc"
+// -----------------------------------------------------------------------------
+// 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:       "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
+// CHECK089:       "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
+// CHECK089-NOT:   -lclang_rt.builtins-hexagon
+// CHECK089-NOT:   -lc


        


More information about the cfe-commits mailing list