Skip to content

Commit

Permalink
gcc14: Patches for Tiger
Browse files Browse the repository at this point in the history
Adds 2 patches to make gcc14 build on Tiger.

The patches correspond to the following upstream bugs:

1. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117834
2. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117857
  • Loading branch information
glebm authored and kencu committed Dec 9, 2024
1 parent 4a77429 commit 4e3a411
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lang/gcc14/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ if { ${os.platform} eq "darwin" } {
# This patch has been merged upstream in https://github.com/gcc-mirror/gcc/commit/1cfe4a4d0d4447b364815d5e5c889deb2e533669
# Remove it when upgrading gcc to a version that has it.
patchfiles-append darwin-ppc-fpu.patch

if { ${os.major} == 8 } {
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117834
patchfiles-append darwin8-define-PTHREAD_RWLOCK_INITIALIZER.patch

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117857
patchfiles-append darwin8-ttyname_r.patch
}
}

# Since GCC 7.4.0, during configure, it detects features supported by target-as.
Expand Down
33 changes: 33 additions & 0 deletions lang/gcc14/files/darwin8-define-PTHREAD_RWLOCK_INITIALIZER.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From c86f77d40e74cbbd6bc2bb4b2d8aaa30bac04f23 Mon Sep 17 00:00:00 2001
From: Gleb Mazovetskiy <[email protected]>
Date: Thu, 28 Nov 2024 16:00:06 +0000
Subject: [PATCH] define PTHREAD_RWLOCK_INITIALIZER

Per https://github.com/macports/macports-ports/pull/26655#issuecomment-2506351012

Remove this patch once
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117834 is resolved
---
libgcc/gthr-posix.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git libgcc/gthr-posix.h libgcc/gthr-posix.h
index 82e8f9ffcf6..f87283cb0e4 100644
--- libgcc/gthr-posix.h
+++ libgcc/gthr-posix.h
@@ -62,6 +62,12 @@ typedef struct timespec __gthread_time_t;
#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
#ifndef __cplusplus
+#ifndef PTHREAD_RWLOCK_INITIALIZER
+#ifndef _PTHREAD_RWLOCK_SIG_init
+#define _PTHREAD_RWLOCK_SIG_init 0x2DA8B3B4
+#endif
+#define PTHREAD_RWLOCK_INITIALIZER {_PTHREAD_RWLOCK_SIG_init, {0}}
+#endif
#define __GTHREAD_RWLOCK_INIT PTHREAD_RWLOCK_INITIALIZER
#endif
#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
--
2.43.0

62 changes: 62 additions & 0 deletions lang/gcc14/files/darwin8-ttyname_r.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From 7abb2866863471eb6252ebec67ac2de56abda0db Mon Sep 17 00:00:00 2001
From: Gleb Mazovetskiy <[email protected]>
Date: Sat, 30 Nov 2024 08:57:43 +0000
Subject: [PATCH] darwin8 ttyname_r patch

---
libgfortran/io/unix.c | 7 +++++++
.../sanitizer_common_interceptors.inc | 12 ++++++++++++
2 files changed, 19 insertions(+)

diff --git libgfortran/io/unix.c libgfortran/io/unix.c
index 16600c855f2..80d2fad7ef8 100644
--- libgfortran/io/unix.c
+++ libgfortran/io/unix.c
@@ -2094,7 +2094,14 @@ stream_ttyname (stream *s __attribute__ ((unused)),
size_t buflen __attribute__ ((unused)))
{
#ifdef HAVE_TTYNAME_R
+#if __DARWIN_UNIX03
return ttyname_r (((unix_stream *)s)->fd, buf, buflen);
+#else
+ char *p = ttyname_r (((unix_stream *)s)->fd, buf, buflen);
+ if (!p)
+ return errno;
+ return 0;
+#endif
#elif defined HAVE_TTYNAME
char *p;
size_t plen;
diff --git libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
index 607ecae6808..2d2fceedf79 100644
--- libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
+++ libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5036,6 +5036,7 @@ INTERCEPTOR(char *, ttyname, int fd) {
#endif

#if SANITIZER_INTERCEPT_TTYNAME_R
+#if __DARWIN_UNIX03
INTERCEPTOR(int, ttyname_r, int fd, char *name, SIZE_T namesize) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, ttyname_r, fd, name, namesize);
@@ -5044,6 +5045,17 @@ INTERCEPTOR(int, ttyname_r, int fd, char *name, SIZE_T namesize) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, internal_strlen(name) + 1);
return res;
}
+#else
+INTERCEPTOR(char*, ttyname_r, int fd, char *name, SIZE_T namesize) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, ttyname_r, fd, name, namesize);
+ char *res = REAL(ttyname_r)(fd, name, namesize);
+ if (res != nullptr)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, internal_strlen(name) + 1);
+ return res;
+}
+#endif
+
#define INIT_TTYNAME_R COMMON_INTERCEPT_FUNCTION(ttyname_r);
#else
#define INIT_TTYNAME_R
--
2.43.0

0 comments on commit 4e3a411

Please sign in to comment.