[clang] [clang][Driver][BareMetal] Add profile library to the command line when needed (PR #191847)
Volodymyr Turanskyy via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 27 07:08:46 PDT 2026
https://github.com/voltur01 updated https://github.com/llvm/llvm-project/pull/191847
>From 4956559bc60d5f27280366e4bd65d4d26558c3d3 Mon Sep 17 00:00:00 2001
From: Volodymyr Turanskyy <volodymyr.turanskyy at arm.com>
Date: Mon, 13 Apr 2026 17:28:14 +0100
Subject: [PATCH] Add profile library to the command line when needed
Now that libclang_rt.profile.a supports bare-metal targets, follow other drivers
and add libclang_rt.profile.a in the BareMetal driver to the command line
automatically when needed, e.g. when -fprofile-instr-generate is provided.
---
clang/lib/Driver/ToolChains/BareMetal.cpp | 1 +
clang/test/Driver/baremetal.cpp | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 9370eb21454e3..3ba592666647a 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -605,6 +605,7 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
D.getLTOMode() == LTOK_Thin);
AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+ TC.addProfileRTLibs(Args, CmdArgs);
if (TC.ShouldLinkCXXStdlib(Args)) {
bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 70e74743c1338..f36faf59f55d6 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -176,6 +176,18 @@
// RUN: | FileCheck %s --check-prefix=CHECK-RTLIB-GCC
// CHECK-RTLIB-GCC: -lgcc
+// RUN: %clang -### --target=arm-none-eabi -rtlib=compiler-rt \
+// RUN: -fprofile-instr-generate %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-PROFILE
+// CHECK-PROFILE: "{{[^"]*}}libclang_rt.profile.a"
+
+// RUN: %clang -### --target=arm-none-eabi -nostdlib -rtlib=compiler-rt \
+// RUN: -fprofile-instr-generate %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-PROFILE-NOSTDLIB
+// CHECK-PROFILE-NOSTDLIB: "{{[^"]*}}libclang_rt.profile.a"
+// CHECK-PROFILE-NOSTDLIB-NOT: "-lc"
+// CHECK-PROFILE-NOSTDLIB-NOT: "{{[^"]*}}libclang_rt.builtins.a"
+
// RUN: %clang -### --target=arm-none-eabi -nolibc -rtlib=compiler-rt %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NOLIBC
// CHECK-NOLIBC-NOT: "-lc"
More information about the cfe-commits
mailing list