pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sergey Shinderuk <s.shinderuk@postgrespro.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org, Thomas Munro <thomas.munro@gmail.com>
Subject: Re: [PATCH 1/1] Fix detection of pwritev support for OSX.
Date: Thu, 21 Jan 2021 11:39:48 +0300
Message-ID: <9ae3cf4f-895d-685f-333e-2c14a0e62b0a@postgrespro.ru> (raw)
In-Reply-To: <791992.1611184078@sss.pgh.pa.us>
References: <20210119111625.20435-1-james.hilliard1@gmail.com>
	<479372.1611070041@sss.pgh.pa.us>
	<CADvTj4riiHN9Zhhk5qOVndevQMOxuduFbFVVJnCiQ4R7k5_eng@mail.gmail.com>
	<480660.1611071845@sss.pgh.pa.us>
	<CADvTj4o6LEGRJSRR4H8Rmn8r_vv4ZE_mS0MS5Z60NwDZRwdZHQ@mail.gmail.com>
	<483800.1611076636@sss.pgh.pa.us>
	<CADvTj4oD6NoTe78vLi+Ss1CFuPH26vrhUrVTd5DHAPX63vP9Ww@mail.gmail.com>
	<522433.1611089678@sss.pgh.pa.us>
	<CADvTj4qNyMM5vHo+uZ6Xfq5n5g++X_bUTX1-g3zmNXYDWAo8sQ@mail.gmail.com>
	<CADvTj4pucOvo6aWinatLgARs3mjPFSiAXZr2ErSG4ASJsKNxBw@mail.gmail.com>
	<559755.1611106628@sss.pgh.pa.us>
	<CADvTj4qcwzrti9qK8E_xnoPHHn13hWqOGQC-1r3a=Y=mmGvCfQ@mail.gmail.com>
	<791992.1611184078@sss.pgh.pa.us>

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





view thread (30+ messages)  latest in thread

Message-ID: <9ae3cf4f-895d-685f-333e-2c14a0e62b0a@postgrespro.ru>
Permalink:  ../9ae3cf4f-895d-685f-333e-2c14a0e62b0a@postgrespro.ru/
Also on:    postgresql.org/message-id/9ae3cf4f-895d-685f-333e-2c14a0e62b0a@postgrespro.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: s.shinderuk@postgrespro.ru, tgl@sss.pgh.pa.us, james.hilliard1@gmail.com, thomas.munro@gmail.com
  Subject: Re: [PATCH 1/1] Fix detection of pwritev support for OSX.
  In-Reply-To: <9ae3cf4f-895d-685f-333e-2c14a0e62b0a@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox