diff --git a/runtime/DRuntimeIntegrationTests.cmake b/runtime/DRuntimeIntegrationTests.cmake index 1927c0b010..152e79067e 100644 --- a/runtime/DRuntimeIntegrationTests.cmake +++ b/runtime/DRuntimeIntegrationTests.cmake @@ -57,7 +57,7 @@ else() list(REMOVE_ITEM testnames uuid) endif() -set(musl "") +set(musl "IS_MUSL=0") if(TARGET_SYSTEM MATCHES "musl") set(musl "IS_MUSL=1") endif() @@ -89,7 +89,7 @@ foreach(name ${testnames}) ROOT=${outdir} DMD=${LDMD_EXE_FULL} BUILD=${build} SHARED=1 DRUNTIME=${druntime_path_build} DRUNTIMESO=${shared_druntime_path_build} ${cc} ${cxx} CFLAGS_BASE=${cflags_base} DFLAGS_BASE=${dflags_base} ${linkdl} - IN_LDC=1 ${musl} + IN_LDC=1 ${musl} BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} ) set_tests_properties(${fullname} PROPERTIES DEPENDS clean-${fullname}) endforeach() diff --git a/runtime/druntime/src/__importc_builtins.di b/runtime/druntime/src/__importc_builtins.di index 312e16c62c..476852cd82 100644 --- a/runtime/druntime/src/__importc_builtins.di +++ b/runtime/druntime/src/__importc_builtins.di @@ -193,3 +193,10 @@ else version (LDC) version (X86) public import ldc.gccbuiltins_x86; version (X86_64) public import ldc.gccbuiltins_x86; } + +version (CRuntime_Glibc) version (AArch64) +{ + // math.h needs these + alias __Float32x4_t = __vector(float[4]); + alias __Float64x2_t = __vector(double[2]); +} diff --git a/runtime/druntime/src/core/sys/posix/sys/shm.d b/runtime/druntime/src/core/sys/posix/sys/shm.d index 6ecdc0defe..7481d8cc60 100644 --- a/runtime/druntime/src/core/sys/posix/sys/shm.d +++ b/runtime/druntime/src/core/sys/posix/sys/shm.d @@ -66,11 +66,11 @@ version (linux) ipc_perm shm_perm; size_t shm_segsz; time_t shm_atime; - version (X86_64) {} else c_ulong __unused1; + static if (time_t.sizeof == 4) c_ulong __unused1; time_t shm_dtime; - version (X86_64) {} else c_ulong __unused2; + static if (time_t.sizeof == 4) c_ulong __unused2; time_t shm_ctime; - version (X86_64) {} else c_ulong __unused3; + static if (time_t.sizeof == 4) c_ulong __unused3; pid_t shm_cpid; pid_t shm_lpid; shmatt_t shm_nattch; diff --git a/runtime/druntime/src/core/sys/posix/sys/types.d b/runtime/druntime/src/core/sys/posix/sys/types.d index 642b3839aa..081748ac60 100644 --- a/runtime/druntime/src/core/sys/posix/sys/types.d +++ b/runtime/druntime/src/core/sys/posix/sys/types.d @@ -103,7 +103,20 @@ version (linux) alias ulong dev_t; alias uint gid_t; alias uint mode_t; - alias ulong_t nlink_t; + + version (X86_64) + alias ulong nlink_t; + else version (S390) + alias size_t nlink_t; + else version (PPC64) + alias size_t nlink_t; + else version (MIPS64) + alias size_t nlink_t; + else version (HPPA64) + alias size_t nlink_t; + else + alias uint nlink_t; + alias int pid_t; //size_t (defined in core.stdc.stddef) alias c_long ssize_t; diff --git a/runtime/druntime/src/importc.h b/runtime/druntime/src/importc.h index d60fcfff75..02e16adf76 100644 --- a/runtime/druntime/src/importc.h +++ b/runtime/druntime/src/importc.h @@ -187,8 +187,16 @@ typedef unsigned long long __uint64_t; #define _Float128 long double #define __float128 long double #endif + +#ifdef __aarch64__ +// glibc's math.h needs these types to be defined +typedef struct {} __SVBool_t; +typedef struct {} __SVFloat32_t; +typedef struct {} __SVFloat64_t; #endif +#endif // __linux__ + #if __APPLE__ #undef __SIZEOF_INT128__ #endif diff --git a/runtime/druntime/test/exceptions/Makefile b/runtime/druntime/test/exceptions/Makefile index 7565e42506..0c630d0517 100644 --- a/runtime/druntime/test/exceptions/Makefile +++ b/runtime/druntime/test/exceptions/Makefile @@ -3,10 +3,12 @@ ifdef IN_LDC include ../../../../dmd/osmodel.mak endif -ifeq ($(OS),linux) - # FIXME: detect musl libc robustly; just checking Alpine Linux' apk tool for now - ifeq (1,$(shell which apk &>/dev/null && echo 1)) - IS_MUSL:=1 +ifndef IS_MUSL # LDC defines it externally + ifeq ($(OS),linux) + # FIXME: detect musl libc robustly; just checking Alpine Linux' apk tool for now + ifeq (1,$(shell which apk >/dev/null 2>&1 && echo 1)) + IS_MUSL := 1 + endif endif endif @@ -65,6 +67,33 @@ endif ifeq ($(OS),windows) TESTS+=winstack endif + +ifdef IN_LDC + ifeq ($(OS)-$(ARCH),linux-aarch64) + # This hits the "should never happen" default branch in the + # rt.dwarfeh._d_throw_exception:399 unwind switch statement. + # The value is 0xf7fe7fb8 which is complete garbage. + TESTS := $(filter-out memoryerror_null_call,$(TESTS)) + + # The aarch64 github runners fail but it works locally + TESTS := $(filter-out memoryerror_%,$(TESTS)) + endif + + ifeq ($(OS),linux) + # These maybe fail with a shared runtime. + # + # CircleCI fails on x86_64, other CI and locally work. + # aarch64 fails locally, shared-only is not tested in CI. + # + # The failure is caused by the backtrace call in + # core.runtime.DefaultTraceInfo.this + ifeq ($(BUILD_SHARED_LIBS),ON) + TESTS := $(filter-out memoryerror_%,$(TESTS)) + endif + $(ROOT)/memoryerror_%: private extra_ldflags.d += -link-defaultlib-shared=false + endif +endif + include ../common.mak $(ROOT)/line_trace.done: $(ROOT)/line_trace$(DOTEXE) diff --git a/runtime/druntime/test/exceptions/src/memoryerror_stackoverflow.d b/runtime/druntime/test/exceptions/src/memoryerror_stackoverflow.d index f54d78d26a..729174f199 100644 --- a/runtime/druntime/test/exceptions/src/memoryerror_stackoverflow.d +++ b/runtime/druntime/test/exceptions/src/memoryerror_stackoverflow.d @@ -1,16 +1,19 @@ import etc.linux.memoryerror; +import core.volatile; pragma(inline, false): void f(ref ubyte[1024] buf) { ubyte[1024] cpy = buf; + volatileStore(&cpy[0], 1); g(cpy); } void g(ref ubyte[1024] buf) { ubyte[1024] cpy = buf; + volatileStore(&cpy[0], 2); f(cpy); } diff --git a/runtime/druntime/test/importc_compare/Makefile b/runtime/druntime/test/importc_compare/Makefile index 983c19bc8a..5a50aef521 100644 --- a/runtime/druntime/test/importc_compare/Makefile +++ b/runtime/druntime/test/importc_compare/Makefile @@ -5,12 +5,19 @@ endif TESTS := importc_compare +ifndef IS_MUSL # LDC defines it externally + ifeq ($(OS),linux) + # FIXME: detect musl libc robustly; just checking Alpine Linux' apk tool for now + ifeq (1,$(shell which apk >/dev/null 2>&1 && echo 1)) + IS_MUSL := 1 + endif + endif +endif + # FIXME: fails on Alpine v3.21 with conflicting struct declarations in the C headers: # /usr/include/asm-generic/fcntl.h(195): Error: struct `importc_includes.flock` conflicts with struct `importc_includes.flock` at /usr/include/fcntl.h(24) -ifeq ($(OS),linux) - ifeq (1,$(shell which apk &>/dev/null && echo 1)) - TESTS := - endif +ifeq ($(IS_MUSL),1) + TESTS := endif # FIXME: fails on macOS arm64, e.g., due to unsupported `_Float16` diff --git a/tests/dmd/compilable/stdcheaders.c b/tests/dmd/compilable/stdcheaders.c index 12674dce37..0d8e0f0422 100644 --- a/tests/dmd/compilable/stdcheaders.c +++ b/tests/dmd/compilable/stdcheaders.c @@ -21,12 +21,10 @@ #include #include -#if !(defined(__linux__) && defined(__aarch64__)) // /usr/include/bits/math-vector.h(162): Error: undefined identifier `__Float32x4_t` #include #ifndef _MSC_VER // C:\Program Files (x86)\Windows Kits\10\include\10.0.26100.0\ucrt\corecrt_math.h(93): Error: reinterpretation through overlapped field `f` is not allowed in CTFE float x = NAN; #endif -#endif #ifndef _MSC_VER // setjmp.h(51): Error: missing tag `identifier` after `struct #include @@ -66,11 +64,9 @@ float x = NAN; // Apple: /Applications/Xcode-14.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/tgmath.h(39): Error: named parameter required before `...` // OpenBSD: /usr/lib/clang/13.0.0/include/tgmath.h(34): Error: named parameter required before `...` // Linux: /tmp/clang/lib/clang/15.0.3/include/tgmath.h(34): Error: named parameter required before `...` -#if !(defined(__linux__) && defined(__aarch64__)) // /usr/include/bits/math-vector.h(162): Error: undefined identifier `__Float32x4_t` #include #endif #endif -#endif #ifndef __linux__ #ifndef __APPLE__