Commit 63776766 authored by Sid Manning's avatar Sid Manning
Browse files

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
parent e392dcd5
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -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());
+66 −0
Original line number Diff line number Diff line
@@ -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"