Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -325,9 +325,16 @@ if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag(-Wl,--build-id=sha1)
add_linker_flag(-Wl,-z,relro,-z,now)
elseif(CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_OPENBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
elseif(CLR_CMAKE_HOST_OPENBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--build-id=sha1")
# OpenBSD's ld.so can't resolve native TLS relocs in a .so; rely on clang's default
# emulated TLS (don't pass -fno-emulated-tls).
# The PAL's hand-written asm lacks endbr64 landing pads, so disable branch-target CFI.
add_linker_flag("-Wl,-z,nobtcfi")
elseif(CLR_CMAKE_HOST_SUNOS)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
Expand DownExpand Up@@ -847,6 +854,20 @@ else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)

# OpenBSD only exposes its libunwind symbols through the LLVM C++ runtime
# (libc++/libc++abi), so default to those there. An explicit selection via
# CLR_CMAKE_CXX_STANDARD_LIBRARY/CLR_CMAKE_CXX_ABI_LIBRARY (applied by the cross
# toolchain file) still takes precedence.
if(CLR_CMAKE_TARGET_OPENBSD)
if(NOT CLR_CMAKE_CXX_STANDARD_LIBRARY)
add_compile_options($<$<COMPILE_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
add_link_options($<$<LINK_LANG_AND_ID:CXX,Clang>:--stdlib=libc++>)
endif()
if(NOT CLR_CMAKE_CXX_ABI_LIBRARY)
add_link_options("LINKER:-lc++abi")
endif()
endif()

if(CLR_CMAKE_HOST_UNIX_ARM)
if (NOT DEFINED CLR_ARM_FPU_TYPE)
set(CLR_ARM_FPU_TYPE vfpv3)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/functions.cmake
Original file line numberDiff line numberDiff line change
Expand Up@@ -192,7 +192,13 @@ function(find_unwind_libs UnwindLibs)
find_library(UNWIND NAMES unwind)

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

set(${UnwindLibs} ${UNWIND_LIBS} ${UNWIND} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1013,11 +1013,13 @@ static size_t GetCurrentVirtualMemorySize()
// non zero if it has succeeded, GetVirtualMemoryMaxAddress() if not available
size_t GCToOSInterface::GetVirtualMemoryLimit()
{
#ifdef RLIMIT_AS
rlimit addressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &addressSpaceLimit) == 0) && (addressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
return addressSpaceLimit.rlim_cur;
}
#endif // RLIMIT_AS

// No virtual memory limit
return GetVirtualMemoryMaxAddress();
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,6 +384,16 @@ class platform_specific_actions final
#include <link.h>
#include <elf.h>
#include <cstring>

// glibc defines the ElfW() macro to select the native-width Elf type, but some
// libcs (e.g. OpenBSD) don't provide it. Fall back to the appropriate fixed-width type.
#ifndef ElfW
#if defined(TARGET_64BIT)
#define ElfW(type) Elf64_##type
#else
#define ElfW(type) Elf32_##type
#endif
#endif // ElfW
#endif

// CMake generated
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.h
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ---------------------------------------------------------------------------
// Check.h
//

//
// Assertion checking infrastructure
// ---------------------------------------------------------------------------
Expand DownExpand Up@@ -663,7 +662,7 @@ CHECK CheckAligned(UINT value, UINT alignment);
CHECK CheckAligned(ULONG value, UINT alignment);
#endif
CHECK CheckAligned(UINT64 value, UINT alignment);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckAligned(SIZE_T value, UINT alignment);
#endif
CHECK CheckAligned(const void *address, UINT alignment);
Expand All@@ -673,7 +672,7 @@ CHECK CheckOverflow(UINT value1, UINT value2);
CHECK CheckOverflow(ULONG value1, ULONG value2);
#endif
CHECK CheckOverflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckOverflow(SIZE_T value1, SIZE_T value2);
#endif
#ifndef __wasm__
Expand All@@ -689,15 +688,15 @@ CHECK CheckUnderflow(UINT value1, UINT value2);
CHECK CheckUnderflow(ULONG value1, ULONG value2);
#endif
CHECK CheckUnderflow(UINT64 value1, UINT64 value2);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2);
#endif
CHECK CheckUnderflow(const void *address, UINT offset);
#if defined(_MSC_VER)
CHECK CheckUnderflow(const void *address, ULONG offset);
#endif
CHECK CheckUnderflow(const void *address, UINT64 offset);
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
CHECK CheckUnderflow(const void *address, SIZE_T offset);
#endif
CHECK CheckUnderflow(const void *address, void *address2);
Expand Down
11 changes: 5 additions & 6 deletions src/coreclr/inc/check.inl
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,7 @@ inline CHECK CheckAligned(UINT64 value, UINT alignment)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckAligned(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -192,7 +192,7 @@ inline CHECK CheckOverflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 + value2 >= value1);
Expand DownExpand Up@@ -237,7 +237,7 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
CHECK_OK;
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
{
CHECK((UINT64) address + offset >= (UINT64) address);
Expand DownExpand Up@@ -271,7 +271,7 @@ inline CHECK CheckUnderflow(UINT64 value1, UINT64 value2)
CHECK_OK;
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline CHECK CheckUnderflow(SIZE_T value1, SIZE_T value2)
{
CHECK(value1 - value2 <= value1);
Expand DownExpand Up@@ -316,7 +316,7 @@ inline CHECK CheckUnderflow(const void *address, UINT64 offset)
CHECK_OK;
}

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

#endif // CHECK_INL_

9 changes: 5 additions & 4 deletions src/coreclr/inc/clrtypes.h
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ================================================================================
// Standard primitive types for CLR code
//
Expand DownExpand Up@@ -275,7 +276,7 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
return (value+alignment-1)&~(UINT64)(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -316,7 +317,7 @@ inline uintptr_t AlignDown(uintptr_t value, UINT alignment)
}
#endif

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline SIZE_T AlignDown(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand DownExpand Up@@ -345,7 +346,7 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
return (UINT) (AlignUp(value, alignment) - value);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_WRAPPER;
Expand DownExpand Up@@ -378,7 +379,7 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
return ((UINT)value)&(alignment-1);
}

#if defined(__APPLE__) || defined(__wasm__)
#if defined(__APPLE__) || defined(__wasm__) || defined(__OpenBSD__)
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
{
STATIC_CONTRACT_LEAF;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/pedecoder.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x4644
#elif defined(__FreeBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC4
#elif defined(__OpenBSD__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0xADC5
#elif defined(__linux__)
#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x7B79
#elif defined(__NetBSD__)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,12 +141,12 @@ inline unsigned genLog2(uint64_t value)
return BitOperations::BitScanForward(value);
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline unsigned genLog2(size_t value)
{
return genLog2((uint64_t)value);
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__

// Given an unsigned 64-bit value, returns the lower 32-bits in unsigned format
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jit.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -731,12 +731,12 @@ inline size_t unsigned_abs(ssize_t x)
return ((size_t)std::abs((int64_t)x));
}

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__OpenBSD__)
inline size_t unsigned_abs(int64_t x)
{
return ((size_t)std::abs(x));
}
#endif // __APPLE__
#endif // __APPLE__ || __OpenBSD__
#endif // TARGET_64BIT

/*****************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/minipal/Unix/doublemapping.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

#include <stddef.h>
#include <sys/mman.h>
Expand DownExpand Up@@ -102,6 +101,8 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
// Clip the maximum double mapped memory size to 1/4 of the virtual address space limit.
// When such a limit is set, GC reserves 1/2 of it, so we need to leave something
// for the rest of the process.
#ifdef RLIMIT_AS
// OpenBSD has no address-space rlimit (RLIMIT_AS), so this clipping is skipped there.
struct rlimit virtualAddressSpaceLimit;
if ((getrlimit(RLIMIT_AS, &virtualAddressSpaceLimit) == 0) && (virtualAddressSpaceLimit.rlim_cur != RLIM_INFINITY))
{
Expand All@@ -111,6 +112,7 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
maxDoubleMappedMemorySize = virtualAddressSpaceLimit.rlim_cur;
}
}
#endif // RLIMIT_AS

// Clip the maximum double mapped memory size to the file size limit
struct rlimit fileSizeLimit;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CppLibCreator>ar</CppLibCreator>
<_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'openbsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
Expand DownExpand Up@@ -65,6 +66,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' != '0'">$(CrossCompileArch)-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and '$(_IsAlpineExitCode)' == '0'">$(CrossCompileArch)-alpine-linux-$(CrossCompileAbi)</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('openbsd')))">$(CrossCompileArch)-unknown-openbsd</TargetTriple>

<SharedLibraryInstallName Condition="'$(SharedLibraryInstallName)' == '' and '$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'">@rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</SharedLibraryInstallName>

Expand DownExpand Up@@ -222,14 +224,14 @@ The .NET Foundation licenses this file to you under the MIT license.

<ItemGroup>
<NativeSystemLibrary Include="stdc++" Condition="'$(LinkStandardCPlusPlusLibrary)' == 'true'" />
<NativeSystemLibrary Include="dl" />
<NativeSystemLibrary Include="dl" Condition="'$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="objc" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
<NativeSystemLibrary Include="zstd" Condition="'$(UseSystemZstd)' == 'true'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic' and '$(_targetOS)' != 'openbsd'" />
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
Expand DownExpand Up@@ -267,6 +269,10 @@ The .NET Foundation licenses this file to you under the MIT license.
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
<!-- OpenBSD enforces IBT/BTCFI on amd64. NativeAOT codegen is not endbr64-instrumented, so
indirect branches (e.g. switch jump tables) to non-endbr64 targets fault with SIGILL.
Opt out of branch-target CFI enforcement via the PT_OPENBSD_NOBTCFI program header. -->
<LinkerArg Include="-Wl,-z,nobtcfi" Condition="'$(_targetOS)' == 'openbsd'" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,12 @@ if(CLR_CMAKE_TARGET_ANDROID)
set(FEATURE_JAVAMARSHAL 1)
endif()

if(CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
add_definitions(-DFEATURE_EMULATED_TLS)
endif()

if(NOT DEFINED FEATURE_JAVAMARSHAL)
set(FEATURE_JAVAMARSHAL $<IF:$<CONFIG:Debug,Checked>,1,0>)
endif()
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,7 +288,10 @@ if(CLR_CMAKE_TARGET_WIN32)
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/safeseh>)
endif()
else()
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
# OpenBSD marks the main executable's read-only segments immutable (mimmutable) at load,
# so the runtime cannot mprotect the read-only GS cookie page to writable to initialize it.
# Keep the cookie in writable memory there, like Apple.
if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
include(unix/configure.cmake)
Expand Down
Loading
Loading