Skip to content

Commit 12c4799

Browse files
committed
Port bootstrap build on OpenBSD
1 parent c0d7ef5 commit 12c4799

32 files changed

Lines changed: 267 additions & 98 deletions

File tree

eng/native/configurecompiler.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,27 @@ else(CLR_CMAKE_TARGET_UNIX)
847847
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
848848
endif(CLR_CMAKE_TARGET_UNIX)
849849

850+
# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
851+
# (libc++/libc++abi), so default to those there. An explicit selection via
852+
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
853+
# toolchain file) still takes precedence.
854+
if(CLR_CMAKE_TARGET_OPENBSD)
855+
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
856+
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
857+
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
858+
endif()
859+
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
860+
add_link_options("LINKER:-lc++abi")
861+
endif()
862+
863+
# Use native (not emulated) TLS so C/C++ __thread vars match the runtime's assembly.
864+
add_compile_options(-fno-emulated-tls)
865+
866+
# OpenBSD has no __tls_get_addr (only static TLS). Use initial-exec so general-dynamic
867+
# TLS (and its unresolvable __tls_get_addr reference in shared objects) is never emitted.
868+
add_compile_options(-ftls-model=initial-exec)
869+
endif()
870+
850871
if(CLR_CMAKE_HOST_UNIX_ARM)
851872
if (NOT DEFINED CLR_ARM_FPU_TYPE)
852873
set(CLR_ARM_FPU_TYPE vfpv3)

eng/native/functions.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
192192
find_library(UNWIND NAMES unwind)
193193

194194
if(UNWIND STREQUAL UNWIND-NOTFOUND)
195-
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.")
195+
if(CLR_CMAKE_TARGET_OPENBSD)
196+
# On OpenBSD the libunwind symbols are provided by the C++ ABI library
197+
# (libc++abi), so a standalone libunwind is not expected.
198+
set(UNWIND "")
199+
else()
200+
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.")
201+
endif()
196202
endif()
197203

198204
set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
10131013
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
10141014
size_t GCToOSInterface::GetVirtualMemoryLimit()
10151015
{
1016+
#ifdef RLIMIT_AS
10161017
rlimit addressSpaceLimit;
10171018
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
10181019
{
10191020
return addressSpaceLimit.rlim_cur;
10201021
}
1022+
#endif // RLIMIT_AS
10211023

10221024
// No virtual memory limit
10231025
return GetVirtualMemoryMaxAddress();

src/coreclr/hosts/corerun/corerun.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ class platform_specific_actions final
384384
#include <link.h>
385385
#include <elf.h>
386386
#include <cstring>
387+
388+
// glibc defines the ElfW() macro to select the native-width Elf type, but some
389+
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
390+
#ifndef ElfW
391+
#if defined(TARGET_64BIT)
392+
#define ElfW(type) Elf64_##type
393+
#else
394+
#define ElfW(type) Elf32_##type
395+
#endif
396+
#endif // ElfW
387397
#endif
388398

389399
// CMake generated

src/coreclr/inc/check.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
3+
34
// ---------------------------------------------------------------------------
45
// Check.h
5-
//
6-
76
//
87
// Assertion checking infrastructure
98
// ---------------------------------------------------------------------------
@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
663662
CHECK CheckAligned(ULONG value, UINT alignment);
664663
#endif
665664
CHECK CheckAligned(UINT64 value, UINT alignment);
666-
#ifdef __APPLE__
665+
#if defined(__APPLE__) || defined(__OpenBSD__)
667666
CHECK CheckAligned(SIZE_T value, UINT alignment);
668667
#endif
669668
CHECK CheckAligned(const void *address, UINT alignment);
@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
673672
CHECK CheckOverflow(ULONG value1, ULONG value2);
674673
#endif
675674
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
676-
#ifdef __APPLE__
675+
#if defined(__APPLE__) || defined(__OpenBSD__)
677676
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
678677
#endif
679678
#ifndef __wasm__
@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
689688
CHECK CheckUnderflow(ULONG value1, ULONG value2);
690689
#endif
691690
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
692-
#ifdef __APPLE__
691+
#if defined(__APPLE__) || defined(__OpenBSD__)
693692
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
694693
#endif
695694
CHECK CheckUnderflow(const void *address, UINT offset);
696695
#if defined(_MSC_VER)
697696
CHECK CheckUnderflow(const void *address, ULONG offset);
698697
#endif
699698
CHECK CheckUnderflow(const void *address, UINT64 offset);
700-
#ifdef __APPLE__
699+
#if defined(__APPLE__) || defined(__OpenBSD__)
701700
CHECK CheckUnderflow(const void *address, SIZE_T offset);
702701
#endif
703702
CHECK CheckUnderflow(const void *address, void *address2);

src/coreclr/inc/check.inl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
156156
CHECK_OK;
157157
}
158158

159-
#if defined(__APPLE__) || defined(__wasm__)
159+
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
160160
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
161161
{
162162
STATIC_CONTRACT_WRAPPER;
@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
192192
CHECK_OK;
193193
}
194194

195-
#ifdef __APPLE__
195+
#if defined(__APPLE__) || defined(__OpenBSD__)
196196
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
197197
{
198198
CHECK(value1 + value2 >= value1);
@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
237237
CHECK_OK;
238238
}
239239

240-
#if defined(__APPLE__) || defined(__wasm__)
240+
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
241241
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
242242
{
243243
CHECK((UINT64) address + offset >= (UINT64) address);
@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
271271
CHECK_OK;
272272
}
273273

274-
#ifdef __APPLE__
274+
#if defined(__APPLE__) || defined(__OpenBSD__)
275275
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
276276
{
277277
CHECK(value1 - value2 <= value1);
@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
316316
CHECK_OK;
317317
}
318318

319-
#if defined(__APPLE__) || defined(__wasm__)
319+
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
320320
inline CHECK CheckUnderflow(const void *address, SIZE_T offset)
321321
{
322322
// SIZE_T is 32bit on wasm32
@@ -371,4 +371,3 @@ inline CHECK CheckBounds(const void *rangeBase, UINT32 rangeSize, UINT32 offset,
371371
}
372372

373373
#endif // CHECK_INL_
374-

src/coreclr/inc/clrtypes.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
3+
34
// ================================================================================
45
// Standard primitive types for CLR code
56
//
@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
275276
return (value+alignment-1)&~(UINT64)(alignment-1);
276277
}
277278

278-
#if defined(__APPLE__) || defined(__wasm__)
279+
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
279280
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
280281
{
281282
STATIC_CONTRACT_LEAF;
@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
316317
}
317318
#endif
318319

319-
#ifdef __APPLE__
320+
#if defined(__APPLE__) || defined(__OpenBSD__)
320321
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
321322
{
322323
STATIC_CONTRACT_LEAF;
@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
345346
return (UINT) (AlignUp(value, alignment) - value);
346347
}
347348

348-
#if defined(__APPLE__) || defined(__wasm__)
349+
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
349350
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
350351
{
351352
STATIC_CONTRACT_WRAPPER;
@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
378379
return ((UINT)value)&(alignment-1);
379380
}
380381

381-
#if defined(__APPLE__) || defined(__wasm__)
382+
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
382383
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
383384
{
384385
STATIC_CONTRACT_LEAF;

src/coreclr/inc/pedecoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
102102
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
103103
#elif defined(__FreeBSD__)
104104
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
105+
#elif defined(__OpenBSD__)
106+
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
105107
#elif defined(__linux__)
106108
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
107109
#elif defined(__NetBSD__)

src/coreclr/jit/compiler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
141141
return BitOperations::BitScanForward(value);
142142
}
143143

144-
#ifdef __APPLE__
144+
#if defined(__APPLE__) || defined(__OpenBSD__)
145145
inline unsigned genLog2(size_t value)
146146
{
147147
return genLog2((uint64_t)value);
148148
}
149-
#endif // __APPLE__
149+
#endif // __APPLE__ || __OpenBSD__
150150

151151
// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
152152
//

src/coreclr/jit/jit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
731731
return ((size_t)std::abs((int64_t)x));
732732
}
733733

734-
#ifdef __APPLE__
734+
#if defined(__APPLE__) || defined(__OpenBSD__)
735735
inline size_t unsigned_abs(int64_t x)
736736
{
737737
return ((size_t)std::abs(x));
738738
}
739-
#endif // __APPLE__
739+
#endif // __APPLE__ || __OpenBSD__
740740
#endif // TARGET_64BIT
741741

742742
/*****************************************************************************/

0 commit comments

Comments
 (0)