ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Unable to build LDC 1.41 on FreeBSD/PowerPC64

Open lenoil98 opened this issue 5 months ago • 8 comments

Attempting to build LDC 1.41 on FreeBSD 14.1 on PowerPC64(BE) using GDC, from GCC v14.2.

Get the below error:

std/internal/math/gammafunction.d(262): Error: static assert: "missing MAXGAMMA for other real types" static assert(0, "missing MAXGAMMA for other real types"); ^

All/Any help is appreciated.

lenoil98 avatar Jul 22 '25 16:07 lenoil98

please file this issue upstream in https://github.com/dlang/phobos/issues

thewilsonator avatar Jul 23 '25 00:07 thewilsonator

Opened issue upstream as requested.

lenoil98 avatar Jul 25 '25 03:07 lenoil98

Discovered that a recent commit is the cause, so I reopened this issue. Commits in #4833 in gen/target.cpp to fix PowerPC IEEE long double broke build for FreeBSD/PowerPC. Here's the relevent code:


#if defined(__linux__) && defined(__powerpc64__)
    // for a PowerPC64 Linux build:
    // default to the C++ host compiler's `long double` ABI when targeting
    // PowerPC64 (non-musl) Linux
    if (triple.isOSLinux()) {
#if __LDBL_MANT_DIG__ == 113
      return LLType::getFP128Ty(ctx);
#elif __LDBL_MANT_DIG__ == 106
      return LLType::getPPC_FP128Ty(ctx);
#elif __LDBL_MANT_DIG__ == 53
      return LLType::getDoubleTy(ctx);
#else
      static_assert(
          __LDBL_MANT_DIG__ == 0,
          "Unexpected C++ 'long double' precision for a PowerPC64 host!");
#endif
    }
#endif

The following modifications allowed me to build on FreeBSD/PowerPC:


   // for a PowerPC64 Linux and FreeBSD build:
    // default to the C++ host compiler's `long double` ABI when targeting
    // PowerPC64 (non-musl) Linux
    if (triple.isOSLinux() || triple.isOSFreeBSD()) {
#if __LDBL_MANT_DIG__ == 113
      return LLType::getFP128Ty(ctx);
#elif __LDBL_MANT_DIG__ == 106
      return LLType::getPPC_FP128Ty(ctx);
#elif __LDBL_MANT_DIG__ == 53
      return LLType::getDoubleTy(ctx);
#else
      static_assert(
          __LDBL_MANT_DIG__ == 0,
          "Unexpected C++ 'long double' precision for a PowerPC64 host!");
#endif
    }

While this works for FreeBSD, other BSDs using PowerPC will have the same issue.

lenoil98 avatar Aug 01 '25 15:08 lenoil98

That just enabled the doubledouble type, if the C++ compiler uses it on that platform. So the issue remains in upstream Phobos, probably just a simple constant missing for that exotic format.

kinke avatar Aug 01 '25 19:08 kinke

Oh sorry, just checked your diff (manually) - so the propagation of the host-C++ long double is only enabled on non-musl Linux, not for any BSDs etc. Which is probably too conservative, and doing that on Posix in general might make more sense (even on musl, since the expected C++ compiler is supposed to target a 64-bit long double too). A PR would be welcome! :)

kinke avatar Aug 01 '25 20:08 kinke

Were you able to resolve the issue and successfully build LDC for ppc64le? I'm trying to build an image with LDC (https://hub.docker.com/r/starxen/ldc), but unfortunately I encounter an error during the build. Here is where the error occurs:

[108/268] /usr/bin/c++ -DLDC_DYNAMIC_COMPILE -DLDC_DYNAMIC_COMPILE_API_VERSION=4 -DLDC_ENABLE_PLUGINS -DLDC_LLVM_SUPPORTED_TARGET_AArch64=1 -DLDC_LLVM_SUPPORTED_TARGET_AMDGPU=1 -DLDC_LLVM_SUPPORTED_TARGET_ARM=1 -DLDC_LLVM_SUPPORTED_TARGET_AVR=1 -DLDC_LLVM_SUPPORTED_TARGET_BPF=1 -DLDC_LLVM_SUPPORTED_TARGET_Hexagon=1 -DLDC_LLVM_SUPPORTED_TARGET_Lanai=1 -DLDC_LLVM_SUPPORTED_TARGET_LoongArch=1 -DLDC_LLVM_SUPPORTED_TARGET_M68k=1 -DLDC_LLVM_SUPPORTED_TARGET_MSP430=1 -DLDC_LLVM_SUPPORTED_TARGET_Mips=1 -DLDC_LLVM_SUPPORTED_TARGET_NVPTX=1 -DLDC_LLVM_SUPPORTED_TARGET_PowerPC=1 -DLDC_LLVM_SUPPORTED_TARGET_RISCV=1 -DLDC_LLVM_SUPPORTED_TARGET_Sparc=1 -DLDC_LLVM_SUPPORTED_TARGET_SystemZ=1 -DLDC_LLVM_SUPPORTED_TARGET_VE=1 -DLDC_LLVM_SUPPORTED_TARGET_WebAssembly=1 -DLDC_LLVM_SUPPORTED_TARGET_X86=1 -DLDC_LLVM_SUPPORTED_TARGET_XCore=1 -DLDC_LLVM_SUPPORTED_TARGET_Xtensa=1 -I/build/ldc/. -I/build/ldc/dmd -DDMDV2 -O3 -DNDEBUG -I/usr/lib/llvm-19/include -std=c++17 -fno-exceptions -funwind-tables -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wno-missing-field-initializers -Wno-non-virtual-dtor -Wno-pedantic -DLDC_POSIX -DIN_LLVM -DOPAQUE_VTBLS "-DLDC_INSTALL_PREFIX=R"(/install-ldc)"" -DLDC_LLVM_VER=1901 "-DLDC_LIBDIR_SUFFIX=R"()"" -DLDC_HOST_GDMD=1 -DLDC_HOST_FE_VER=2108 "-DLDC_LLVM_LIBDIR=R"(/usr/lib/llvm-19/lib)"" -DNDEBUG -MD -MT CMakeFiles/LDCShared.dir/driver/main.cpp.o -MF CMakeFiles/LDCShared.dir/driver/main.cpp.o.d -o CMakeFiles/LDCShared.dir/driver/main.cpp.o -c /build/ldc/driver/main.cpp ninja: build stopped: subcommand failed. root@c30a233567fe:/build/build-ldc#

Below is a minimal Dockerfile that reproduces this build using Docker with buildx (via QEMU on any host):

FROM debian:13 AS build_ldc
RUN apt-get update && apt-get install -y git-core g++ gdc gdmd cmake ninja-build python3 zlib1g-dev libcurl4t64 gdb unzip zip tzdata llvm-dev libclang-common-19-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /build
RUN git clone https://github.com/ldc-developers/ldc && cd ldc && git checkout tags/v1.41.0 && git submodule update --init --recursive
WORKDIR /build/build-ldc
RUN cmake -G Ninja ../ldc -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=/install-ldc

Based on this Dockerfile

You can run it with the following commands:

docker buildx build -t starxen/ldc:trixie_ppc64le --platform linux/ppc64le --load
docker run --rm -it --platform linux/ppc64le starxen/ldc:trixie_ppc64le bash
ninja -v -j"$(nproc)"

If I can provide a more detailed log or anything else, please let me know where to send it—I’m happy to help.

laserovsky avatar Oct 26 '25 12:10 laserovsky

Were you able to resolve the issue and successfully build LDC for ppc64le? I'm trying to build an image with LDC (https://hub.docker.com/r/starxen/ldc), but unfortunately I encounter an error during the build. Here is where the error occurs:

[108/268] /usr/bin/c++ -DLDC_DYNAMIC_COMPILE -DLDC_DYNAMIC_COMPILE_API_VERSION=4 -DLDC_ENABLE_PLUGINS -DLDC_LLVM_SUPPORTED_TARGET_AArch64=1 -DLDC_LLVM_SUPPORTED_TARGET_AMDGPU=1 -DLDC_LLVM_SUPPORTED_TARGET_ARM=1 -DLDC_LLVM_SUPPORTED_TARGET_AVR=1 -DLDC_LLVM_SUPPORTED_TARGET_BPF=1 -DLDC_LLVM_SUPPORTED_TARGET_Hexagon=1 -DLDC_LLVM_SUPPORTED_TARGET_Lanai=1 -DLDC_LLVM_SUPPORTED_TARGET_LoongArch=1 -DLDC_LLVM_SUPPORTED_TARGET_M68k=1 -DLDC_LLVM_SUPPORTED_TARGET_MSP430=1 -DLDC_LLVM_SUPPORTED_TARGET_Mips=1 -DLDC_LLVM_SUPPORTED_TARGET_NVPTX=1 -DLDC_LLVM_SUPPORTED_TARGET_PowerPC=1 -DLDC_LLVM_SUPPORTED_TARGET_RISCV=1 -DLDC_LLVM_SUPPORTED_TARGET_Sparc=1 -DLDC_LLVM_SUPPORTED_TARGET_SystemZ=1 -DLDC_LLVM_SUPPORTED_TARGET_VE=1 -DLDC_LLVM_SUPPORTED_TARGET_WebAssembly=1 -DLDC_LLVM_SUPPORTED_TARGET_X86=1 -DLDC_LLVM_SUPPORTED_TARGET_XCore=1 -DLDC_LLVM_SUPPORTED_TARGET_Xtensa=1 -I/build/ldc/. -I/build/ldc/dmd -DDMDV2 -O3 -DNDEBUG -I/usr/lib/llvm-19/include -std=c++17 -fno-exceptions -funwind-tables -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wno-missing-field-initializers -Wno-non-virtual-dtor -Wno-pedantic -DLDC_POSIX -DIN_LLVM -DOPAQUE_VTBLS "-DLDC_INSTALL_PREFIX=R"(/install-ldc)"" -DLDC_LLVM_VER=1901 "-DLDC_LIBDIR_SUFFIX=R"()"" -DLDC_HOST_GDMD=1 -DLDC_HOST_FE_VER=2108 "-DLDC_LLVM_LIBDIR=R"(/usr/lib/llvm-19/lib)"" -DNDEBUG -MD -MT CMakeFiles/LDCShared.dir/driver/main.cpp.o -MF CMakeFiles/LDCShared.dir/driver/main.cpp.o.d -o CMakeFiles/LDCShared.dir/driver/main.cpp.o -c /build/ldc/driver/main.cpp ninja: build stopped: subcommand failed. root@c30a233567fe:/build/build-ldc#

Below is a minimal Dockerfile that reproduces this build using Docker with buildx (via QEMU on any host):

FROM debian:13 AS build_ldc RUN apt-get update && apt-get install -y git-core g++ gdc gdmd cmake ninja-build python3 zlib1g-dev libcurl4t64 gdb unzip zip tzdata llvm-dev libclang-common-19-dev && rm -rf /var/lib/apt/lists/* WORKDIR /build RUN git clone https://github.com/ldc-developers/ldc && cd ldc && git checkout tags/v1.41.0 && git submodule update --init --recursive WORKDIR /build/build-ldc RUN cmake -G Ninja ../ldc -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=/install-ldc

Based on this Dockerfile

You can run it with the following commands:

docker buildx build -t starxen/ldc:trixie_ppc64le --platform linux/ppc64le --load docker run --rm -it --platform linux/ppc64le starxen/ldc:trixie_ppc64le bash ninja -v -j"$(nproc)"

If I can provide a more detailed log or anything else, please let me know where to send it—I’m happy to help.

I was able to build on both LE and BE by changing "target.cpp" to include "FreeBSD" for long double on PowerPC64. However, I don't think this will resolve your issue, as you're building on Linux.

lenoil98 avatar Oct 27 '25 13:10 lenoil98

Hey, actually I noticed the PowerPC part and started writing, but I didn’t realize it was on FreeBSD. Thanks for the hint!

laserovsky avatar Oct 28 '25 18:10 laserovsky