Skip to content

Commit d481e59

Browse files
committed
[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
1 parent 0145a26 commit d481e59

File tree

2 files changed

+92
-4
lines changed

2 files changed

+92
-4
lines changed

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,39 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
264264
UseG0 = G.getValue() == 0;
265265
}
266266

267-
//----------------------------------------------------------------------------
268-
//
269-
//----------------------------------------------------------------------------
270267
CmdArgs.push_back("-o");
271268
CmdArgs.push_back(Output.getFilename());
272269

270+
if (HTC.getTriple().isMusl()) {
271+
if (!Args.hasArg(options::OPT_shared, options::OPT_static))
272+
CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
273+
274+
if (!Args.hasArg(options::OPT_shared, options::OPT_nostartfiles,
275+
options::OPT_nostdlib))
276+
CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/crt1.o"));
277+
else if (Args.hasArg(options::OPT_shared) &&
278+
!Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
279+
CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/Scrt1.o"));
280+
281+
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + D.SysRoot + "/lib"));
282+
Args.AddAllArgs(CmdArgs,
283+
{options::OPT_T_Group, options::OPT_e, options::OPT_s,
284+
options::OPT_t, options::OPT_u_Group});
285+
AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
286+
287+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
288+
CmdArgs.push_back("-lclang_rt.builtins-hexagon");
289+
CmdArgs.push_back("-lc");
290+
}
291+
292+
return;
293+
}
294+
273295
//----------------------------------------------------------------------------
274296
// moslib
275297
//----------------------------------------------------------------------------
276298
std::vector<std::string> OsLibs;
277299
bool HasStandalone = false;
278-
279300
for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) {
280301
A->claim();
281302
OsLibs.emplace_back(A->getValue());

clang/test/Driver/hexagon-toolchain-elf.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,70 @@
597597
// RUN: %s 2>&1 \
598598
// RUN: | FileCheck -check-prefix=CHECK084 %s
599599
// CHECK084: "-fno-use-init-array"
600+
// -----------------------------------------------------------------------------
601+
// Passing --musl
602+
// -----------------------------------------------------------------------------
603+
// RUN: %clang -### -target hexagon-unknown-linux-musl \
604+
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
605+
// RUN: -mcpu=hexagonv60 \
606+
// RUN: -fuse-ld=lld \
607+
// RUN: --sysroot=/hexagon \
608+
// RUN: %s 2>&1 \
609+
// RUN: | FileCheck -check-prefix=CHECK085 %s
610+
// CHECK085-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
611+
// CHECK085: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
612+
// CHECK085: "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
613+
// CHECK085: "-lclang_rt.builtins-hexagon" "-lc"
614+
// -----------------------------------------------------------------------------
615+
// Passing --musl --shared
616+
// -----------------------------------------------------------------------------
617+
// RUN: %clang -### -target hexagon-unknown-linux-musl \
618+
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
619+
// RUN: -mcpu=hexagonv60 \
620+
// RUN: --sysroot=/hexagon -shared \
621+
// RUN: %s 2>&1 \
622+
// RUN: | FileCheck -check-prefix=CHECK086 %s
623+
// CHECK086-NOT: -dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1
624+
// CHECK086: "/hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o"
625+
// CHECK086: "-lclang_rt.builtins-hexagon" "-lc"
626+
// CHECK086-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
627+
// -----------------------------------------------------------------------------
628+
// Passing --musl -nostdlib
629+
// -----------------------------------------------------------------------------
630+
// RUN: %clang -### -target hexagon-unknown-linux-musl \
631+
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
632+
// RUN: -mcpu=hexagonv60 \
633+
// RUN: --sysroot=/hexagon -nostdlib \
634+
// RUN: %s 2>&1 \
635+
// RUN: | FileCheck -check-prefix=CHECK087 %s
636+
// CHECK087: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
637+
// CHECK087-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
638+
// CHECK087-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
639+
// CHECK087-NOT: -lclang_rt.builtins-hexagon
640+
// CHECK087-NOT: -lc
641+
// -----------------------------------------------------------------------------
642+
// Passing --musl -nostartfiles
643+
// -----------------------------------------------------------------------------
644+
// RUN: %clang -### -target hexagon-unknown-linux-musl \
645+
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
646+
// RUN: -mcpu=hexagonv60 \
647+
// RUN: --sysroot=/hexagon -nostartfiles \
648+
// RUN: %s 2>&1 \
649+
// RUN: | FileCheck -check-prefix=CHECK088 %s
650+
// CHECK088: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
651+
// CHECK088-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
652+
// CHECK088-NOT: /hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o
653+
// CHECK088: "-lclang_rt.builtins-hexagon" "-lc"
654+
// -----------------------------------------------------------------------------
655+
// Passing --musl -nodefaultlibs
656+
// -----------------------------------------------------------------------------
657+
// RUN: %clang -### -target hexagon-unknown-linux-musl \
658+
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
659+
// RUN: -mcpu=hexagonv60 \
660+
// RUN: --sysroot=/hexagon -nodefaultlibs \
661+
// RUN: %s 2>&1 \
662+
// RUN: | FileCheck -check-prefix=CHECK089 %s
663+
// CHECK089: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
664+
// CHECK089: "/hexagon{{/|\\\\}}lib{{/|\\\\}}crt1.o"
665+
// CHECK089-NOT: -lclang_rt.builtins-hexagon
666+
// CHECK089-NOT: -lc

0 commit comments

Comments
 (0)