Skip to content

Commit

Permalink
[clang][hexagon] Add support for -nolibc (#67515)
Browse files Browse the repository at this point in the history
  • Loading branch information
androm3da committed Sep 28, 2023
1 parent 183a1b1 commit a1b02c9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
6 changes: 4 additions & 2 deletions clang/lib/Driver/ToolChains/Hexagon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
linkXRayRuntimeDeps(HTC, Args, CmdArgs);

CmdArgs.push_back("-lclang_rt.builtins-hexagon");
CmdArgs.push_back("-lc");
if (!Args.hasArg(options::OPT_nolibc))
CmdArgs.push_back("-lc");
}
if (D.CCCIsCXX()) {
if (HTC.ShouldLinkCXXStdlib(Args))
Expand Down Expand Up @@ -470,7 +471,8 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
if (!IsShared) {
for (StringRef Lib : OsLibs)
CmdArgs.push_back(Args.MakeArgString("-l" + Lib));
CmdArgs.push_back("-lc");
if (!Args.hasArg(options::OPT_nolibc))
CmdArgs.push_back("-lc");
}
CmdArgs.push_back("-lgcc");

Expand Down
23 changes: 22 additions & 1 deletion clang/test/Driver/hexagon-toolchain-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
// CHECK335-SAME: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/G0/fini.o"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// -nostdlib, -nostartfiles, -nodefaultlibs
// -nostdlib, -nostartfiles, -nodefaultlibs, -nolibc
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// RUN: %clangxx -### --target=hexagon-unknown-elf \
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
Expand Down Expand Up @@ -337,6 +337,27 @@
// CHECK338-NOT: "--end-group"
// CHECK338: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/fini.o"

// RUN: %clangxx -### --target=hexagon-unknown-elf \
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin -mcpu=hexagonv60 \
// RUN: -fuse-ld=lld -nolibc %s 2>&1 | FileCheck -check-prefix=CHECK-NOLIBC %s
// CHECK-NOLIBC: "-cc1"
// CHECK-NOLIBC: ld.lld
// CHECK-NOLIBC-SAME: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/crt0_standalone.o"
// CHECK-NOLIBC-SAME: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/crt0.o"
// CHECK-NOLIBC-SAME: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/init.o"
// CHECK-NOLIBC-SAME: "-L{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60"
// CHECK-NOLIBC-SAME: "-L{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib"
// CHECK-NOLIBC-SAME: "{{[^"]+}}.o"
// CHECK-NOLIBC-SAME: "-lstdc++"
// CHECK-NOLIBC-SAME: "-lm"
// CHECK-NOLIBC-SAME: "--start-group"
// CHECK-NOLIBC-SAME: "-lstandalone"
// CHECK-NOLIBC-NOT: "-lc"
// CHECK-NOLIBC-SAME: "-lgcc"
// CHECK-NOLIBC-SAME: "--end-group"
// CHECK-NOLIBC-SAME: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/fini.o"


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// -moslib
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/hexagon-toolchain-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
// CHECK004-NOT: "-lclang_rt.builtins-hexagon"
// CHECK004-NOT: "-lc"
// -----------------------------------------------------------------------------
// Passing --musl -nolibc
// -----------------------------------------------------------------------------
// RUN: %clang -### --target=hexagon-unknown-linux-musl \
// RUN: -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
// RUN: -mcpu=hexagonv60 --sysroot=%S/Inputs/basic_linux_libcxx_tree \
// RUN: -nolibc %s 2>&1 | FileCheck -check-prefix=CHECK-NOLIBC %s
// CHECK-NOLIBC: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
// CHECK-NOLIBC-SAME: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o"
// CHECK-NOLIBC-NOT: "-lc"
// -----------------------------------------------------------------------------
// Not Passing -fno-use-init-array when musl is selected
// -----------------------------------------------------------------------------
// RUN: %clang -### --target=hexagon-unknown-linux-musl \
Expand Down

0 comments on commit a1b02c9

Please sign in to comment.