diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -264,18 +264,41 @@ 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 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 --- a/clang/test/Driver/hexagon-toolchain-elf.c +++ b/clang/test/Driver/hexagon-toolchain-elf.c @@ -588,3 +588,69 @@ // RUN: | FileCheck -check-prefix=CHECK083 %s // CHECK083: "-isysroot" "/hexagon" // CHECK083: "-internal-externc-isystem" "/hexagon{{/|\\\\}}include" +// ----------------------------------------------------------------------------- +// 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=CHECK084 %s +// CHECK084-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o +// CHECK084: "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o" +// CHECK084: "-lclang_rt.builtins-hexagon" "-lc" +// CHECK084: "-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=CHECK085 %s +// CHECK085: "/hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o" +// CHECK085: "-lclang_rt.builtins-hexagon" "-lc" +// CHECK085-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o +// CHECK085-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=CHECK086 %s +// CHECK086-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o +// CHECK086-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o +// CHECK086-NOT: -lclang_rt.builtins-hexagon +// CHECK086-NOT: -lc +// CHECK086: "-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=CHECK087 %s +// CHECK087-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o +// CHECK087-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o +// CHECK087: "-lclang_rt.builtins-hexagon" "-lc" +// CHECK087: "-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=CHECK088 %s +// CHECK088: "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o" +// CHECK088-NOT: -lclang_rt.builtins-hexagon +// CHECK088-NOT: -lc +// CHECK088: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"