iains / gcc-darwin-arm64

GCC master branch for Darwin with experimental support for Arm64. Currently GCC-15.0.0 [September 2024]
GNU General Public License v2.0
268 stars 33 forks source link

With 14.0, tests using -fuse-ld=lld fail #130

Closed ilg-ul closed 4 months ago

ilg-ul commented 5 months ago

Given that older Apple linkers are not able to process LTO properly, in my tests I paired -flto with -fuse-ld=lld.

It looks like this no longer works with 14.0:

[/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc simple-hello.c -o lto-simple-hello-c-one -fuse-ld=lld -flto -v -v]
Using built-in specs.
COLLECT_GCC=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc
COLLECT_LTO_WRAPPER=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/lto-wrapper
Target: x86_64-apple-darwin23.3.0
Configured with: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/sources/gcc-darwin-arm64.git/configure --prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application --program-suffix= --infodir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/info --mandir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/man --htmldir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/html --pdfdir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/pdf --build=x86_64-apple-darwin23.3.0 --host=x86_64-apple-darwin23.3.0 --target=x86_64-apple-darwin23.3.0 --with-pkgversion='xPack GCC x86_64' --with-dwarf2 --with-diagnostics-color=auto --with-libiconv-prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-gmp=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-isl=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpc=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpfr=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-zstd=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-system-zlib --without-cuda-driver --enable-languages=c,c++,objc,obj-c++,lto,fortran --enable-objc-gc=auto --enable-checking=release --enable-lto --enable-plugin --enable-__cxa_atexit --enable-cet=auto --enable-threads=posix --enable-cloog-backend=isl --enable-default-pie --enable-libgomp --enable-libssp --enable-default-ssp --enable-libatomic --enable-graphite --enable-libquadmath --enable-libquadmath-support --enable-libstdcxx --enable-libstdcxx-backtrace --enable-libstdcxx-time=yes --enable-libstdcxx-visibility --enable-libstdcxx-threads --enable-static --with-default-libstdcxx-abi=new --enable-pie-tools --enable-gold --disable-nls --disable-libstdcxx-debug --disable-libstdcxx-pch --disable-install-libiberty --disable-werror --enable-shared --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --enable-bootstrap --with-boot-ldflags='-static-libstdc++ -static-libgcc -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib -Wl,-rpath,/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib' --disable-rpath --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240405 (experimental) (xPack GCC x86_64) 
COLLECT_GCC_OPTIONS='-o' 'lto-simple-hello-c-one' '-fuse-ld=lld' '-flto' '-v' '-v' '-mmacosx-version-min=10.13' '-asm_macosx_version_min=10.13' '-nodefaultexport' '-mtune=core2' '-dumpdir' 'lto-simple-hello-c-one-'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/cc1 -quiet -v -v -D__DYNAMIC__ simple-hello.c -fPIC -quiet -dumpdir lto-simple-hello-c-one- -dumpbase simple-hello.c -dumpbase-ext .c -mmacosx-version-min=10.13 -mtune=core2 -version -fuse-ld=lld -flto -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccScaqnc.s
GNU C17 (xPack GCC x86_64) version 14.0.1 20240405 (experimental) (x86_64-apple-darwin23.3.0)
       compiled by GNU C version 14.0.1 20240405 (experimental), GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../../x86_64-apple-darwin23.3.0/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/include
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
End of search list.
Compiler executable checksum: 993e3a1f5195221aaf9c598269b10657
COLLECT_GCC_OPTIONS='-o' 'lto-simple-hello-c-one' '-fuse-ld=lld' '-flto' '-v' '-v' '-mmacosx-version-min=10.13'  '-nodefaultexport' '-mtune=core2' '-dumpdir' 'lto-simple-hello-c-one-'
as -arch x86_64 -v -v -mmacosx-version-min=10.13 -mllvm -x86-pad-for-align=false -force_cpusubtype_ALL -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cccpM6Eg.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccScaqnc.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx10.13.0 -filetype obj -main-file-name ccScaqnc.s -target-cpu penryn -fdebug-compilation-dir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -x86-pad-for-align=false -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cccpM6Eg.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccScaqnc.s
COMPILER_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/
LIBRARY_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../
COLLECT_GCC_OPTIONS='-o' 'lto-simple-hello-c-one' '-fuse-ld=lld' '-flto' '-v' '-v' '-mmacosx-version-min=10.13'  '-nodefaultexport' '-mtune=core2' '-dumpdir' 'lto-simple-hello-c-one.'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/collect2 -demangle -flto -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch x86_64 -fuse-ld=lld -platform_version macos 10.13 0.0 -o lto-simple-hello-c-one -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1 -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../.. -lemutls_w -lheapt_w /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cccpM6Eg.o -lgcc -lSystem -no_compact_unwind -rpath @loader_path -rpath /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1 -rpath /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib
ld.lld: error: unknown argument '-syslibroot'
ld.lld: error: unknown argument '-dynamic', did you mean '-Bdynamic'
ld.lld: error: unknown argument '-arch'
ld.lld: error: unknown argument '-platform_version'
ld.lld: error: unknown argument '-no_compact_unwind'
ld.lld: error: cannot open /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/: Is a directory
ld.lld: error: cannot open x86_64: No such file or directory
ld.lld: error: cannot open macos: No such file or directory
ld.lld: error: cannot open 10.13: No such file or directory
ld.lld: error: cannot open 0.0: No such file or directory
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libemutls_w.a: archive member 'emutls_s.o' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libheapt_w.a: archive member 'heap-trampoline_s.o' is neither ET_REL nor LLVM bitcode
ld.lld: error: /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cccpM6Eg.o: unknown file type
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libgcc.a: archive member '_muldi3.o' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libgcc.a: archive member '_negdi2.o' is neither ET_REL nor LLVM bitcode

After removing -fuse-ld=lld, the test passed:

[/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc simple-hello.c -o lto-simple-hello-c-one -flto -v -v]
Using built-in specs.
COLLECT_GCC=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc
COLLECT_LTO_WRAPPER=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/lto-wrapper
Target: x86_64-apple-darwin23.3.0
Configured with: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/sources/gcc-darwin-arm64.git/configure --prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application --program-suffix= --infodir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/info --mandir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/man --htmldir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/html --pdfdir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/pdf --build=x86_64-apple-darwin23.3.0 --host=x86_64-apple-darwin23.3.0 --target=x86_64-apple-darwin23.3.0 --with-pkgversion='xPack GCC x86_64' --with-dwarf2 --with-diagnostics-color=auto --with-libiconv-prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-gmp=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-isl=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpc=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpfr=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-zstd=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-system-zlib --without-cuda-driver --enable-languages=c,c++,objc,obj-c++,lto,fortran --enable-objc-gc=auto --enable-checking=release --enable-lto --enable-plugin --enable-__cxa_atexit --enable-cet=auto --enable-threads=posix --enable-cloog-backend=isl --enable-default-pie --enable-libgomp --enable-libssp --enable-default-ssp --enable-libatomic --enable-graphite --enable-libquadmath --enable-libquadmath-support --enable-libstdcxx --enable-libstdcxx-backtrace --enable-libstdcxx-time=yes --enable-libstdcxx-visibility --enable-libstdcxx-threads --enable-static --with-default-libstdcxx-abi=new --enable-pie-tools --enable-gold --disable-nls --disable-libstdcxx-debug --disable-libstdcxx-pch --disable-install-libiberty --disable-werror --enable-shared --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --enable-bootstrap --with-boot-ldflags='-static-libstdc++ -static-libgcc -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib -Wl,-rpath,/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib' --disable-rpath --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240405 (experimental) (xPack GCC x86_64) 
COLLECT_GCC_OPTIONS='-o' 'lto-simple-hello-c-one' '-flto' '-v' '-v' '-mmacosx-version-min=10.13' '-asm_macosx_version_min=10.13' '-nodefaultexport' '-mtune=core2' '-dumpdir' 'lto-simple-hello-c-one-'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/cc1 -quiet -v -v -D__DYNAMIC__ simple-hello.c -fPIC -quiet -dumpdir lto-simple-hello-c-one- -dumpbase simple-hello.c -dumpbase-ext .c -mmacosx-version-min=10.13 -mtune=core2 -version -flto -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccX6ySad.s
GNU C17 (xPack GCC x86_64) version 14.0.1 20240405 (experimental) (x86_64-apple-darwin23.3.0)
       compiled by GNU C version 14.0.1 20240405 (experimental), GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../../x86_64-apple-darwin23.3.0/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/include
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
End of search list.
Compiler executable checksum: 993e3a1f5195221aaf9c598269b10657
COLLECT_GCC_OPTIONS='-o' 'lto-simple-hello-c-one' '-flto' '-v' '-v' '-mmacosx-version-min=10.13' '-nodefaultexport' '-mtune=core2' '-dumpdir' 'lto-simple-hello-c-one-'
as -arch x86_64 -v -v -mmacosx-version-min=10.13 -mllvm -x86-pad-for-align=false -force_cpusubtype_ALL -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccZpnw6I.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccX6ySad.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx10.13.0 -filetype obj -main-file-name ccX6ySad.s -target-cpu penryn -fdebug-compilation-dir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -x86-pad-for-align=false -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccZpnw6I.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccX6ySad.s
COMPILER_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/
LIBRARY_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../
COLLECT_GCC_OPTIONS='-o' 'lto-simple-hello-c-one' '-flto' '-v' '-v' '-mmacosx-version-min=10.13' '-nodefaultexport' '-mtune=core2' '-dumpdir' 'lto-simple-hello-c-one.'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/collect2 -demangle -flto -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch x86_64 -platform_version macos 10.13 0.0 -o lto-simple-hello-c-one -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1 -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../.. -lemutls_w -lheapt_w /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccZpnw6I.o -lgcc -lSystem -no_compact_unwind -rpath @loader_path -rpath /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1 -rpath /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/lto-wrapper /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccZpnw6I.o 
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccB10uRc
Using built-in specs.
COLLECT_GCC=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc
Target: x86_64-apple-darwin23.3.0
Configured with: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/sources/gcc-darwin-arm64.git/configure --prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application --program-suffix= --infodir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/info --mandir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/man --htmldir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/html --pdfdir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/pdf --build=x86_64-apple-darwin23.3.0 --host=x86_64-apple-darwin23.3.0 --target=x86_64-apple-darwin23.3.0 --with-pkgversion='xPack GCC x86_64' --with-dwarf2 --with-diagnostics-color=auto --with-libiconv-prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-gmp=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-isl=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpc=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpfr=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-zstd=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-system-zlib --without-cuda-driver --enable-languages=c,c++,objc,obj-c++,lto,fortran --enable-objc-gc=auto --enable-checking=release --enable-lto --enable-plugin --enable-__cxa_atexit --enable-cet=auto --enable-threads=posix --enable-cloog-backend=isl --enable-default-pie --enable-libgomp --enable-libssp --enable-default-ssp --enable-libatomic --enable-graphite --enable-libquadmath --enable-libquadmath-support --enable-libstdcxx --enable-libstdcxx-backtrace --enable-libstdcxx-time=yes --enable-libstdcxx-visibility --enable-libstdcxx-threads --enable-static --with-default-libstdcxx-abi=new --enable-pie-tools --enable-gold --disable-nls --disable-libstdcxx-debug --disable-libstdcxx-pch --disable-install-libiberty --disable-werror --enable-shared --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --enable-bootstrap --with-boot-ldflags='-static-libstdc++ -static-libgcc -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib -Wl,-rpath,/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib' --disable-rpath --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240405 (experimental) (xPack GCC x86_64) 
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-v' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans-output-list=/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans.out' '-fwpa' '-mmacosx-version-min=10.13' '-asm_macosx_version_min=10.13' '-nodefaultexport'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/lto1 -fPIC -quiet -dumpbase ./lto-simple-hello-c-one.wpa -mtune=core2 -mmacosx-version-min=10.13 -version -fno-openmp -fno-openacc -fcf-protection=none -fPIC -fltrans-output-list=/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans.out -fwpa @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cc12QskA
GNU GIMPLE (xPack GCC x86_64) version 14.0.1 20240405 (experimental) (x86_64-apple-darwin23.3.0)
       compiled by GNU C version 14.0.1 20240405 (experimental), GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COMPILER_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/
LIBRARY_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-v' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans-output-list=/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans.out' '-fwpa' '-mmacosx-version-min=10.13' '-asm_macosx_version_min=10.13' '-nodefaultexport' '-dumpdir' './lto-simple-hello-c-one.wpa.'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccaZSq4P
Using built-in specs.
COLLECT_GCC=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc
Target: x86_64-apple-darwin23.3.0
Configured with: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/sources/gcc-darwin-arm64.git/configure --prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application --program-suffix= --infodir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/info --mandir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/man --htmldir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/html --pdfdir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/share/pdf --build=x86_64-apple-darwin23.3.0 --host=x86_64-apple-darwin23.3.0 --target=x86_64-apple-darwin23.3.0 --with-pkgversion='xPack GCC x86_64' --with-dwarf2 --with-diagnostics-color=auto --with-libiconv-prefix=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-gmp=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-isl=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpc=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-mpfr=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-zstd=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install --with-system-zlib --without-cuda-driver --enable-languages=c,c++,objc,obj-c++,lto,fortran --enable-objc-gc=auto --enable-checking=release --enable-lto --enable-plugin --enable-__cxa_atexit --enable-cet=auto --enable-threads=posix --enable-cloog-backend=isl --enable-default-pie --enable-libgomp --enable-libssp --enable-default-ssp --enable-libatomic --enable-graphite --enable-libquadmath --enable-libquadmath-support --enable-libstdcxx --enable-libstdcxx-backtrace --enable-libstdcxx-time=yes --enable-libstdcxx-visibility --enable-libstdcxx-threads --enable-static --with-default-libstdcxx-abi=new --enable-pie-tools --enable-gold --disable-nls --disable-libstdcxx-debug --disable-libstdcxx-pch --disable-install-libiberty --disable-werror --enable-shared --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --enable-bootstrap --with-boot-ldflags='-static-libstdc++ -static-libgcc -L/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib -Wl,-rpath,/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/install/lib' --disable-rpath --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240405 (experimental) (xPack GCC x86_64) 
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-v' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans' '-o' '/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans0.ltrans.o' '-mmacosx-version-min=10.13' '-asm_macosx_version_min=10.13' '-nodefaultexport'
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/lto1 -fPIC -quiet -dumpbase ./lto-simple-hello-c-one.ltrans0.ltrans -mtune=core2 -mmacosx-version-min=10.13 -version -fno-openmp -fno-openacc -fcf-protection=none -fPIC -fltrans @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cciWeTcS -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccUUbWdI.s
GNU GIMPLE (xPack GCC x86_64) version 14.0.1 20240405 (experimental) (x86_64-apple-darwin23.3.0)
       compiled by GNU C version 14.0.1 20240405 (experimental), GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-v' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans' '-o' '/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans0.ltrans.o' '-mmacosx-version-min=10.13'  '-nodefaultexport'
as -arch x86_64 -v -v -mmacosx-version-min=10.13 -mllvm -x86-pad-for-align=false -force_cpusubtype_ALL -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans0.ltrans.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccUUbWdI.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx10.13.0 -filetype obj -main-file-name ccUUbWdI.s -target-cpu penryn -fdebug-compilation-dir=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -x86-pad-for-align=false -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans0.ltrans.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccUUbWdI.s
COMPILER_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/libexec/gcc/x86_64-apple-darwin23.3.0/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/
LIBRARY_PATH=/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/../../../
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-v' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans' '-o' '/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccSEiUpw.ltrans0.ltrans.o' '-mmacosx-version-min=10.13'  '-nodefaultexport' '-dumpdir' './lto-simple-hello-c-one.ltrans0.ltrans.'

[ls -l /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp/lto-simple-hello-c-one]
-rwxr-xr-x  1 ilg  staff  33040 Apr 11 10:50 /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp/lto-simple-hello-c-one

[file -L /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp/lto-simple-hello-c-one]
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp/lto-simple-hello-c-one: Mach-O 64-bit executable x86_64

[/usr/bin/objdump --macho --dylibs-used /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp/lto-simple-hello-c-one]
/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/x86_64-apple-darwin23.3.0/tests/gcc/c-cpp/lto-simple-hello-c-one: (LC_RPATH=@loader_path:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1:/Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib)

Test "lto-simple-hello-c-one " passed, got "Hello" :-)

The test is a simple printf("Hello\n"); return 0;

The build used the trunk, bootstrapped with Homebrew llvm 17, on an Intel macOS 14.3.1 & CLT 15.1.

iains commented 5 months ago

Given that older Apple linkers are not able to process LTO properly, in my tests I paired -flto with -fuse-ld=lld.

I am not sure what you are expecting.

There are two kinds of LTO in Darwin toolchains - clang's LTO and GCC's LTO - they are not compatible or interoperable.

Darwins' linkers have never (to date) handled GCC's LTO (they do, however, handle clang's LTO even back to earlier toolchains).

GCC's LTO is handled by "collect2" but has some known issues with debug [ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82005 ] (which needs patches to dsymutll to fix, so non-trivial).

AFAIK ld64, lld and mold only support clang's LTO - so I am not sure what/how was previously working that is not now - can you point to a GCC-13 test that passes but now fails on GCC-trunk?

(I would not expect -fuse-ld=lld to work on Darwin unless there's an lld installed in the same directory as ld - which will not be the case for xcode releases).

ilg-ul commented 5 months ago

My production builds run on macOS 10.13, and when I first tried LTO, I remember the linker was not happy, thus I used the newer lld, available in the llvm/clang package.

This worked up to GCC 13.2, with clang 16.

The current test build was done with Homebrew llvm 17, which also includes lld.

I don't know if the problem is with Homebrew llvm 17 lld, or with GCC 14, but the test that previously used lld no longer passed.

If you think that this is not expected to work, I'll update my test scripts.

iains commented 5 months ago

I cannot tell without a reproducer (GCC's LTO without debug should be working fine - I do not see any wholesale regressions on trunk c.f. gcc-13)

ilg-ul commented 5 months ago

I did a run on a M1 macOS 11.6, this time using the Apple clang and the results are the same:

iains commented 5 months ago

OK. I think I'm stumped here without a reproducer.

ilg-ul commented 5 months ago

Perhaps @fxcoudert has a better idea, but my reproducer uses a Homebrew instance installed in a custom location (for example ~/.local/homebrew/hb, since I have multiple Homebrew instances in ~/.local/homebrew).

ilg@wksi tmp % export PATH=${HOME}/.local/homebrew/hb/bin:${PATH}

ilg@wksi tmp % brew install gcc llvm 
ilg@wksi tmp % export PATH=${HOME}/.local/homebrew/hb/Cellar/gcc/13.2.0/bin:${HOME}/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin:$PATH

ilg@wksi tmp % which gcc-13
/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/gcc-13
ilg@wksi tmp % which lld   
/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/lld

ilg@wksi tmp % cat hello.c
#include <stdio.h>

int
main(int argc, char* argv[])
{
  printf("Hello\n");

  return 0;
}

ilg@wksi tmp % gcc-13 hello.c -o hello-13  -flto   
ilg@wksi tmp % ./hello-13
Hello
ilg@wksi tmp % gcc-13 hello.c -o hello-13-lld  -flto -fuse-ld=lld
ilg@wksi tmp % ./hello-13-lld
Hello

ilg@wksi tmp % /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc -o hello-14  hello.c
ilg@wksi tmp % ./hello-14
Hello

ilg@wksi tmp % /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc -o hello-14-ld  hello.c -fuse-ld=lld 
ld.lld: error: unknown argument '-syslibroot'
ld.lld: error: unknown argument '-dynamic', did you mean '-Bdynamic'
ld.lld: error: unknown argument '-arch'
ld.lld: error: unknown argument '-platform_version'
ld.lld: error: unknown argument '-no_compact_unwind'
ld.lld: error: cannot open /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/: Is a directory
ld.lld: error: cannot open x86_64: No such file or directory
ld.lld: error: cannot open macos: No such file or directory
ld.lld: error: cannot open 14.0.0: No such file or directory
ld.lld: error: cannot open 0.0: No such file or directory
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libemutls_w.a: archive member 'emutls_s.o' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libheapt_w.a: archive member 'heap-trampoline_s.o' is neither ET_REL nor LLVM bitcode
ld.lld: error: /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccUjfNr2.o: unknown file type
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libgcc.a: archive member '_muldi3.o' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libgcc.a: archive member '_negdi2.o' is neither ET_REL nor LLVM bitcode
...
ld.lld: warning: /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/lib/gcc/x86_64-apple-darwin23.3.0/14.0.1/libgcc.a: archive member 'sse_resms64fx.o' is neither ET_REL nor LLVM bitcode
ld.lld: error: unable to find library -lSystem
collect2: error: ld returned 1 exit status
iains commented 5 months ago

Perhaps @fxcoudert has a better idea, but my reproducer uses a Homebrew instance installed in a custom location (for example ~/.local/homebrew/hb, since I have multiple Homebrew instances in ~/.local/homebrew).

ilg@wksi tmp % /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc -o hello-14-ld hello.c -fuse-ld=lld ld.lld: error: unknown argument '-syslibroot' ld.lld: error: unknown argument '-dynamic', did you mean '-Bdynamic' ld.lld: error: unknown argument '-arch' ld.lld: error: unknown argument '-platform_version'

^^^ this is exactly as expected - since Darwin needs to use ld64.lld (which should be installed as part of the llvm install) .. however we do not currently have -fuse-ld=ld64.lld (or whatever equivalent we'd need to make)

Perhaps an earlier install had lld symlinked to ld64.lld?

iains commented 5 months ago

ilg@wksi tmp % gcc-13 hello.c -o hello-13-lld -flto -fuse-ld=lld ilg@wksi tmp % ./hello-13-lld Hello

Please can you repeat this with "-v -Wl,-v" and put the output ?

ilg-ul commented 5 months ago

^^^ this is exactly as expected - since Darwin needs to use ld64.lld (which should be installed as part of the llvm install) .. however we do not currently have -fuse-ld=ld64.lld (or whatever equivalent we'd need to make)

Perhaps an earlier install had lld symlinked to ld64.lld?

I don't know what this means, but both lld and ld64.lld are part of the installed llvm:

ilg@wksi tmp % file $(which lld) 
/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/lld: Mach-O 64-bit executable x86_64
ilg@wksi tmp % which lld
/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/lld
ilg@wksi tmp % which ld64.lld
/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/ld64.lld

Please can you repeat this with "-v -Wl,-v" and put the output ?

ilg@wksi tmp % gcc-13 hello.c -o hello-13-lld -flto -fuse-ld=lld -v -Wl,-v
Using built-in specs.
COLLECT_GCC=gcc-13
COLLECT_LTO_WRAPPER=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/lto-wrapper
Target: x86_64-apple-darwin23
Configured with: ../configure --prefix=/Users/ilg/.local/homebrew/hb/opt/gcc --libdir=/Users/ilg/.local/homebrew/hb/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/Users/ilg/.local/homebrew/hb/opt/gmp --with-mpfr=/Users/ilg/.local/homebrew/hb/opt/mpfr --with-mpc=/Users/ilg/.local/homebrew/hb/opt/libmpc --with-isl=/Users/ilg/.local/homebrew/hb/opt/isl --with-zstd=/Users/ilg/.local/homebrew/hb/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=x86_64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Homebrew GCC 13.2.0) 
COLLECT_GCC_OPTIONS='-o' 'hello-13-lld' '-flto' '-fuse-ld=lld' '-v' '-mmacosx-version-min=14.0.0' '-asm_macosx_version_min=14.0' '-nodefaultexport' '-mtune=core2' '-dumpdir' 'hello-13-lld-'
 /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/cc1 -quiet -v -iprefix /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/ -D__DYNAMIC__ hello.c -fPIC -quiet -dumpdir hello-13-lld- -dumpbase hello.c -dumpbase-ext .c -mmacosx-version-min=14.0.0 -mtune=core2 -version -flto -fuse-ld=lld -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccQAQW9F.s
GNU C17 (Homebrew GCC 13.2.0) version 13.2.0 (x86_64-apple-darwin23)
    compiled by GNU C version 13.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../../../../x86_64-apple-darwin23/include"
ignoring duplicate directory "/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/x86_64-apple-darwin23/13/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/local/include"
ignoring duplicate directory "/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/x86_64-apple-darwin23/13/include-fixed"
ignoring nonexistent directory "/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../../../../x86_64-apple-darwin23/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/include
 /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/include-fixed
 /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks
End of search list.
Compiler executable checksum: d54e05566f4bd579d2601ae91105141f
COLLECT_GCC_OPTIONS='-o' 'hello-13-lld' '-flto' '-fuse-ld=lld' '-v' '-mmacosx-version-min=14.0.0'  '-nodefaultexport' '-mtune=core2' '-dumpdir' 'hello-13-lld-'
 as -arch x86_64 -v -mmacosx-version-min=14.0 -mllvm -x86-pad-for-align=false -force_cpusubtype_ALL -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccJY0GFJ.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccQAQW9F.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx14.0.0 -filetype obj -main-file-name ccQAQW9F.s -target-cpu penryn -fdebug-compilation-dir=/Users/ilg/tmp -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -x86-pad-for-align=false -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccJY0GFJ.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccQAQW9F.s
COMPILER_PATH=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/
LIBRARY_PATH=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../
COLLECT_GCC_OPTIONS='-o' 'hello-13-lld' '-flto' '-fuse-ld=lld' '-v' '-mmacosx-version-min=14.0.0'  '-nodefaultexport' '-mtune=core2' '-dumpdir' 'hello-13-lld.'
 /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/collect2 -flto -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ -dynamic -arch x86_64 -platform_version macos 14.0.0 0.0 -o hello-13-lld -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13 -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../.. /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccJY0GFJ.o -v -lemutls_w -lgcc -lSystem -no_compact_unwind -rpath @loader_path -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current/gcc/x86_64-apple-darwin23/13 -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current/gcc -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current
collect2 version 13.2.0
/usr/bin/ld -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ -dynamic -arch x86_64 -platform_version macos 14.0.0 0.0 -o hello-13-lld -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13 -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../.. /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccJY0GFJ.o -v -lemutls_w -lgcc -lSystem -no_compact_unwind -rpath @loader_path -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current/gcc/x86_64-apple-darwin23/13 -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current/gcc -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current
@(#)PROGRAM:ld  PROJECT:dyld-1022.1
BUILD 13:20:30 Nov 10 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.8)
Library search paths:
    /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13
    /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc
    /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../..
Framework search paths:
/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/lto-wrapper /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccJY0GFJ.o
/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/lto-wrapper /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccJY0GFJ.o 
gcc-13 @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cceW5wpr
Using built-in specs.
COLLECT_GCC=gcc-13
Target: x86_64-apple-darwin23
Configured with: ../configure --prefix=/Users/ilg/.local/homebrew/hb/opt/gcc --libdir=/Users/ilg/.local/homebrew/hb/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/Users/ilg/.local/homebrew/hb/opt/gmp --with-mpfr=/Users/ilg/.local/homebrew/hb/opt/mpfr --with-mpc=/Users/ilg/.local/homebrew/hb/opt/libmpc --with-isl=/Users/ilg/.local/homebrew/hb/opt/isl --with-zstd=/Users/ilg/.local/homebrew/hb/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=x86_64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Homebrew GCC 13.2.0) 
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-fuse-ld=lld' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans-output-list=/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans.out' '-fwpa' '-mmacosx-version-min=14.0.0' '-asm_macosx_version_min=14.0' '-nodefaultexport'
 /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../libexec/gcc/x86_64-apple-darwin23/13/lto1 -fPIC -quiet -dumpbase ./hello-13-lld.wpa -mtune=core2 -mmacosx-version-min=14.0.0 -version -fno-openmp -fno-openacc -fcf-protection=none -fPIC -fuse-ld=lld -fltrans-output-list=/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans.out -fwpa @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//cc3EdDEb
GNU GIMPLE (Homebrew GCC 13.2.0) version 13.2.0 (x86_64-apple-darwin23)
    compiled by GNU C version 13.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COMPILER_PATH=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../libexec/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/
LIBRARY_PATH=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-fuse-ld=lld' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans-output-list=/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans.out' '-fwpa' '-mmacosx-version-min=14.0.0' '-asm_macosx_version_min=14.0' '-nodefaultexport' '-dumpdir' './hello-13-lld.wpa.'
gcc-13 @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccXNZZcE
Using built-in specs.
COLLECT_GCC=gcc-13
Target: x86_64-apple-darwin23
Configured with: ../configure --prefix=/Users/ilg/.local/homebrew/hb/opt/gcc --libdir=/Users/ilg/.local/homebrew/hb/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/Users/ilg/.local/homebrew/hb/opt/gmp --with-mpfr=/Users/ilg/.local/homebrew/hb/opt/mpfr --with-mpc=/Users/ilg/.local/homebrew/hb/opt/libmpc --with-isl=/Users/ilg/.local/homebrew/hb/opt/isl --with-zstd=/Users/ilg/.local/homebrew/hb/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=x86_64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Homebrew GCC 13.2.0) 
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-fuse-ld=lld' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans' '-o' '/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans0.ltrans.o' '-mmacosx-version-min=14.0.0' '-asm_macosx_version_min=14.0' '-nodefaultexport'
 /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../libexec/gcc/x86_64-apple-darwin23/13/lto1 -fPIC -quiet -dumpbase ./hello-13-lld.ltrans0.ltrans -mtune=core2 -mmacosx-version-min=14.0.0 -version -fno-openmp -fno-openacc -fcf-protection=none -fPIC -fuse-ld=lld -fltrans @/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccNVF5Cr -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccKUnMCX.s
GNU GIMPLE (Homebrew GCC 13.2.0) version 13.2.0 (x86_64-apple-darwin23)
    compiled by GNU C version 13.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-fuse-ld=lld' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans' '-o' '/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans0.ltrans.o' '-mmacosx-version-min=14.0.0'  '-nodefaultexport'
 as -arch x86_64 -v -mmacosx-version-min=14.0 -mllvm -x86-pad-for-align=false -force_cpusubtype_ALL -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans0.ltrans.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccKUnMCX.s
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx14.0.0 -filetype obj -main-file-name ccKUnMCX.s -target-cpu penryn -fdebug-compilation-dir=/Users/ilg/tmp -dwarf-debug-producer "Apple clang version 15.0.0 (clang-1500.1.0.2.5)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -x86-pad-for-align=false -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans0.ltrans.o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccKUnMCX.s
COMPILER_PATH=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/../../../../libexec/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../libexec/gcc/
LIBRARY_PATH=/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../:/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../../
COLLECT_GCC_OPTIONS='-c' '-fno-openmp' '-fno-openacc' '-fcf-protection=none' '-fPIC' '-fuse-ld=lld' '-v' '-nodefaultexport' '-mtune=core2'   '-fltrans' '-o' '/var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans0.ltrans.o' '-mmacosx-version-min=14.0.0'  '-nodefaultexport' '-dumpdir' './hello-13-lld.ltrans0.ltrans.'
/usr/bin/ld -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ -dynamic -arch x86_64 -platform_version macos 14.0.0 0.0 -o hello-13-lld -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13 -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc -L/Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../.. /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T//ccA7gllv.ltrans0.ltrans.o -v -lemutls_w -lgcc -lSystem -no_compact_unwind -rpath @loader_path -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current/gcc/x86_64-apple-darwin23/13 -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current/gcc -rpath /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/lib/gcc/current
@(#)PROGRAM:ld  PROJECT:dyld-1022.1
BUILD 13:20:30 Nov 10 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.8)
Library search paths:
    /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13
    /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc
    /Users/ilg/.local/homebrew/hb/Cellar/gcc/13.2.0/bin/../lib/gcc/current/gcc/x86_64-apple-darwin23/13/../../..
Framework search paths:
ilg@wksi tmp % 
iains commented 5 months ago

I think the difference is that before gcc-14 (current patches), Darwin silently ignore -fuse-ld= and now (since i added support for -fuse-ld=classic) it's trying to invoke what you asked (lld) which is not compatible with Darwin.

Using LLVM's lld is not currently supported (neither is mold/sold) - maybe we can take a look in GCC-15 - but there has to be some benefit to it (and I'm not aware of one other than it being open source, so we can patch it)

iains commented 5 months ago

as you can see, your "working" -fuse-ld=lld is ignoring it and invoking the standard ld.

ilg-ul commented 5 months ago

(lld) which is not compatible with Darwin. ... -fuse-ld=lld is ignoring it and invoking the standard ld.

If lld is indeed not compatible with Darwin, any idea why it is included in the Homebrew llvm distribution? Could it be compatible with Darwin, but not compatible with GCC? @fxcoudert ?

iains commented 5 months ago

lld can be used to build cross-compilers (so can binutils bfd.ld) neither is compatible with Darwin (but ld64.lld is)

ilg-ul commented 5 months ago

ld64.lld is

I'm not sure, but isn't clang forwarding lld to ld64.lld automatically on Darwin?

GCC does not accept even explicit use:

ilg@wksi tmp % gcc-13 hello.c -o hello-13-lld -flto -fuse-ld=ld64.lld     
gcc-13: error: unrecognized command-line option '-fuse-ld=ld64.lld'; did you mean '-fuse-ld=lld'?
ilg@wksi tmp % /Users/ilg/Work/xpack-dev-tools-build/gcc-14.0.1-1/darwin-x64/application/bin/gcc -o hello-14-ld  hello.c -fuse-ld=ld64.lld
gcc: error: unrecognized command-line option '-fuse-ld=ld64.lld'; did you mean '-fuse-ld=lld'?
ilg-ul commented 5 months ago

Apparently clang does forward lld to ld64.lld automatically:

ilg@wksi tmp % which clang-17
/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/clang-17
ilg@wksi tmp % clang-17 hello.c -o hello-17-lld -flto -fuse-ld=lld          

ilg@wksi tmp % clang-17 hello.c -o hello-17-lld -flto -fuse-ld=lld -v -Wl,-v
Homebrew clang version 17.0.6
Target: x86_64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin
 "/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/clang-17" -cc1 -triple x86_64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-llvm-bc -flto=full -flto-unit -dumpdir hello-17-lld- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 1022.1 -v -fcoverage-compilation-dir=/Users/ilg/tmp -resource-dir /Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/lib/clang/17 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/local/include -internal-isystem /Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/lib/clang/17/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include -fdebug-compilation-dir=/Users/ilg/tmp -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T/hello-856b09.o -x c hello.c
clang -cc1 version 17.0.6 based upon LLVM 17.0.6 default target x86_64-apple-darwin23.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/lib/clang/17/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/bin/ld64.lld" -demangle -object_path_lto /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T/cc-00d4a7.o -no_deduplicate -dynamic -arch x86_64 -platform_version macos 14.0.0 14.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -o hello-17-lld /var/folders/gr/13tt3vcd7m1gnbhwtkmf5cnw0000gn/T/hello-856b09.o -v -lSystem /Users/ilg/.local/homebrew/hb/Cellar/llvm/17.0.6_1/lib/clang/17/lib/darwin/libclang_rt.osx.a
Homebrew LLD 17.0.6
Library search paths:
    /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/lib
Framework search paths:
    /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks
ilg@wksi tmp % 
iains commented 5 months ago

Apparently clang does forward lld to ld64.lld automatically:

OK. 1/ I can make Darwin do the same. 2/ ld64.lld will still be unsupported (I am not sure that even the lld team claims that the mach-o linker is actually "ready" for production use yet).

It will not make any material difference to the support for GCC's LTO - that needs linker and debug linker patching - on my very long TODO (but not especially high).

ilg-ul commented 5 months ago

Fair enough.

My build scripts generate toolchain binaries for macOS/Linux/Windows, each for gcc/mingw-gcc/clang and I have common tests running on all these variants; now that I know what the details are, I can adjust the scripts to accommodate for these specifics.

iains commented 5 months ago

I implemented the ld64.lld change and tried it out on the GCC testsuite - with quite a lot of succeeding tests - but, unfortunately [with llvm-17 lld]:

ld64.lld: warning: Option `-r' is not yet implemented. Stay tuned...

which is a show-stopper for production use (perhaps it's implemented in llvm-18, I did not yet check, but clearly there is still some way to go)

ilg-ul commented 5 months ago

I don't know how the tests are organised, but I'm thinking that GCC's responsibility should be to properly invoke lld, not to also check its functionality.

iains commented 5 months ago

Sure .. the point I was making is that it should be regarded as experimental (so that you should not be relying on -fuse-ld=lld to fix problems, better instead to report the problems to GCC Bugzilla)

iains commented 4 months ago

the use of correct (ld64.lld) lld is fixed with the latest development version (https://github.com/iains/gcc-darwin-arm64/tree/master-wip-apple-si-on-1667962ae75). It remains 'very experimental' and is not a supported linker to bootstrap GCC (yet), hopefully the Mach-O lld folks will iron out the wrinkles (unfortunately, I do not have any spare time to contribute there).