https://github.com/androm3da created https://github.com/llvm/llvm-project/pull/67515
None >From 41a8826e647917042e8e5eaf0922f60e16d98839 Mon Sep 17 00:00:00 2001 From: Brian Cain <bc...@quicinc.com> Date: Tue, 26 Sep 2023 19:57:47 -0700 Subject: [PATCH] [clang][hexagon] Add support for -nolibc --- clang/lib/Driver/ToolChains/Hexagon.cpp | 6 +++-- clang/test/Driver/hexagon-toolchain-elf.c | 26 ++++++++++++++++++++- clang/test/Driver/hexagon-toolchain-linux.c | 12 ++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index e7dca1053dc8d8a..d81e022708932f7 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -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)) @@ -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"); diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c index 039b87347436d51..48b9aa2c22bffaa 100644 --- a/clang/test/Driver/hexagon-toolchain-elf.c +++ b/clang/test/Driver/hexagon-toolchain-elf.c @@ -330,7 +330,7 @@ // CHECK335: "{{.*}}/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 \ @@ -401,6 +401,30 @@ // 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 \ +// RUN: -mcpu=hexagonv60 \ +// RUN: -nolibc \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-NOLIBC %s +// CHECK-NOLIBC: "-cc1" +// CHECK-NOLIBC: {{hexagon-link|ld}} +// CHECK-NOLIBC: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/crt0_standalone.o" +// CHECK-NOLIBC: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/crt0.o" +// CHECK-NOLIBC: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/init.o" +// CHECK-NOLIBC: "-L{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60" +// CHECK-NOLIBC: "-L{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib" +// CHECK-NOLIBC: "{{[^"]+}}.o" +// CHECK-NOLIBC: "-lstdc++" +// CHECK-NOLIBC: "-lm" +// CHECK-NOLIBC: "--start-group" +// CHECK-NOLIBC: "-lstandalone" +// CHECK-NOLIBC-NOT: "-lc" +// CHECK-NOLIBC: "-lgcc" +// CHECK-NOLIBC: "--end-group" +// CHECK-NOLIBC: "{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/fini.o" + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // -moslib // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/clang/test/Driver/hexagon-toolchain-linux.c b/clang/test/Driver/hexagon-toolchain-linux.c index 423306affdce3ac..90a92900020fcda 100644 --- a/clang/test/Driver/hexagon-toolchain-linux.c +++ b/clang/test/Driver/hexagon-toolchain-linux.c @@ -68,6 +68,18 @@ // 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 \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -nolibc \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-NOLIBC %s +// CHECK-NOLIBC: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1" +// CHECK-NOLIBC: "{{.*}}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 \ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits