From 3186893e69fa636fdecc0552a2dff008bd4654a1 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 19 Nov 2020 01:07:40 +0000 Subject: [PATCH] Libsystem-1292.50.1.tar.gz --- Libsystem.xcconfig | 9 +++- Libsystem.xcodeproj/project.pbxproj | 4 ++ i386.c | 66 +++++++++++++++++++++++++++++ init.c | 35 +++++++++++++-- optionallibs | 1 + optionallibs_i386 | 33 +++++++++++++++ requiredlibs | 1 + requiredlibs_i386 | 3 ++ xcodescripts/linker_arguments.sh | 12 ++++++ 9 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 i386.c create mode 100644 optionallibs_i386 create mode 100644 requiredlibs_i386 diff --git a/Libsystem.xcconfig b/Libsystem.xcconfig index c11431b..545b436 100644 --- a/Libsystem.xcconfig +++ b/Libsystem.xcconfig @@ -10,10 +10,13 @@ ASAN_IN_NORMAL_VARIANT_RC_1 = $(ASAN_IN_NORMAL_VARIANT_DK_$(DRIVERKIT)) ASAN_IN_NORMAL_VARIANT_RC_ = NO ASAN_IN_NORMAL_VARIANT = $(ASAN_IN_NORMAL_VARIANT_RC_$(RC_SUPPORT_ADDRESS_SANITIZATION)) +// Apple Internal Sanitizer dylib path +SANITIZER_DYLIB_DIR = /usr/appleinternal/lib/sanitizers + ASAN_CFLAGS_ = ASAN_CFLAGS_YES = -DCURRENT_VARIANT_asan=1 ASAN_LDFLAGS_ = -SHARED_ASAN_LDFLAGS = -L $(SDKROOT)/usr/local/lib/sanitizers -Xlinker -not_for_dyld_shared_cache -rpath /usr/local/lib/sanitizers/ +SHARED_ASAN_LDFLAGS = -L $(SDKROOT)$(SANITIZER_DYLIB_DIR) -Xlinker -not_for_dyld_shared_cache -rpath $(SANITIZER_DYLIB_DIR)/ ASAN_LDFLAGS_YES[sdk=macosx*] = $(SHARED_ASAN_LDFLAGS) -Xlinker -upward-lclang_rt.asan_osx_dynamic ASAN_LDFLAGS_YES[sdk=iphoneos*] = $(SHARED_ASAN_LDFLAGS) -Xlinker -upward-lclang_rt.asan_ios_dynamic ASAN_LDFLAGS_YES[sdk=watchos*] = $(SHARED_ASAN_LDFLAGS) -Xlinker -upward-lclang_rt.asan_watchos_dynamic @@ -75,6 +78,10 @@ PLIST_FILE_OUTPUT_FORMAT = binary PLIST_FILE_OUTPUT_FORMAT[sdk=macosx*] = xml EXCLUDED_SOURCE_FILE_NAMES[sdk=driverkit*] = Info.plist +EXCLUDED_SOURCE_FILE_NAMES = $(inherited) i386.c +INCLUDED_SOURCE_FILE_NAMES[sdk=macos*][arch=i386] = $(inherited) i386.c +EXCLUDED_SOURCE_FILE_NAMES[sdk=macosx*][arch=i386] = $(inherited) init.c CompatibilityHacks.c + // override presence of $(EXECUTABLE_VARIANT_SUFFIX) in the default EXECUTABLE_NAME rdar://26234727 DYLIB_INSTALL_NAME_EXECUTABLE_NAME = $(EXECUTABLE_PREFIX)$(PRODUCT_NAME)$(EXECUTABLE_SUFFIX) DYLIB_INSTALL_NAME_EXECUTABLE_PATH = $(DYLIB_INSTALL_NAME_EXECUTABLE_NAME) diff --git a/Libsystem.xcodeproj/project.pbxproj b/Libsystem.xcodeproj/project.pbxproj index bba1b8e..1ea3af3 100644 --- a/Libsystem.xcodeproj/project.pbxproj +++ b/Libsystem.xcodeproj/project.pbxproj @@ -73,6 +73,7 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 2B9D8B542402427100E7F338 /* i386.c in Sources */ = {isa = PBXBuildFile; fileRef = 2B9D8B53240239BD00E7F338 /* i386.c */; }; 923662F821276300001FB3E7 /* enable_asan_mode in Copy enable_asan_mode */ = {isa = PBXBuildFile; fileRef = 8C0BF1291F58E51D00706493 /* enable_asan_mode */; }; BA2BD900136D282200FF78C0 /* Info.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA5511B6136C9D780012B9B5 /* Info.plist */; }; BA2FABC5136DBF45004383E5 /* linker_arguments_changed.c in Sources */ = {isa = PBXBuildFile; fileRef = BA2FABC4136DBF45004383E5 /* linker_arguments_changed.c */; }; @@ -158,6 +159,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 2B9D8B53240239BD00E7F338 /* i386.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = i386.c; sourceTree = ""; }; 8C0BF1291F58E51D00706493 /* enable_asan_mode */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = enable_asan_mode; sourceTree = ""; }; 923662FC212B442C001FB3E7 /* create_asan_override_file.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = create_asan_override_file.sh; sourceTree = ""; }; BA2FABC4136DBF45004383E5 /* linker_arguments_changed.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = linker_arguments_changed.c; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -205,6 +207,7 @@ BA5511B6136C9D780012B9B5 /* Info.plist */, C9A43CAB15374DB200388D0C /* alloc_once_private.h */, BA5511B7136C9D780012B9B5 /* init.c */, + 2B9D8B53240239BD00E7F338 /* i386.c */, BA5511B9136C9D780012B9B5 /* optionallibs */, BA5511BA136C9D780012B9B5 /* requiredlibs */, E43B88B42245778F00215272 /* optionallibs_driverkit */, @@ -378,6 +381,7 @@ buildActionMask = 2147483647; files = ( BA5511C9136C9E4D0012B9B5 /* CompatibilityHacks.c in Sources */, + 2B9D8B542402427100E7F338 /* i386.c in Sources */, BA5511CA136C9E510012B9B5 /* init.c in Sources */, BA2FABC5136DBF45004383E5 /* linker_arguments_changed.c in Sources */, ); diff --git a/i386.c b/i386.c new file mode 100644 index 0000000..0fbd443 --- /dev/null +++ b/i386.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2007, 2008, 2011-2013 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ + +// This is the only C file compiled into Libsystem when building for i386. +// We use EXCLUDED_ and INCLUDED_SOURCE_FILES in the xcconfig to accomplish +// this. +// +// i386 is no longer a supported architecture for macOS. The kernel doesn’t run +// i386 macOS executables. However, we cannot completely remove the i386 +// slice from libSystem.B.dylib. In order to support the watchOS Simulator, +// macOS includes several libraries with i386 slices. The watchOS Simulator +// uses the i386 ISA with a different Mach-O platform and its own entire set +// of system libraries. Some of those libraries (including those from the clang/ +// llvm project) verify that the compiler works by compiling and linking a +// simple executable. That would fail if Libsystem lacked an i386 slice. +// So, we will preserve a vestigial i386 slice, but no executables can actually +// use it to run. +// rdar://problem/59703537 + +#include + +#if !defined(__i386__) || !defined(TARGET_OS_OSX) || (TARGET_OS_OSX == 0) +#error "This file should not be built for this environment" +#endif // !defined(__i386__) || !defined(TARGET_OS_OSX) || (TARGET_OS_OSX == 0) + +#include + +struct ProgramVars; + +__attribute__((constructor)) +static void +libSystem_initializer(int argc __attribute__((unused)), + const char* argv[] __attribute__((unused)), + const char* envp[] __attribute__((unused)), + const char* apple[] __attribute__((unused)), + const struct ProgramVars* vars __attribute__((unused))) +{ + abort_with_reason(OS_REASON_LIBSYSTEM, 386, + "i386 is not supported on macOS", + OS_REASON_FLAG_CONSISTENT_FAILURE); +} diff --git a/init.c b/init.c index 9d604e0..cdc5130 100644 --- a/init.c +++ b/init.c @@ -225,6 +225,7 @@ libSystem_initializer(int argc, _libSystem_ktrace_init_func(LIBC); // TODO: Move __malloc_init before __libc_init after breaking malloc's upward link to Libc + // Note that __malloc_init() will also initialize ASAN when it is present __malloc_init(apple); _libSystem_ktrace_init_func(MALLOC); @@ -234,9 +235,6 @@ libSystem_initializer(int argc, _libSystem_ktrace_init_func(KEYMGR); #endif - // No ASan interceptors are invoked before this point. ASan is normally initialized via the malloc interceptor: - // _dyld_initializer() -> tlv_load_notification -> wrap_malloc -> ASanInitInternal - _dyld_initializer(); _libSystem_ktrace_init_func(DYLD); @@ -285,6 +283,37 @@ libSystem_initializer(int argc, } #endif +#if TARGET_OS_OSX && !defined(__i386__) + bool enable_system_version_compat = false; + bool enable_ios_version_compat = false; + char *system_version_compat_override = getenv("SYSTEM_VERSION_COMPAT"); + if (system_version_compat_override != NULL) { + long override = strtol(system_version_compat_override, NULL, 0); + if (override == 1) { + enable_system_version_compat = true; + } else if (override == 2) { + enable_ios_version_compat = true; + } + } else if (dyld_get_active_platform() == PLATFORM_MACCATALYST) { + if (!dyld_program_sdk_at_least(dyld_platform_version_iOS_14_0)) { + enable_system_version_compat = true; + } + } else if (dyld_get_active_platform() == PLATFORM_IOS) { + enable_ios_version_compat = true; + } else if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_10_16)) { + enable_system_version_compat = true; + } + + if (enable_system_version_compat || enable_ios_version_compat) { + struct _libkernel_late_init_config config = { + .version = 2, + .enable_system_version_compat = enable_system_version_compat, + .enable_ios_version_compat = enable_ios_version_compat, + }; + __libkernel_init_late(&config); + } +#endif // TARGET_OS_OSX && !defined(__i386__) + _libSystem_ktrace0(ARIADNE_LIFECYCLE_libsystem_init | DBG_FUNC_END); /* diff --git a/optionallibs b/optionallibs index 40cd8fc..60daab2 100644 --- a/optionallibs +++ b/optionallibs @@ -4,5 +4,6 @@ quarantine system_containermanager system_featureflags system_networkextension +system_product_info_filter system_secinit system_symptoms diff --git a/optionallibs_i386 b/optionallibs_i386 new file mode 100644 index 0000000..3a1a491 --- /dev/null +++ b/optionallibs_i386 @@ -0,0 +1,33 @@ +cache +commonCrypto +compiler_rt +copyfile +corecrypto +dispatch +dyld +keymgr +launch +macho +quarantine +removefile +system_asl +system_blocks +system_c +system_configuration +system_containermanager +system_coreservices +system_darwin +system_dnssd +system_featureflags +system_info +system_m +system_malloc +system_networkextension +system_notify +system_product_info_filter +system_sandbox +system_secinit +system_symptoms +system_trace +unwind +xpc diff --git a/requiredlibs b/requiredlibs index 11fff63..9737e70 100644 --- a/requiredlibs +++ b/requiredlibs @@ -10,6 +10,7 @@ removefile system_asl system_blocks system_c +system_collections system_configuration system_coreservices system_darwin diff --git a/requiredlibs_i386 b/requiredlibs_i386 new file mode 100644 index 0000000..6ca7afb --- /dev/null +++ b/requiredlibs_i386 @@ -0,0 +1,3 @@ +system_sim_kernel system_kernel +system_sim_platform system_platform +system_sim_pthread system_pthread diff --git a/xcodescripts/linker_arguments.sh b/xcodescripts/linker_arguments.sh index 2795481..2f22e9b 100755 --- a/xcodescripts/linker_arguments.sh +++ b/xcodescripts/linker_arguments.sh @@ -26,6 +26,18 @@ for arch in ${ARCHS}; do SDK_INSTALL_VARIANT="${DRIVERKIT:+_driverkit}" + # Unwinding i386 dependencies. + # there are no more "real" uses of i386 Libsystem, only dependency + # cycles from within the umbrella (plus libobjc and libc++). + # We will remove non-critical dylibs (that have no real dependents + # anymore) from the umbrella to decrease the overall size of the + # i386 umbrella. + # (Note that there is no i386 driverkit so this does not conflict + # with the preceding rule) + if [ "$arch" = "i386" ]; then + SDK_INSTALL_VARIANT="_i386" + fi + mkdir -p "${TEMPDIR}" ACTUALLIBS="${TEMPDIR}/${arch}.${variant}.actuallibs" -- 2.45.2