Skip to content

compiling is broken when compiling against muslc #46

@Neo-Desktop

Description

@Neo-Desktop

basically its a gcc problem but the djgpp doesn't build under a muslc environment (and therefore alpine linux)

I had to include this patch for it to build correctly

https://gitweb.gentoo.org/proj/gcc-patches.git/tree/12.1.0/musl/50_all_calloc_libgccjit.patch?id=caa4485a49e1064181e7ac2df2c5476fbb6e9cf5

side note- I also prefer to use clang even though I'm not in a freebsd environment. The build script overrides both CC and CXX even if I pass it in as an environment variable.

the patches below remove the freebsd check and just override the script to use clang and clang++, this is obviously not necessary but it conforms to my usecase

this is the patch set I use to get it to compile correctly under alpine:

/tmp/patches/djgcc/0001-Add-calloc-patch-to-build-script.patch

diff --git a/script/12.1.0 b/script/12.1.0
index 834e0c2..3d94495 100755
--- a/script/12.1.0
+++ b/script/12.1.0
@@ -36,14 +36,10 @@ AUTOMAKE_VERSION=1.15.1
 CC=gcc
 CXX=g++

-# use gmake under FreeBSD
-if [ `uname` = "FreeBSD" ]; then
-  MAKE=gmake
+# use clang on alpine
   CC=clang
   CXX=clang++
-else
   MAKE=make
-fi
 #CFLAGS="-O2 -g $CFLAGS -std=gnu11"

 export CC CXX CFLAGS MAKE
@@ -288,6 +284,10 @@ if uname|grep "^MINGW32" > /dev/null; then
   (cd $BUILDDIR && patch -p0 < $BUILDDIR/../../patch/patch-gcc12-mingw.txt) || exit 1
 fi

+cp /tmp/patches/djgcc/0002-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch $BUILDDIR/../../patch/
+echo "Patch GCC for alpine"
+(cd $BUILDDIR && patch -p0 < $BUILDDIR/../../patch/0002-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch) || exit 1
+
 # patch gnu/gcc-X.XX/gcc/doc/gcc.texi
 echo "Patch gcc/doc/gcc.texi"
 cd gnu/gcc-*/gcc/doc || exit 1

/tmp/patches/djgcc/0002-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch

https://git.alpinelinux.org/aports/plain/main/gcc/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch
https://bugs.gentoo.org/828580
https://gcc.gnu.org/bugzillgnu-orig/gcc-12.10/show_bug.cgi?id=104799 (additional two hunks thrown in from here for 12)

From 72f32e3383129ad139df76d9a063fac9b03079b1 Mon Sep 17 00:00:00 2001
From: Alex McGrath <amk@amk.ie>
Date: Wed, 13 Oct 2021 23:24:27 +0100
Subject: [PATCH] Fix attempt to use poisoned calloc error in libgccjit

This moves usages of pthread.h to above any usage of system.h as it
included #pragma GCC poison calloc
--- gnu-orig/gcc-12.10/gcc/jit/jit-playback.cc
+++ gnu/gcc-12.10/gcc/jit/jit-playback.cc
@@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#include <pthread.h>
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -41,8 +43,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "stmt.h"
 
-#include <pthread.h>
-
 #include "jit-playback.h"
 #include "jit-result.h"
 #include "jit-builtins.h"
--- gnu-orig/gcc-12.10/gcc/jit/jit-recording.cc
+++ gnu/gcc-12.10/gcc/jit/jit-recording.cc
@@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#include <pthread.h>
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -25,8 +27,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "pretty-print.h"
 #include "toplev.h"
 
-#include <pthread.h>
-
 #include "jit-builtins.h"
 #include "jit-recording.h"
 #include "jit-playback.h"
--- gnu-orig/gcc-12.10/gcc/jit/libgccjit.cc
+++ gnu/gcc-12.10/gcc/jit/libgccjit.cc
@@ -18,13 +18,14 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#include <pthread.h>
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
 #include "timevar.h"
 #include "typed-splay-tree.h"
 #include "cppbuiltin.h"
-#include <pthread.h>
 
 #include "libgccjit.h"
 #include "jit-recording.h"
--- gnu-orig/gcc-12.10/libcc1/libcc1plugin.cc
+++ gnu/gcc-12.10/libcc1/libcc1plugin.cc
@@ -17,6 +17,7 @@
    along with GCC; see the file COPYING3.  If not see
    <http://www.gnu.org/licenses/>.  */
 
+#include <pthread.h>
 #include <cc1plugin-config.h>
 
 #undef PACKAGE_NAME
--- gnu-orig/gcc-12.10/libcc1/libcp1plugin.cc
+++ gnu/gcc-12.10/libcc1/libcp1plugin.cc
@@ -18,6 +18,7 @@
    along with GCC; see the file COPYING3.  If not see
    <http://www.gnu.org/licenses/>.  */
 
+#include <pthread.h>
 #include <cc1plugin-config.h>
 
 #undef PACKAGE_NAME

--- gnu-orig/gcc-12.10/gcc/cp/mapper-client.cc
+++ gnu/gcc-12.10/gcc/cp/mapper-client.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #define INCLUDE_STRING
 #define INCLUDE_VECTOR
 #define INCLUDE_MAP
+#include <pthread.h>
 #include "system.h"
 
 #include "line-map.h"
--- gnu-orig/gcc-12.10/gcc/cp/module.cc
+++ gnu/gcc-12.10/gcc/cp/module.cc
@@ -204,6 +204,7 @@ Classes used:
 #include "config.h"
 #define INCLUDE_STRING
 #define INCLUDE_VECTOR
+#include <pthread.h>
 #include "system.h"
 #include "coretypes.h"
 #include "cp-tree.h"
--- gnu-orig/gcc-12.10/gcc/cp/mapper-resolver.cc
+++ gnu/gcc-12.10/gcc/cp/mapper-resolver.cc
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #define INCLUDE_VECTOR
 #define INCLUDE_ALGORITHM
 #define INCLUDE_MAP
+#include <pthread.h>
 #include "system.h"
 
 // We don't want or need to be aware of networking

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions