summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorIsmael Luceno2022-05-30 22:35:59 +0200
committerIsmael Luceno2022-06-02 18:31:13 +0200
commita76f1fd315dae5878572b8c315e5db773dc53601 (patch)
treeef22a0be9cfcde069c09098678ec233f58608e50 /gnu
parentd130f54440cd7119bc22455a8795e7d8fda91144 (diff)
gcc: Fix build against musl libc
Diffstat (limited to 'gnu')
-rwxr-xr-xgnu/gcc/BUILD1
-rw-r--r--gnu/gcc/HISTORY7
-rwxr-xr-xgnu/gcc/PRE_BUILD3
-rw-r--r--gnu/gcc/patches/0001-musl-always-use--lib--directory-for-all-x86_64-ABIs.patch116
-rw-r--r--gnu/gcc/patches/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch101
-rw-r--r--gnu/gcc/patches/50_all_cpu_indicator.patch37
-rw-r--r--gnu/gcc/patches/50_all_posix_memalign.patch31
7 files changed, 294 insertions, 2 deletions
diff --git a/gnu/gcc/BUILD b/gnu/gcc/BUILD
index fff1758a36..8bd5e07a5f 100755
--- a/gnu/gcc/BUILD
+++ b/gnu/gcc/BUILD
@@ -122,7 +122,6 @@ OPTS="$GCC_MULTILIB $OPTS" &&
case "$HOST" in
*-musl)
OPTS="--disable-multilib $OPTS" &&
- OPTS="--disable-libssp $OPTS" &&
OPTS="--disable-libmpx $OPTS" &&
OPTS="--disable-libmudflap $OPTS" &&
OPTS="--disable-libsanitizer $OPTS" &&
diff --git a/gnu/gcc/HISTORY b/gnu/gcc/HISTORY
index 0dc4968d15..4264981ed7 100644
--- a/gnu/gcc/HISTORY
+++ b/gnu/gcc/HISTORY
@@ -1,3 +1,10 @@
+2022-06-02 Ismael Luceno <ismael@sourcemage.org>
+ * BUILD, PRE_BUILD,
+ 0001-musl-always-use--lib--directory-for-all-x86_64-ABIs.patch,
+ 0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch,
+ 50_all_cpu_indicator.patch, 50_all_posix_memalign.patch:
+ fixed build against musl
+
2022-05-30 Ismael Luceno <ismael@sourcemage.org>
* 0003-fix-header-generation-for-libgo.patch,
0001-Do-not-attempt-to-use-mallinfo2.patch,
diff --git a/gnu/gcc/PRE_BUILD b/gnu/gcc/PRE_BUILD
index d09ea99de0..1f89668fe4 100755
--- a/gnu/gcc/PRE_BUILD
+++ b/gnu/gcc/PRE_BUILD
@@ -31,12 +31,13 @@ fi &&
cd ${SOURCE_DIRECTORY} &&
+apply_patch_dir patches &&
+
# Drop .la files like everyone else.
find . -name Makefile.in \
| xargs sed -i 's,^\(LIBTOOL[[:space:]]*=[[:space:]]*\),\1'"$GRIMOIRE"'/libtool-nola ,' &&
mk_source_dir $SOURCE_DIRECTORY.bld &&
-cd $SOURCE_DIRECTORY &&
sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in &&
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
diff --git a/gnu/gcc/patches/0001-musl-always-use--lib--directory-for-all-x86_64-ABIs.patch b/gnu/gcc/patches/0001-musl-always-use--lib--directory-for-all-x86_64-ABIs.patch
new file mode 100644
index 0000000000..80fa28c51e
--- /dev/null
+++ b/gnu/gcc/patches/0001-musl-always-use--lib--directory-for-all-x86_64-ABIs.patch
@@ -0,0 +1,116 @@
+From f313773d9087298a3f0ab45602791946debff8b7 Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Mon, 05 Jul 2021 18:15:44 +0000
+Subject: [PATCH] musl: always use 'lib' directory for all x86_64 ABIs [PR90077]
+Message-ID: <20210705181544.1519647-1-slyfox@gentoo.org>
+
+From: Sergei Trofimovich <siarheit@google.com>
+
+musl library intentionally does not support glibc-style multilib layout
+and usually assumes --libdir=lib (Gentoo and Alpine Linux both use it).
+
+Before the change --disable-multilib x86_64-gentoo-linux-musl returned:
+
+ $ gcc -print-multi-os-directory
+ ../lib64
+ $ gcc -print-multi-os-directory -m32
+ ../lib32
+ $ gcc -print-multi-os-directory -mx32
+ ../libx32
+
+After the change the layout is always the same:
+
+ $ gcc -print-multi-os-directory
+ ../lib
+ $ gcc -print-multi-os-directory -m32
+ ../lib
+ $ gcc -print-multi-os-directory -mx32
+ ../lib
+
+The discrepancy was noticed in meson build system which uses
+-print-multi-os-directory to find out target directory.
+
+Debian's multi-arch setup should not change.
+
+ PR target/90077
+
+gcc/ChangeLog
+
+ * gcc/config.gcc: Specal case musl to t-linux64-musl.
+
+ * gcc/config/i386/t-linux64-musl: New file based on t-linux64
+ that pins MULTILIB_OSDIRNAMES to lib.
+
+Origin: Gentoo
+Upstream-Status: Submitted [https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574482.html]
+Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
+---
+ gcc/config.gcc | 10 ++++++++--
+ gcc/config/i386/t-linux64-musl | 28 ++++++++++++++++++++++++++++
+ 2 files changed, 36 insertions(+), 2 deletions(-)
+ create mode 100644 gcc/config/i386/t-linux64-musl
+
+diff --git a/gcc/config.gcc b/gcc/config.gcc
+index 0230bb88861..a87a59c9403 100644
+--- a/gcc/config.gcc
++++ b/gcc/config.gcc
+@@ -1923,7 +1923,10 @@ i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-gnu* | i[34567]8
+ if test x$enable_targets = xall; then
+ tm_file="${tm_file} i386/x86-64.h i386/gnu-user-common.h i386/gnu-user64.h i386/linux-common.h i386/linux64.h"
+ tm_defines="${tm_defines} TARGET_BI_ARCH=1"
+- tmake_file="${tmake_file} i386/t-linux64"
++ case $target in
++ *-*-*musl*) tmake_file="${tmake_file} i386/t-linux64-musl";;
++ *) tmake_file="${tmake_file} i386/t-linux64";;
++ esac
+ x86_multilibs="${with_multilib_list}"
+ if test "$x86_multilibs" = "default"; then
+ x86_multilibs="m64,m32"
+@@ -1983,7 +1986,10 @@ x86_64-*-linux* | x86_64-*-kfreebsd*-gnu)
+ tm_file="${tm_file} kfreebsd-gnu.h i386/kfreebsd-gnu64.h"
+ ;;
+ esac
+- tmake_file="${tmake_file} i386/t-linux64"
++ case $target in
++ *-*-*musl*) tmake_file="${tmake_file} i386/t-linux64-musl";;
++ *) tmake_file="${tmake_file} i386/t-linux64";;
++ esac
+ x86_multilibs="${with_multilib_list}"
+ if test "$x86_multilibs" = "default"; then
+ case ${with_abi} in
+diff --git a/gcc/config/i386/t-linux64-musl b/gcc/config/i386/t-linux64-musl
+new file mode 100644
+index 00000000000..58e23c3c7dc
+--- /dev/null
++++ b/gcc/config/i386/t-linux64-musl
+@@ -0,0 +1,28 @@
++# Copyright (C) 2002-2021 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3, or (at your option)
++# any later version.
++#
++# GCC is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3. If not see
++# &lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.
++
++# musl explicitly does not support lib/lib32/lib64 layouts and always
++# uses lib layout. On debian full arch suffix is used. Thus we populate
++# all the m32/m64/mx32 with the same lib and apply multiarch suffix.
++
++comma=,
++MULTILIB_OPTIONS = $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
++MULTILIB_DIRNAMES = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
++MULTILIB_OSDIRNAMES = m64=../lib$(call if_multiarch,:x86_64-linux-gnu)
++MULTILIB_OSDIRNAMES+= m32=../lib$(call if_multiarch,:i386-linux-gnu)
++MULTILIB_OSDIRNAMES+= mx32=../lib$(call if_multiarch,:x86_64-linux-gnux32)
+--
+2.32.0
diff --git a/gnu/gcc/patches/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch b/gnu/gcc/patches/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch
new file mode 100644
index 0000000000..83a62f2888
--- /dev/null
+++ b/gnu/gcc/patches/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch
@@ -0,0 +1,101 @@
+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
+
+Origin: Alpine Linux
+Ref: https://git.alpinelinux.org/aports/plain/main/gcc/0042-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch
+Ref: https://bugs.gentoo.org/828580
+Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104799
+Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
+
+---
+ gcc/jit/jit-playback.cc | 4 ++--
+ gcc/jit/jit-recording.cc | 4 ++--
+ gcc/jit/libgccjit.cc | 3 ++-
+ libcc1/libcc1plugin.cc | 1 +
+ libcc1/libcp1plugin.cc | 1 +
+ 5 files changed, 8 insertions(+), 5 deletions(-)
+
+--- a/gcc/jit/jit-playback.cc
++++ b/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"
+--- a/gcc/jit/jit-recording.cc
++++ b/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"
+--- a/gcc/jit/libgccjit.cc
++++ b/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"
+--- a/libcc1/libcc1plugin.cc
++++ b/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
+--- a/libcc1/libcp1plugin.cc
++++ b/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
+
diff --git a/gnu/gcc/patches/50_all_cpu_indicator.patch b/gnu/gcc/patches/50_all_cpu_indicator.patch
new file mode 100644
index 0000000000..ca0876ecdf
--- /dev/null
+++ b/gnu/gcc/patches/50_all_cpu_indicator.patch
@@ -0,0 +1,37 @@
+From d16a8ceb1c3c8a7ec381090b4c316ff4c55661c0 Mon Sep 17 00:00:00 2001
+From:
+Date: Thu, 7 May 2020 21:14:11 -0500
+Subject: [PATCH] convert "__cpu_indicator_init" to
+ "__cpu_indicator_init_local"
+
+Origin: Gentoo
+
+--- a/gcc/config/i386/i386-expand.cc
++++ b/gcc/config/i386/i386-expand.cc
+@@ -12338,10 +12338,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
+ {
+ case IX86_BUILTIN_CPU_INIT:
+ {
+- /* Make it call __cpu_indicator_init in libgcc. */
++ /* Make it call __cpu_indicator_init_local in libgcc. */
+ tree call_expr, fndecl, type;
+ type = build_function_type_list (integer_type_node, NULL_TREE);
+- fndecl = build_fn_decl ("__cpu_indicator_init", type);
++ fndecl = build_fn_decl ("__cpu_indicator_init_local", type);
+ call_expr = build_call_expr (fndecl, 0);
+ return expand_expr (call_expr, target, mode, EXPAND_NORMAL);
+ }
+
+--- a/libgcc/config/i386/cpuinfo.c
++++ b/libgcc/config/i386/cpuinfo.c
+@@ -508,7 +508,7 @@ __cpu_indicator_init (void)
+ return 0;
+ }
+
+-#if defined SHARED && defined USE_ELF_SYMVER
+-__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0");
+-__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0");
++#ifndef SHARED
++int __cpu_indicator_init_local (void)
++ __attribute__ ((weak, alias ("__cpu_indicator_init")));
+ #endif
diff --git a/gnu/gcc/patches/50_all_posix_memalign.patch b/gnu/gcc/patches/50_all_posix_memalign.patch
new file mode 100644
index 0000000000..d974b56666
--- /dev/null
+++ b/gnu/gcc/patches/50_all_posix_memalign.patch
@@ -0,0 +1,31 @@
+Origin: Gentoo
+
+diff -Naur gcc-7.1.0.orig/gcc/config/i386/pmm_malloc.h gcc-7.1.0/gcc/config/i386/pmm_malloc.h
+--- gcc-7.1.0.orig/gcc/config/i386/pmm_malloc.h 2017-01-01 04:07:43.000000000 -0800
++++ gcc-7.1.0/gcc/config/i386/pmm_malloc.h 2017-05-07 11:35:22.878398460 -0700
+@@ -27,12 +27,13 @@
+ #include <stdlib.h>
+
+ /* We can't depend on <stdlib.h> since the prototype of posix_memalign
+- may not be visible. */
++ may not be visible and we can't pollute the namespace either. */
+ #ifndef __cplusplus
+-extern int posix_memalign (void **, size_t, size_t);
++extern int __gcc_posix_memalign (void **, size_t, size_t)
+ #else
+-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
++extern "C" int __gcc_posix_memalign (void **, size_t, size_t) throw ()
+ #endif
++__asm__("posix_memalign");
+
+ static __inline void *
+ _mm_malloc (size_t __size, size_t __alignment)
+@@ -42,7 +43,7 @@
+ return malloc (__size);
+ if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4))
+ __alignment = sizeof (void *);
+- if (posix_memalign (&__ptr, __alignment, __size) == 0)
++ if (__gcc_posix_memalign (&__ptr, __alignment, __size) == 0)
+ return __ptr;
+ else
+ return NULL;