[MacPorts] #57612: clang does not respect -syslibroot when linking

MacPorts noreply at macports.org
Fri Nov 16 03:12:22 UTC 2018


#57612: clang does not respect -syslibroot when linking
---------------------+--------------------
  Reporter:  kencu   |      Owner:  (none)
      Type:  defect  |     Status:  new
  Priority:  Normal  |  Milestone:
 Component:  ports   |    Version:
Resolution:          |   Keywords:
      Port:          |
---------------------+--------------------

Comment (by kencu):

 No, it's a clang driver thing. Take a simple example:
 {{{
 $ cat hello.cpp
 #include <iostream>
 using namespace std;

 int main()
 {
     cout << "Hello, World!";
     return 0;
 }
 }}}

 we compile that, and a default isysroot is helpfully added, to the 10.14
 SDK, as you would expect:
 {{{
 $ clang++ -v -c hello.cpp
 Apple LLVM version 10.0.0 (clang-1000.11.45.5)
 Target: x86_64-apple-darwin18.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
 -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage
 -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free
 -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp
 -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim
 -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn
 -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v
 -coverage-notes-file /Users/cunningh/hello.gcno -resource-dir
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0
 -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 -I/usr/local/include -stdlib=libc++ -fdeprecated-macro -fdebug-
 compilation-dir /Users/cunningh -ferror-limit 19 -fmessage-length 195
 -stack-protector 1 -fblocks -fencode-extended-block-signature -fobjc-
 runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16
 -fdiagnostics-show-option -fcolor-diagnostics -o hello.o -x c++ hello.cpp
 clang -cc1 version 10.0.0 (clang-1000.11.45.5) default target x86_64
 -apple-darwin18.2.0
 ignoring nonexistent directory "/usr/local/include"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
 #include "..." search starts here:
 #include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks
 (framework directory)
 }}}

 if you just link it, you get a nice default syslibroot, exactly like you
 would want:
 {{{
  $ clang++ -v -Wl,-v -o hello  hello.o
 Apple LLVM version 10.0.0 (clang-1000.11.45.5)
 Target: x86_64-apple-darwin18.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -lto_library
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib
 -dynamic -arch x86_64 -macosx_version_min 10.14.0 -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 -o hello -v hello.o -L/usr/local/lib -lc++ -lSystem
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
 @(#)PROGRAM:ld  PROJECT:ld64-409.12
 BUILD 17:47:51 Sep 25 2018
 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
 armv6m armv7k armv7m armv7em arm64e arm64_32
 Library search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib
 Framework search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/
 }}}

 But if you try to force it to link against a different syslibroot, it is
 prepended by the default one, and it does **not** use the syslibroot you
 wanted it to:
 {{{
 $ clang++ -v -Wl,-v -Wl,-syslibroot
 -Wl,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -o hello  hello.o
 Apple LLVM version 10.0.0 (clang-1000.11.45.5)
 Target: x86_64-apple-darwin18.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -lto_library
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib
 -dynamic -arch x86_64 -macosx_version_min 10.14.0 -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 -o hello -v -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 hello.o -lc++ -lSystem
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
 @(#)PROGRAM:ld  PROJECT:ld64-409.12
 BUILD 17:47:51 Sep 25 2018
 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
 armv6m armv7k armv7m armv7em arm64e arm64_32
 Library search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
 Framework search paths:
         /Library/Frameworks/
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
 }}}
 unless you also add an `-isysroot`, in which case your `syslibroot` was
 for nothing anyway:
 {{{
 $ clang++ -v -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -Wl,-v -Wl,-syslibroot
 -Wl,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -o hello  hello.o
 Apple LLVM version 10.0.0 (clang-1000.11.45.5)
 Target: x86_64-apple-darwin18.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -lto_library
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib
 -dynamic -arch x86_64 -macosx_version_min 10.13.0 -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -o hello -v -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 hello.o -lc++ -lSystem
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
 @(#)PROGRAM:ld  PROJECT:ld64-409.12
 BUILD 17:47:51 Sep 25 2018
 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
 armv6m armv7k armv7m armv7em arm64e arm64_32
 Library search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
 Framework search paths:
         /Library/Frameworks/
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
 ld: warning: object file (hello.o) was built for newer OSX version (10.14)
 than being linked (10.13)
 }}}
 So the way to get what you want (at present) is to just use `-isysroot`,
 even for the link:
 {{{
 $ clang++ -v -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -Wl,-v -o hello  hello.o
 Apple LLVM version 10.0.0 (clang-1000.11.45.5)
 Target: x86_64-apple-darwin18.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -lto_library
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib
 -dynamic -arch x86_64 -macosx_version_min 10.13.0 -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -o hello -v hello.o -lc++ -lSystem
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
 @(#)PROGRAM:ld  PROJECT:ld64-409.12
 BUILD 17:47:51 Sep 25 2018
 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
 armv6m armv7k armv7m armv7em arm64e arm64_32
 Library search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
 Framework search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
 ld: warning: object file (hello.o) was built for newer OSX version (10.14)
 than being linked (10.13)
 }}}

 and that works to give you your universal binaries:
 {{{
 $ clang++ -v -arch i386 -arch x86_64  -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -Wl,-v -o hello hello.cpp
 Apple LLVM version 10.0.0 (clang-1000.11.45.5)
 Target: x86_64-apple-darwin18.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
 -cc1 -triple i386-apple-macosx10.13.0 -emit-obj -mrelax-all -disable-free
 -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp
 -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim
 -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn
 -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v
 -resource-dir
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0
 -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/cunningh
 -ferror-limit 19 -fmessage-length 195 -stack-protector 1 -fblocks
 -fencode-extended-block-signature -fobjc-runtime=macosx-fragile-10.13.0
 -fobjc-subscripting-legacy-runtime -fcxx-exceptions -fexceptions -fmax-
 type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o
 /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/hello-b3f99e.o -x c++
 hello.cpp
 clang -cc1 version 10.0.0 (clang-1000.11.45.5) default target x86_64
 -apple-darwin18.2.0
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/v1"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/local/include"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/Library/Frameworks"
 #include "..." search starts here:
 #include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks
 (framework directory)
 End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -lto_library
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib
 -no_deduplicate -dynamic -arch i386 -macosx_version_min 10.13.0
 -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -o /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/-7c0252.out -v
 /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/hello-b3f99e.o
 -arch_multiple -final_output hello -lc++ -lSystem
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
 @(#)PROGRAM:ld  PROJECT:ld64-409.12
 BUILD 17:47:51 Sep 25 2018
 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
 armv6m armv7k armv7m armv7em arm64e arm64_32
 Library search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
 Framework search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
 ld: warning: The i386 architecture is deprecated for macOS (remove from
 the Xcode build setting: ARCHS)
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
 -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage
 -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free
 -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp
 -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim
 -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn
 -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v
 -resource-dir
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0
 -isysroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/cunningh
 -ferror-limit 19 -fmessage-length 195 -stack-protector 1 -fblocks
 -fencode-extended-block-signature -fobjc-runtime=macosx-10.13.0 -fcxx-
 exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option
 -fcolor-diagnostics -o /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T
 /hello-8ccfe5.o -x c++ hello.cpp
 clang -cc1 version 10.0.0 (clang-1000.11.45.5) default target x86_64
 -apple-darwin18.2.0
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/v1"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/local/include"
 ignoring nonexistent directory
 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/Library/Frameworks"
 #include "..." search starts here:
 #include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks
 (framework directory)
 End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
 -demangle -lto_library
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib
 -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.13.0
 -syslibroot
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
 -o /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/-78252a.out -v
 /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/hello-8ccfe5.o
 -arch_multiple -final_output hello -lc++ -lSystem
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
 @(#)PROGRAM:ld  PROJECT:ld64-409.12
 BUILD 17:47:51 Sep 25 2018
 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
 armv6m armv7k armv7m armv7em arm64e arm64_32
 Library search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
 Framework search paths:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo"
 -create -output hello
 /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/-7c0252.out
 /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/-78252a.out
 }}}

 So using `-Wl,-syslibroot -Wl,/path/to/SDK` is basically useless at
 present, when using clang. Just use `isysroot /path/to/SDK` (which is
 broken because presently `libtool` strips it out of the link line).

-- 
Ticket URL: <https://trac.macports.org/ticket/57612#comment:10>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list