Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2VVX-0008B4-Cu for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 08:40:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2VVW-0004Tc-9x for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 08:39:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2VVV-0004TV-SN for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 08:39:58 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2VVP-00069D-Vt for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 08:39:56 +0000 Received: from Sergeys-MacBook-Pro.local (unknown [62.217.185.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 27D8721C5553; Thu, 21 Jan 2021 11:39:49 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1611218389; bh=bBUFq+EGh2Cz9G3nPXBs2AP/LtUsdkJekOnfVcusC7g=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=DdNrohbWszke5YzJZaiU3+iJEmNTkvVn7wVidSVUhFQd9Lg8uTiZYBHpEF9QfPZhJ cGzZBtNHBXyuFKwgIZSAGpcJbly3I11a0v3Wk7iVssSOZk9/eWHP0g5jD+S53hUyCz qsGX9BK8to/lLal3CmEvuITlD4lXVrZlCxIP6eA8= Subject: Re: [PATCH 1/1] Fix detection of pwritev support for OSX. To: Tom Lane , James Hilliard Cc: pgsql-hackers@lists.postgresql.org, Thomas Munro References: <20210119111625.20435-1-james.hilliard1@gmail.com> <479372.1611070041@sss.pgh.pa.us> <480660.1611071845@sss.pgh.pa.us> <483800.1611076636@sss.pgh.pa.us> <522433.1611089678@sss.pgh.pa.us> <559755.1611106628@sss.pgh.pa.us> <791992.1611184078@sss.pgh.pa.us> From: Sergey Shinderuk Message-ID: <9ae3cf4f-895d-685f-333e-2c14a0e62b0a@postgrespro.ru> Date: Thu, 21 Jan 2021 11:39:48 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <791992.1611184078@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 21.01.2021 02:07, Tom Lane wrote: > I now believe what is actually happening with the short command is > that it's iterating through the available SDKs (according to some not > very clear search path) and picking the first one it finds that > matches the host system version. That matches the ktrace evidence > that shows it reading the SDKSettings.plist file in each SDK > directory. Yes, you are right. After some more digging... It searches the DEVELOPER_DIR first and then /Library/Developer/CommandLineTools, which is hardcoded. My DEVELOPER_DIR is % xcode-select -p /Applications/Xcode.app/Contents/Developer (For more detail try "otool -tV /usr/lib/libxcselect.dylib -p _xcselect_get_developer_dir_path".) It reads ProductVersion from /System/Library/CoreServices/SystemVersion.plist % plutil -p /System/Library/CoreServices/SystemVersion.plist | grep ProductVersion "ProductVersion" => "10.15.7" Strips anything after the second dot, and prepends "macosx" to it, which gives "macosx10.15". Then it scans through SDK dirs looking up CanonicalName from SDKSettings.plist until it finds a match with "macosx10.15". The overall callstack: % sudo dtrace -n 'syscall::getdirentries64:entry { ustack() }' -c 'xcrun --show-sdk-path' dtrace: description 'syscall::getdirentries64:entry ' matched 1 probe /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk dtrace: pid 20183 has exited CPU ID FUNCTION:NAME 0 846 getdirentries64:entry libsystem_kernel.dylib`__getdirentries64+0xa libsystem_c.dylib`readdir$INODE64+0x23 libsystem_c.dylib`scandir$INODE64+0x6c libxcrun.dylib`cltools_lookup_sdk_by_key+0x5f libxcrun.dylib`cltools_lookup_boot_system_sdk+0xda libxcrun.dylib`xcinfocache_resolve_sdkroot+0xc0 libxcrun.dylib`xcrun_main2+0x57a libxcrun.dylib`xcrun_main+0x9 libxcselect.dylib`xcselect_invoke_xcrun_via_library+0xc8 libxcselect.dylib`xcselect_invoke_xcrun+0x25a xcrun`DYLD-STUB$$getprogname libdyld.dylib`start+0x1 xcrun`0x2 0 846 getdirentries64:entry libsystem_kernel.dylib`__getdirentries64+0xa libsystem_c.dylib`readdir$INODE64+0x23 libsystem_c.dylib`scandir$INODE64+0x6c libxcrun.dylib`cltools_lookup_sdk_by_key+0x5f libxcrun.dylib`cltools_lookup_boot_system_sdk+0xf3 libxcrun.dylib`xcinfocache_resolve_sdkroot+0xc0 libxcrun.dylib`xcrun_main2+0x57a libxcrun.dylib`xcrun_main+0x9 libxcselect.dylib`xcselect_invoke_xcrun_via_library+0xc8 libxcselect.dylib`xcselect_invoke_xcrun+0x25a xcrun`DYLD-STUB$$getprogname libdyld.dylib`start+0x1 xcrun`0x2 The SDK search path: % sudo dtrace -n 'pid$target:::entry /probefunc=="cltools_lookup_sdk_by_key"/ { trace(copyinstr(arg0)); trace(copyinstr(arg1)) }' -c 'xcrun --show-sdk-path' dtrace: description 'pid$target:::entry ' matched 17293 probes /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk dtrace: pid 20191 has exited CPU ID FUNCTION:NAME 8 398290 cltools_lookup_sdk_by_key:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer macosx10.15 9 398290 cltools_lookup_sdk_by_key:entry /Library/Developer/CommandLineTools macosx10.15 The properties read from SDKSettings.plist: % sudo dtrace -n 'pid$target:::entry /probefunc=="_cltools_lookup_property_in_path"/ { trace(copyinstr(arg0)); trace(copyinstr(arg1)); trace(copyinstr(arg2)) }' -c 'xcrun --show-sdk-path' dtrace: description 'pid$target:::entry ' matched 17293 probes /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk dtrace: pid 20195 has exited CPU ID FUNCTION:NAME 8 398288 _cltools_lookup_property_in_path:entry / System/Library/CoreServices/SystemVersion.plist ProductVersion 8 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit20.2.sdk SDKSettings.plist IsBaseSDK 8 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit20.2.sdk SDKSettings.plist CanonicalName 4 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit20.2.sdk SDKSettings.plist CanonicalNameForBuildSettings 4 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk SDKSettings.plist IsBaseSDK 4 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk SDKSettings.plist CanonicalName 4 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk SDKSettings.plist CanonicalNameForBuildSettings 4 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk SDKSettings.plist PLATFORM_NAME 4 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk SDKSettings.plist IsBaseSDK 2 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk SDKSettings.plist CanonicalName 2 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk SDKSettings.plist CanonicalNameForBuildSettings 2 398288 _cltools_lookup_property_in_path:entry /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk SDKSettings.plist PLATFORM_NAME 2 398288 _cltools_lookup_property_in_path:entry /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk SDKSettings.plist IsBaseSDK 2 398288 _cltools_lookup_property_in_path:entry /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk SDKSettings.plist CanonicalName 2 398288 _cltools_lookup_property_in_path:entry /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk SDKSettings.plist CanonicalNameForBuildSettings 0 398288 _cltools_lookup_property_in_path:entry /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk SDKSettings.plist PLATFORM_NAME 0 398288 _cltools_lookup_property_in_path:entry /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SDKSettings.plist IsBaseSDK 0 398288 _cltools_lookup_property_in_path:entry /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SDKSettings.plist CanonicalName BTW, on my machine /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk is skipped because it points to 11.0: % ls -l /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk lrwxr-xr-x 1 root wheel 14 Nov 17 02:21 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -> MacOSX11.0.sdk For more detail try % otool -tV /Applications/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib -p _cltools_lookup_boot_system_sdk