toolchain: gdb: fix build error with Xcode 16.3
authorGeorgi Valkov <[email protected]>
Mon, 14 Apr 2025 12:28:23 +0000 (15:28 +0300)
committerRobert Marko <[email protected]>
Thu, 12 Jun 2025 08:51:01 +0000 (10:51 +0200)
Xcode 16.3 defines TARGET_OS_MAC, it was not defined in prior versions.
zutil.h conditionally defines fdopen as NULL when this macro is defined,
resulting in the following build error:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:318:7: error: expected identifier or '('
  318 | FILE    *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
      |          ^
./zutil.h:147:33: note: expanded from macro 'fdopen'
  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */

In Xcode 16.2 and earlier, TARGET_OS_MAC was not defined so this entire
block was ignored, gcc and gdb used to compile and work fine.

This may have been used for compatibility with older versions of macOS,
but is no longer needed. By pure luck, the build worked fine for a long
time, because it did not properly detect macOS.
Fixed by removing the check for TARGET_OS_MAC.

Note that since Xcode 16.3, an entire set of TARGET_OS macros
are now defined, most of which are set to 0:
TARGET_OS_LINUX 0
TARGET_OS_MAC 1
TARGET_OS_OSX 1

Signed-off-by: Georgi Valkov <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/18467
(cherry picked from commit dfb8115d0cc00d40f2884d3119b44f3da69c997a)
Link: https://github.com/openwrt/openwrt/pull/19096
Signed-off-by: Robert Marko <[email protected]>
toolchain/gdb/Makefile
toolchain/gdb/patches/130-fix-build-error-with-Xcode-16.3.patch [new file with mode: 0644]

index ad0c843f75d7ecf551c778ebd2a8e8cd9a33705c..861876d54a29c8f419f19562ffbefb6b10b6fd82 100644 (file)
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=gdb
 PKG_VERSION:=15.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=@GNU/gdb
diff --git a/toolchain/gdb/patches/130-fix-build-error-with-Xcode-16.3.patch b/toolchain/gdb/patches/130-fix-build-error-with-Xcode-16.3.patch
new file mode 100644 (file)
index 0000000..4f76ed3
--- /dev/null
@@ -0,0 +1,52 @@
+From 0a084bb6c04e453183530c3e20727be1cc55ff9a Mon Sep 17 00:00:00 2001
+From: Georgi Valkov <[email protected]>
+Date: Mon, 14 Apr 2025 15:18:00 +0300
+Subject: [PATCH] zlib: fix build error with Xcode 16.3
+
+Xcode 16.3 defines TARGET_OS_MAC, it was not defined in prior versions.
+zutil.h conditionally defines fdopen as NULL when this macro is defined,
+resulting in the following build error:
+
+/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:318:7: error: expected identifier or '('
+  318 | FILE    *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
+      |          ^
+./zutil.h:147:33: note: expanded from macro 'fdopen'
+  147 | #        define fdopen(fd,mode) NULL /* No fdopen() */
+
+In Xcode 16.2 and earlier, TARGET_OS_MAC was not defined so this entire
+block was ignored, gcc and gdb used to compile and work fine.
+
+This may have been used for compatibility with older versions of macOS,
+but is no longer needed. By pure luck, the build worked fine for a long
+time, because it did not properly detect macOS.
+Fixed by removing the check for TARGET_OS_MAC.
+
+Note that since Xcode 16.3, an entire set of TARGET_OS macros
+are now defined, most of which are set to 0:
+TARGET_OS_LINUX 0
+TARGET_OS_MAC 1
+TARGET_OS_OSX 1
+
+[1] https://github.com/openwrt/openwrt/pull/18467
+
+Signed-off-by: Georgi Valkov <[email protected]>
+---
+ zlib/zutil.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/zlib/zutil.h b/zlib/zutil.h
+index d9a20ae1bf4..183e51b96b6 100644
+--- a/zlib/zutil.h
++++ b/zlib/zutil.h
+@@ -137,7 +137,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
+ #  endif
+ #endif
+-#if defined(MACOS) || defined(TARGET_OS_MAC)
++#if defined(MACOS)
+ #  define OS_CODE  7
+ #  ifndef Z_SOLO
+ #    if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+-- 
+2.49.0
+