[compiler-rt] [compiler-rt] FreeBSD kernel headers in baremetal libprofile (PR #211278)

Justin Cady via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 07:48:19 PDT 2026


https://github.com/justincady created https://github.com/llvm/llvm-project/pull/211278

Add conditional FreeBSD kernel headers when building baremetal profile
library. This is unconnected to a CMake target; it requires building
libprofile out of band with `-DCOMPILER_RT_PROFILE_BAREMETAL=1`.

The headers replaced in this diff are not available when building for
FreeBSD kernel space. This is the first issue I hit when experimenting
with using the baremetal libprofile like this, so there may be other
changes required as I make progress.

>From fdd8f075a4e975331e5bc664570740a3cd4a58e2 Mon Sep 17 00:00:00 2001
From: Justin Cady <desk at justincady.com>
Date: Wed, 22 Jul 2026 10:36:03 -0400
Subject: [PATCH] [compiler-rt] FreeBSD kernel headers in baremetal libprofile

Add conditional FreeBSD kernel headers when building baremetal profile
library. This is unconnected to a CMake target; it requires building
libprofile out of band with `-DCOMPILER_RT_PROFILE_BAREMETAL=1`.

The headers replaced in this diff are not available when building for
FreeBSD kernel space. This is the first issue I hit when experimenting
with using the baremetal libprofile like this, so there may be other
changes required as I make progress.
---
 compiler-rt/lib/profile/InstrProfiling.c         | 5 +++++
 compiler-rt/lib/profile/InstrProfiling.h         | 5 +++++
 compiler-rt/lib/profile/InstrProfilingInternal.h | 5 +++++
 compiler-rt/lib/profile/InstrProfilingPort.h     | 4 ++++
 compiler-rt/lib/profile/InstrProfilingWriter.c   | 4 ++++
 5 files changed, 23 insertions(+)

diff --git a/compiler-rt/lib/profile/InstrProfiling.c b/compiler-rt/lib/profile/InstrProfiling.c
index d59ec78ad3296..a0adb43d7957f 100644
--- a/compiler-rt/lib/profile/InstrProfiling.c
+++ b/compiler-rt/lib/profile/InstrProfiling.c
@@ -9,8 +9,13 @@
 // Note: This is linked into the Darwin kernel, and must remain compatible
 // with freestanding compilation. See `darwin_add_builtin_libraries`.
 
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include <sys/limits.h>
+#include <sys/systm.h>
+#else
 #include <limits.h>
 #include <string.h>
+#endif
 
 #include "InstrProfiling.h"
 #include "InstrProfilingInternal.h"
diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h
index f4b4a5f622894..369f26b33ba1d 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -10,7 +10,12 @@
 #define PROFILE_INSTRPROFILING_H_
 
 #include "InstrProfilingPort.h"
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include <sys/stddef.h>
+#include <sys/types.h>
+#else
 #include <stddef.h>
+#endif
 #ifndef COMPILER_RT_PROFILE_BAREMETAL
 #include <stdio.h>
 #endif
diff --git a/compiler-rt/lib/profile/InstrProfilingInternal.h b/compiler-rt/lib/profile/InstrProfilingInternal.h
index 61485915bddad..e53c0e28edb13 100644
--- a/compiler-rt/lib/profile/InstrProfilingInternal.h
+++ b/compiler-rt/lib/profile/InstrProfilingInternal.h
@@ -9,7 +9,12 @@
 #ifndef PROFILE_INSTRPROFILING_INTERNALH_
 #define PROFILE_INSTRPROFILING_INTERNALH_
 
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include <sys/stddef.h>
+#include <sys/types.h>
+#else
 #include <stddef.h>
+#endif
 
 #include "InstrProfiling.h"
 
diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h b/compiler-rt/lib/profile/InstrProfilingPort.h
index 0149c7aacb2da..0f397046d2eae 100644
--- a/compiler-rt/lib/profile/InstrProfilingPort.h
+++ b/compiler-rt/lib/profile/InstrProfilingPort.h
@@ -146,6 +146,10 @@ static inline size_t getpagesize(void) {
 #define O_BINARY 0
 #endif
 
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include <sys/stdint.h>
+#else
 #include <stdint.h>
+#endif
 
 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */
diff --git a/compiler-rt/lib/profile/InstrProfilingWriter.c b/compiler-rt/lib/profile/InstrProfilingWriter.c
index 3021e3b3cfc31..59fa2af316544 100644
--- a/compiler-rt/lib/profile/InstrProfilingWriter.c
+++ b/compiler-rt/lib/profile/InstrProfilingWriter.c
@@ -13,7 +13,11 @@
 /* For _alloca */
 #include <malloc.h>
 #endif
+#if defined(__FreeBSD__) && defined(_KERNEL)
+#include <sys/systm.h>
+#else
 #include <string.h>
+#endif
 
 #include "InstrProfiling.h"
 #include "InstrProfilingInternal.h"



More information about the llvm-commits mailing list