Repository navigation
Conversation
configure_platform.cmake only knows x86, x86_64, aarch64 and arm, so configuring OpenModelica on powerpc64 or powerpc64le stops with "Unknown host". Map them to the POWERPC target like libffi's configure.host does for powerpc64*-*-linux* and powerpc64*-*-freebsd*, and build the 64-bit ELF sources: ffi.c, ffi_linux64.c, linux64.S and linux64_closure.S. configure.host also lists ffi_sysv.c, sysv.S and ppc_closure.S, but they are 32-bit only (everything is under #ifndef POWERPC64) and the two .S files include <powerpc/asm.h> relative to src/, which the CMake build does not have on its include path, so they are left out. The pattern covers both variables the wrapper looks at: before CMake 4.1, CMAKE_C_COMPILER_ARCHITECTURE_ID is empty for GCC and Clang and CMAKE_SYSTEM_PROCESSOR is "powerpc64le" on FreeBSD and "ppc64le" on Linux, while CMake 4.1 and later report "ppc64le" or "ppc64" as the compiler architecture. Verified on FreeBSD 15.1 powerpc64le (clang 19, CMake 3.31): the bundled libffi builds, and ffi_call with int, double, long double, struct and pointer arguments returns the expected values.
FFI_MMAP_EXEC_WRIT was only set on Darwin and when TARGET_PLATFORM contains FREEBSD, which only the i386 platform on FreeBSD and OpenBSD does. Every other build on those systems got the malloc based closure allocator, and since malloc memory is not executable there, calling a closure made by ffi_prep_closure_loc crashes with SIGSEGV. Set it from CMAKE_SYSTEM_NAME instead, for the systems libffi's configure.ac sets it for (Darwin, FreeBSD, OpenBSD, Solaris and Android), so the mmap based allocator is used on every CPU there. Found while testing the previous commit on FreeBSD 15.1 powerpc64le: a small program that calls a closure crashed with SIGSEGV before this change and passes with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
None filed. Seen while building OpenModelica 1.25.7 on FreeBSD/powerpc64le
(FreeBSD port science/openmodelica):
Purpose
configure_platform.cmakeonly knows x86, x86_64, aarch64 and arm, so thebundled libffi, and with it the whole OpenModelica configure step, fails on
powerpc64 and powerpc64le. libffi itself supports them (
configure.hostmapspowerpc64*-*-linux*andpowerpc64*-*-freebsd*toTARGET=POWERPC); onlythe CMake wrapper is missing the mapping.
While testing closures on that platform I also found that
FFI_MMAP_EXEC_WRITis only set on Darwin and when the platform name contains
FREEBSD, whichonly the i386 platform on FreeBSD and OpenBSD does. Every other build on those
systems gets the plain
mallocclosure allocator, and sincemallocmemory isnot executable there, calling a closure crashes with SIGSEGV. OpenModelica's
ffi_omc.cpponly usesffi_call, so this is latent for omc, but the bundledlibrary should not be broken for closures.
Approach
powerpc64*/ppc64*hosts toTARGET_PLATFORM POWERPCand build the64-bit ELF sources
ffi.c,ffi_linux64.c,linux64.Sandlinux64_closure.SwithTARGETDIR powerpc. The pattern matches bothCMAKE_SYSTEM_PROCESSOR(powerpc64leon FreeBSD,ppc64leon Linux) andthe
ppc64le/ppc64compiler architecture ID that CMake 4.1+ reports. The32-bit
ffi_sysv.c,sysv.Sandppc_closure.Sfromconfigure.hostareleft out: they are entirely under
#ifndef POWERPC64, and the two.Sfiles include
<powerpc/asm.h>relative tosrc/, which the CMake builddoes not put on the include path.
FFI_MMAP_EXEC_WRITfromCMAKE_SYSTEM_NAMEfor the systems libffi'sconfigure.acsets it for (Darwin, FreeBSD, OpenBSD, Solaris, Android).src/tramp.cis already inSOURCES_LISTon master, so the mmap allocatorlinks.
Tested on FreeBSD 15.1-RELEASE powerpc64le (POWER9, clang 19.1.7, CMake 3.31)
with a standalone CMake build of
libffi/from OMCompiler-3rdParty master anda small test program that calls
ffi_callwith int, double, long double,struct and pointer arguments and then calls a closure made with
ffi_prep_closure_loc:ffi_callWith the first change applied as a FreeBSD port patch, OpenModelica 1.25.7
builds, packages and runs on FreeBSD 15.1 powerpc64le: the HelloWorld example
simulates correctly, and
external "C"functions that the frontend evaluatesthrough libffi (
sin(0.5),ldexp(0.75, 3)) return the right values.