Skip to content

Commit

Permalink
musl-libc: backport gcc-6 musl support, add gdb and strace patches
Browse files Browse the repository at this point in the history
This gets gcc and friends working with musl-libc.
GDB and Strace patches come from openwrt.

Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
  • Loading branch information
bhundven committed Oct 22, 2015
1 parent f34d1a9 commit c7b9a9b
Show file tree
Hide file tree
Showing 12 changed files with 906 additions and 0 deletions.
65 changes: 65 additions & 0 deletions patches/gcc/5.2.0/100-libitm-fixes-for-musl-support.patch
@@ -0,0 +1,65 @@
From: ktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 22 Apr 2015 14:11:25 +0000 (+0000)
Subject: libitm fixes for musl support
X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=e53a4d49c3d03ab8eaddb073cf972c1c46d75338

libitm fixes for musl support

On behalf of Szabolcs.Nagy@arm.com

2015-04-22 Gregor Richards <gregor.richards@uwaterloo.ca>

* config/arm/hwcap.cc: Use fcntl.h instead of sys/fcntl.h.
* config/linux/x86/tls.h: Only use __GLIBC_PREREQ if defined.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222325 138bc75d-0d04-0410-961f-82ee72b054a4
---

diff --git a/libitm/config/arm/hwcap.cc b/libitm/config/arm/hwcap.cc
index a1c2cfd..ea8f023 100644
--- a/libitm/config/arm/hwcap.cc
+++ b/libitm/config/arm/hwcap.cc
@@ -40,7 +40,7 @@ int GTM_hwcap HIDDEN = 0

#ifdef __linux__
#include <unistd.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
#include <elf.h>

static void __attribute__((constructor))
diff --git a/libitm/config/linux/x86/tls.h b/libitm/config/linux/x86/tls.h
index e731ab7..54ad8b6 100644
--- a/libitm/config/linux/x86/tls.h
+++ b/libitm/config/linux/x86/tls.h
@@ -25,16 +25,19 @@
#ifndef LIBITM_X86_TLS_H
#define LIBITM_X86_TLS_H 1

-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
+#if defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 10)
/* Use slots in the TCB head rather than __thread lookups.
GLIBC has reserved words 10 through 13 for TM. */
#define HAVE_ARCH_GTM_THREAD 1
#define HAVE_ARCH_GTM_THREAD_DISP 1
#endif
+#endif

#include "config/generic/tls.h"

-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
+#if defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 10)
namespace GTM HIDDEN {

#ifdef __x86_64__
@@ -101,5 +104,6 @@ static inline void set_abi_disp(struct abi_dispatch *x)

} // namespace GTM
#endif /* >= GLIBC 2.10 */
+#endif

#endif // LIBITM_X86_TLS_H
32 changes: 32 additions & 0 deletions patches/gcc/5.2.0/101-fixincludes-update-for-musl-support.patch
@@ -0,0 +1,32 @@
From: ktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 22 Apr 2015 14:18:16 +0000 (+0000)
Subject: fixincludes update for musl support
X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=2dc727de2e87c2756a514cbb43cea23c99deaa3d

fixincludes update for musl support

On behalf of Szabolcs.Nagy@arm.com

2015-04-22 Gregor Richards <gregor.richards@uwaterloo.ca>

* mkfixinc.sh: Add *-musl* with no fixes.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222327 138bc75d-0d04-0410-961f-82ee72b054a4
---

diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
index 6653fed..0d96c8c 100755
--- a/fixincludes/mkfixinc.sh
+++ b/fixincludes/mkfixinc.sh
@@ -19,7 +19,8 @@ case $machine in
powerpc-*-eabi* | \
powerpc-*-rtems* | \
powerpcle-*-eabisim* | \
- powerpcle-*-eabi* )
+ powerpcle-*-eabi* | \
+ *-musl* )
# IF there is no include fixing,
# THEN create a no-op fixer and exit
(echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
36 changes: 36 additions & 0 deletions patches/gcc/5.2.0/102-unwind-fix-for-musl.patch
@@ -0,0 +1,36 @@
From: ktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 22 Apr 2015 14:20:01 +0000 (+0000)
Subject: unwind fix for musl
X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=a2e31d0681d8a47389b8a3552622fbd9827bcef4

unwind fix for musl

On behalf of szabolcs.nagy@arm.com

2015-04-22 Gregor Richards <gregor.richards@uwaterloo.ca>
Szabolcs Nagy <szabolcs.nagy@arm.com>

* unwind-dw2-fde-dip.c (USE_PT_GNU_EH_FRAME): Define it on
Linux if target provides dl_iterate_phdr.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222328 138bc75d-0d04-0410-961f-82ee72b054a4
---

diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
index e1e566b..137dced 100644
--- a/libgcc/unwind-dw2-fde-dip.c
+++ b/libgcc/unwind-dw2-fde-dip.c
@@ -59,6 +59,12 @@

#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
&& defined(TARGET_DL_ITERATE_PHDR) \
+ && defined(__linux__)
+# define USE_PT_GNU_EH_FRAME
+#endif
+
+#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+ && defined(TARGET_DL_ITERATE_PHDR) \
&& (defined(__DragonFly__) || defined(__FreeBSD__))
# define ElfW __ElfN
# define USE_PT_GNU_EH_FRAME
@@ -0,0 +1,80 @@
From: ktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 22 Apr 2015 14:24:11 +0000 (+0000)
Subject: libstdc++, libgfortran gthr workaround for musl
X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=1e5f711c11cb80ce609db9e9c1d8b2da0f7b5b61

libstdc++, libgfortran gthr workaround for musl

On behalf of szabolcs.nagy@arm.com

[libstdc++-v3/]
2015-04-22 Szabolcs Nagy <szabolcs.nagy@arm.com>

* config/os/generic/os_defines.h (_GLIBCXX_GTHREAD_USE_WEAK): Define.
* configure.host (os_include_dir): Set to "os/generic" for linux-musl*.

[libgfortran/]
2015-04-22 Szabolcs Nagy <szabolcs.nagy@arm.com>

* acinclude.m4 (GTHREAD_USE_WEAK): Define as 0 for *-*-musl*.
* configure: Regenerate.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222329 138bc75d-0d04-0410-961f-82ee72b054a4
---

diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
index ba890f9..30b8b1a6 100644
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -100,7 +100,7 @@ void foo (void);
[Define to 1 if the target supports #pragma weak])
fi
case "$host" in
- *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
+ *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
AC_DEFINE(GTHREAD_USE_WEAK, 0,
[Define to 0 if the target shouldn't use #pragma weak])
;;
diff --git a/libgfortran/configure b/libgfortran/configure
index e1592f7..07542e1 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -26447,7 +26447,7 @@ $as_echo "#define SUPPORTS_WEAK 1" >>confdefs.h

fi
case "$host" in
- *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
+ *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )

$as_echo "#define GTHREAD_USE_WEAK 0" >>confdefs.h

diff --git a/libstdc++-v3/config/os/generic/os_defines.h b/libstdc++-v3/config/os/generic/os_defines.h
index 45bf52a..103ec0e 100644
--- a/libstdc++-v3/config/os/generic/os_defines.h
+++ b/libstdc++-v3/config/os/generic/os_defines.h
@@ -33,4 +33,9 @@
// System-specific #define, typedefs, corrections, etc, go here. This
// file will come before all others.

+// Disable the weak reference logic in gthr.h for os/generic because it
+// is broken on every platform unless there is implementation specific
+// workaround in gthr-posix.h and at link-time for static linking.
+#define _GLIBCXX_GTHREAD_USE_WEAK 0
+
#endif
diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
index 82ddc52..a349ce3 100644
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -271,6 +271,9 @@ case "${host_os}" in
freebsd*)
os_include_dir="os/bsd/freebsd"
;;
+ linux-musl*)
+ os_include_dir="os/generic"
+ ;;
gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
if [ "$uclibc" = "yes" ]; then
os_include_dir="os/uclibc"

0 comments on commit c7b9a9b

Please sign in to comment.