Skip to content

Commit add98b2

Browse files
committed
[compiler-rt] Support FreeBSD standalone (boot) environment
FreeBSD uses -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface to poison uses of floating point in its standalone environment. It also deprecates machine/limits.h in favour of sys/limits.h and does not even provide the former on newer architectures. This is a cleaner reimplementation of equivalent patches in FreeBSD's vendored copy of compiler-rt. Reviewed By: dim Differential Revision: https://reviews.llvm.org/D95264
1 parent 5386aa2 commit add98b2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler-rt/lib/builtins/int_lib.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,21 @@
7070
#error Unsupported target
7171
#endif
7272

73-
#if defined(__NetBSD__) && (defined(_KERNEL) || defined(_STANDALONE))
73+
#if (defined(__FreeBSD__) || defined(__NetBSD__)) && \
74+
(defined(_KERNEL) || defined(_STANDALONE))
7475
//
7576
// Kernel and boot environment can't use normal headers,
7677
// so use the equivalent system headers.
78+
// NB: FreeBSD (and OpenBSD) deprecate machine/limits.h in
79+
// favour of sys/limits.h, so prefer the former, but fall
80+
// back on the latter if not available since NetBSD only has
81+
// the latter.
7782
//
83+
#if defined(__has_include) && __has_include(<sys/limits.h>)
84+
#include <sys/limits.h>
85+
#else
7886
#include <machine/limits.h>
87+
#endif
7988
#include <sys/stdint.h>
8089
#include <sys/types.h>
8190
#else

compiler-rt/lib/builtins/int_types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ static __inline tu_int make_tu(du_int h, du_int l) {
121121

122122
#endif // CRT_HAS_128BIT
123123

124+
// FreeBSD's boot environment does not support using floating-point and poisons
125+
// the float and double keywords.
126+
#if defined(__FreeBSD__) && defined(_STANDALONE)
127+
#define CRT_HAS_FLOATING_POINT 0
128+
#else
129+
#define CRT_HAS_FLOATING_POINT 1
130+
#endif
131+
132+
#if CRT_HAS_FLOATING_POINT
124133
typedef union {
125134
su_int u;
126135
float f;
@@ -130,6 +139,7 @@ typedef union {
130139
udwords u;
131140
double f;
132141
} double_bits;
142+
#endif
133143

134144
typedef struct {
135145
#if _YUGA_LITTLE_ENDIAN
@@ -155,6 +165,7 @@ typedef struct {
155165
#define HAS_80_BIT_LONG_DOUBLE 0
156166
#endif
157167

168+
#if CRT_HAS_FLOATING_POINT
158169
typedef union {
159170
uqwords u;
160171
long double f;
@@ -183,4 +194,5 @@ typedef struct {
183194
#define COMPLEX_REAL(x) (x).real
184195
#define COMPLEX_IMAGINARY(x) (x).imaginary
185196
#endif
197+
#endif
186198
#endif // INT_TYPES_H

0 commit comments

Comments
 (0)