Skip to content

Commit

Permalink
macOS 15 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBrunner committed Oct 24, 2024
1 parent aaf91e9 commit 5433a61
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 136 deletions.
8 changes: 4 additions & 4 deletions Makefile.all.am
Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,27 @@ AM_CCASFLAGS_ARM64_FREEBSD = @FLAG_M64@ -g

AM_FLAG_M3264_X86_DARWIN = -arch i386
AM_CFLAGS_X86_DARWIN = $(WERROR) $(AM_FLAG_M3264_X86_DARWIN) $(AM_CFLAGS_BASE) \
-I@XCODE_INC_DIR@ \
-I@SDK_INC_DIR@ \
@CLANG_OS_MIN_VERS_ARG@ \
-fno-pic -fno-PIC
AM_CFLAGS_PSO_X86_DARWIN = $(AM_CFLAGS_X86_DARWIN) $(AM_CFLAGS_PSO_BASE)
AM_CCASFLAGS_X86_DARWIN = $(AM_FLAG_M3264_X86_DARWIN) -g

AM_FLAG_M3264_AMD64_DARWIN = -arch x86_64
AM_CFLAGS_AMD64_DARWIN = $(WERROR) $(AM_FLAG_M3264_AMD64_DARWIN) $(AM_CFLAGS_BASE) \
-I@XCODE_INC_DIR@ \
-I@SDK_INC_DIR@ \
@CLANG_OS_MIN_VERS_ARG@
AM_CFLAGS_PSO_AMD64_DARWIN = $(AM_CFLAGS_AMD64_DARWIN) $(AM_CFLAGS_PSO_BASE)
AM_CCASFLAGS_AMD64_DARWIN = $(AM_FLAG_M3264_AMD64_DARWIN) -g \
@CLANG_OS_MIN_VERS_ARG@

AM_FLAG_M3264_ARM64_DARWIN = -arch arm64
AM_CFLAGS_ARM64_DARWIN = $(WERROR) $(AM_FLAG_M3264_ARM64_DARWIN) $(AM_CFLAGS_BASE) \
-I@XCODE_INC_DIR@ @CLANG_OS_MIN_VERS_ARG@
-I@SDK_INC_DIR@ @CLANG_OS_MIN_VERS_ARG@
# Repeated instead of using $(AM_CFLAGS_ARM64_DARWIN) because we need to use
# a different arch for preloads (arm64e)
AM_CFLAGS_PSO_ARM64_DARWIN = $(WERROR) $(AM_FLAG_M3264_ARM64_DARWIN)e $(AM_CFLAGS_BASE) \
-I@XCODE_INC_DIR@ @CLANG_OS_MIN_VERS_ARG@ \
-I@SDK_INC_DIR@ @CLANG_OS_MIN_VERS_ARG@ \
$(AM_CFLAGS_PSO_BASE)
AM_CCASFLAGS_ARM64_DARWIN = $(AM_FLAG_M3264_ARM64_DARWIN) -g \
@CLANG_OS_MIN_VERS_ARG@
Expand Down
67 changes: 33 additions & 34 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -632,23 +632,22 @@ case "${host_os}" in
AC_ADD_DARWIN_VERS([DARWIN_12_00], 120000, [DARWIN_VERS value for macOS 12.0 / iOS 15])
AC_ADD_DARWIN_VERS([DARWIN_13_00], 130000, [DARWIN_VERS value for macOS 13.0 / iOS 16])
AC_ADD_DARWIN_VERS([DARWIN_14_00], 140000, [DARWIN_VERS value for macOS 14.0 / iOS 17])
AC_ADD_DARWIN_VERS([DARWIN_15_00], 140000, [DARWIN_VERS value for macOS 15.0 / iOS 18])

AC_DEFINE([XCODE_10_XX], 101200, [XCODE_VERS value for Xcode earlier than 10.13 (iOS 11)])
AC_DEFINE([XCODE_10_13], 101300, [XCODE_VERS value for Xcode 10.13 (iOS 11)])
AC_DEFINE([XCODE_10_14], 101400, [XCODE_VERS value for Xcode 10.14 (iOS 12)])
AC_DEFINE([XCODE_10_14_6], 101406, [XCODE_VERS value for Xcode 10.14.6 (iOS 12)])
AC_DEFINE([XCODE_10_15], 101500, [XCODE_VERS value for Xcode 10.15 (iOS 13)])
AC_DEFINE([XCODE_11_0], 110000, [XCODE_VERS value for Xcode 11.0 (iOS 14)])
AC_DEFINE([XCODE_12_0], 120000, [XCODE_VERS value for Xcode 12.0 (iOS 15)])
AC_DEFINE([XCODE_13_0], 130000, [XCODE_VERS value for Xcode 13.0 (iOS 16)])
AC_DEFINE([XCODE_14_0], 140000, [XCODE_VERS value for Xcode 14.0 (iOS 17)])
AC_DEFINE([XCODE_15_0], 140000, [XCODE_VERS value for Xcode 15.0 (iOS 18)])
AC_ADD_DARWIN_VERS([DARWIN_15_00], 150000, [DARWIN_VERS value for macOS 15.0 / iOS 18])

AC_DEFINE([SDK_10_XX], 101200, [SDK_VERS value for Xcode SDK earlier than macOS 10.13 / iOS 11])
AC_DEFINE([SDK_10_13], 101300, [SDK_VERS value for Xcode SDK macOS 10.13 / iOS 11])
AC_DEFINE([SDK_10_14], 101400, [SDK_VERS value for Xcode SDK macOS 10.14 / iOS 12])
AC_DEFINE([SDK_10_14_6], 101406, [SDK_VERS value for Xcode SDK macOS 10.14.6 / iOS 12])
AC_DEFINE([SDK_10_15], 101500, [SDK_VERS value for Xcode SDK macOS 10.15 / iOS 13])
AC_DEFINE([SDK_11_0], 110000, [SDK_VERS value for Xcode SDK macOS 11.0 / iOS 14])
AC_DEFINE([SDK_12_0], 120000, [SDK_VERS value for Xcode SDK macOS 12.0 / iOS 15])
AC_DEFINE([SDK_13_0], 130000, [SDK_VERS value for Xcode SDK macOS 13.0 / iOS 16])
AC_DEFINE([SDK_14_0], 140000, [SDK_VERS value for Xcode SDK macOS 14.0 / iOS 17])
AC_DEFINE([SDK_15_0], 150000, [SDK_VERS value for Xcode SDK macOS 15.0 / iOS 18])

# Substitute the Xcode include path detected earlier
AC_SUBST(XCODE_INC_DIR, [$xcodedir_inc])
AC_SUBST(XCODE_LIB_DIR, [$xcodedir_lib])

AC_SUBST(SDK_INC_DIR, [$xcodedir_inc])
AC_SUBST(SDK_LIB_DIR, [$xcodedir_lib])

AC_MSG_CHECKING([for the Darwin platform])
case "${darwin_platform}" in
Expand Down Expand Up @@ -823,53 +822,53 @@ case "${host_os}" in
AC_SUBST(LD_OS_MIN_VERS_ARG, [$ld_os_min_vers_arg])

AC_MSG_CHECKING([for the Xcode SDK version])
xcodeversion="legacy"
sdkversion="legacy"
if test "x$XCRUN" != "xno"; then
xcodeversion=`xcrun --sdk $darwin_sdk --show-sdk-version`
sdkversion=`xcrun --sdk $darwin_sdk --show-sdk-version`
fi
case "${darwin_platform}-${xcodeversion}" in
case "${darwin_platform}-${sdkversion}" in
macosx-10.13*|iphoneos-11.*)
AC_DEFINE([XCODE_VERS], XCODE_10_13, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_13, [SDK version])
;;
macosx-10.14.6)
AC_DEFINE([XCODE_VERS], XCODE_10_14_6, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_14_6, [SDK version])
;;
macosx-10.14*|iphoneos-12.*)
AC_DEFINE([XCODE_VERS], XCODE_10_14, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_14, [SDK version])
;;
macosx-10.15*|iphoneos-13.*)
AC_DEFINE([XCODE_VERS], XCODE_10_15, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_15, [SDK version])
;;
macosx-11.*|iphoneos-14.*)
AC_DEFINE([XCODE_VERS], XCODE_11_0, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_11_0, [SDK version])
;;
macosx-12.*|iphoneos-15.*)
AC_DEFINE([XCODE_VERS], XCODE_12_0, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_12_0, [SDK version])
;;
macosx-13.*|iphoneos-16.*)
AC_DEFINE([XCODE_VERS], XCODE_13_0, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_13_0, [SDK version])
;;
macosx-14.*|iphoneos-17.*)
AC_DEFINE([XCODE_VERS], XCODE_14_0, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_14_0, [SDK version])
;;
macosx-15.*|iphoneos-18.*)
AC_DEFINE([XCODE_VERS], XCODE_15_0, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_15_0, [SDK version])
;;
legacy)
AC_DEFINE([XCODE_VERS], XCODE_10_XX, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_XX, [SDK version])
;;
macosx-10.5*|macosx-10.6*|macosx-10.7*|macosx-10.8*|macosx-10.9*|macosx-10.10*|macosx-10.11*|macosx-10.12*)
AC_DEFINE([XCODE_VERS], XCODE_10_XX, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_XX, [SDK version])
;;
iphoneos-4.*|iphoneos-5.*|iphoneos-6.*|iphoneos-7.*|iphoneos-8.*|iphoneos-9.*|iphoneos-10.*)
AC_DEFINE([XCODE_VERS], XCODE_10_XX, [Xcode version])
AC_DEFINE([SDK_VERS], SDK_10_XX, [SDK version])
;;
*)
AC_MSG_RESULT([unsupported (${xcodeversion})])
AC_MSG_RESULT([unsupported (${sdkversion})])
AC_MSG_ERROR([Valgrind works on Darwin 10.x-24.x (Mac OS X 10.6-11 and macOS 10.12-15.0 and iOS 4-18)])
;;
esac
AC_MSG_RESULT([${xcodeversion}])
AC_MSG_RESULT([${sdkversion}])
;;

solaris2.11*)
Expand Down Expand Up @@ -940,10 +939,10 @@ case "$ARCH_MAX-$VGCONF_OS" in
# iOS 7-10 and macOS 10.5-10.15 support both
# iOS 11+ and macOS 10.15 are 64bit only
vg_cv_only32bit="no"
if test x$xcodeversion = x10.14.6 -o $XCODE_VERS -ge $XCODE_10_15 ; then
if test x$sdkversion = x10.14.6 -o $SDK_VERS -ge $SDK_10_15 ; then
vg_cv_only64bit="yes"
AC_MSG_RESULT([no])
elif test $darwin_platform = iphoneos -a $XCODE_VERS -ge $XCODE_10_13; then
elif test $darwin_platform = iphoneos -a $SDK_VERS -ge $SDK_10_13; then
vg_cv_only64bit="yes"
AC_MSG_RESULT([no])
else
Expand Down
38 changes: 19 additions & 19 deletions coregrind/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,25 @@ mach_hdrs =
mach_defs =
if VGCONF_OS_IS_DARWIN
mach_user_srcs += \
m_mach/mach_vmUser.c \
m_mach/taskUser.c \
m_mach/thread_actUser.c \
m_mach/vm_mapUser.c
m_mach/mach_vmUser.c \
m_mach/taskUser.c \
m_mach/thread_actUser.c \
m_mach/vm_mapUser.c
mach_server_srcs += \
m_mach/mach_vmServer.c \
m_mach/taskServer.c \
m_mach/thread_actServer.c \
m_mach/vm_mapServer.c
m_mach/mach_vmServer.c \
m_mach/taskServer.c \
m_mach/thread_actServer.c \
m_mach/vm_mapServer.c
mach_hdrs += \
m_mach/mach_vm.h \
m_mach/task.h \
m_mach/thread_act.h \
m_mach/vm_map.h
m_mach/mach_vm.h \
m_mach/task.h \
m_mach/thread_act.h \
m_mach/vm_map.h
mach_defs += \
@XCODE_INC_DIR@/mach/mach_vm.defs \
@XCODE_INC_DIR@/mach/task.defs \
@XCODE_INC_DIR@/mach/thread_act.defs \
@XCODE_INC_DIR@/mach/vm_map.defs
@SDK_INC_DIR@/mach/mach_vm.defs \
@SDK_INC_DIR@/mach/task.defs \
@SDK_INC_DIR@/mach/thread_act.defs \
@SDK_INC_DIR@/mach/vm_map.defs

if VGCONF_ARCHS_INCLUDE_ARM64
noinst_PROGRAMS += libmySystem.so libmydyld.so
Expand All @@ -179,7 +179,7 @@ libmySystem_so_CPPFLAGS = $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
libmySystem_so_CFLAGS = $(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
libmySystem_so_CCASFLAGS = $(AM_CCASFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
libmySystem_so_LINK = ./delayed-install-systemb.sh \
/usr/bin/ld -dylib @LD_OS_MIN_VERS_ARG@ -L@XCODE_LIB_DIR@ -lSystem -o libmySystem.so
/usr/bin/ld -dylib @LD_OS_MIN_VERS_ARG@ -L@SDK_LIB_DIR@ -lSystem -o libmySystem.so

libmydyld_so_SOURCES = m_mach/dummy_syslib.c m_mach/dummy_dylddata.S
libmydyld_so_CPPFLAGS = $(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
Expand All @@ -196,9 +196,9 @@ endif
$(abs_builddir)/m_mach:
mkdir -p $@
$(mach_user_srcs): $(mach_defs) $(abs_builddir)/m_mach
(cd m_mach && mig -I@XCODE_INC_DIR@ $(mach_defs))
(cd m_mach && mig -I@SDK_INC_DIR@ $(mach_defs))
$(mach_hdrs): $(mach_defs) $(mach_user_srcs) $(abs_builddir)/m_mach
(cd m_mach && mig -I@XCODE_INC_DIR@ $(mach_defs))
(cd m_mach && mig -I@SDK_INC_DIR@ $(mach_defs))

#----------------------------------------------------------------------------
# Headers
Expand Down
2 changes: 1 addition & 1 deletion coregrind/fixup_macho_loadcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void modify_macho_loadcmds ( HChar* filename,
fail("has __UNIXSTACK, but wrong ::vmaddr");
if (seg->vmsize != expected_stack_size)
fail("has __UNIXSTACK, but wrong ::vmsize");
#if XCODE_VERS >= XCODE_10_14_6
#if SDK_VERS >= SDK_10_14_6
if (seg->maxprot != 3)
fail("has __UNIXSTACK, but wrong ::maxprot (should be 3)");
#else
Expand Down
7 changes: 6 additions & 1 deletion coregrind/link_tool_exe_darwin.in
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ if ($archstr eq "arm64") {
$cmd = "$cmd -image_base $ala";
}

# Xcode 16 is completely borked and crashes when you use -segaddr so we rollback to
# the old linker in the meantime
if (@DARWIN_VERS@ >= 150000) {
$cmd = "$cmd -ld_classic";

# If we're building with clang (viz, the C compiler as specified
# by the 2nd arg ends in "clang"), we also need -new_linker. See
# https://bugs.kde.org/show_bug.cgi?id=295427
if ("$cc" =~ /clang$/) {
} elsif ("$cc" =~ /clang$/) {
$cmd = "$cmd -new_linker";
}

Expand Down
35 changes: 30 additions & 5 deletions coregrind/m_aspacemgr/aspacemgr-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -4116,6 +4116,15 @@ static void fill_segment(NSegment* seg) {
seg->fnIdx = ML_(am_allocate_segname)( name );
}

static Bool endswith(const HChar* str, const HChar* suffix) {
SizeT str_len = VG_(strlen)(str);
SizeT suffix_len = VG_(strlen)(suffix);
if (str_len < suffix_len) {
return False;
}
return VG_(strcmp)(str + str_len - suffix_len, suffix) == 0;
}

static UInt stats_machcalls = 0;

static void parse_procselfmaps (
Expand Down Expand Up @@ -4157,15 +4166,31 @@ static void parse_procselfmaps (
}
iter = addr + size;

// FIXME: not sure we should fill up anything here as it will added later anyway
ret = get_filename_for_region(pid, addr, name, sizeof(name), NULL);
if (!ret) {
ret = get_name_from_tag(info.user_tag, name, sizeof(name));
}

#if defined(VGA_arm64)
if (ret) {
if (endswith(name, "/libmySystem.so") || endswith(name, "/libmydyld.so")) {
// not only do we not want to track these, we want to unmmap them completely
// otherwise they clutter the address space and make macOS 15+ fail
// during client loading
kr = mach_vm_deallocate(mach_task_self(), addr, size);
if (kr) {
VG_(debugLog)(0, "aspacem", "failed to deallocate %#llx..%#llx: %s\n", addr, addr + size, name);
}
continue;
}
}
#endif

if (addr > last && record_gap) {
(*record_gap)(last, addr - last);
}
if (record_mapping) {
// FIXME: not sure we should fill up anything here as it will added later anyway
ret = get_filename_for_region(pid, addr, name, sizeof(name), NULL);
if (!ret) {
ret = get_name_from_tag(info.user_tag, name, sizeof(name));
}
(*record_mapping)(addr, size, mach2vki(info.protection),
0, info.user_tag, info.offset, ret ? name : NULL, False);
}
Expand Down
Loading

0 comments on commit 5433a61

Please sign in to comment.