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

Configuring libgomp fails when building a cross-compiler for x86_64-linux-musl host #85

Closed giordano closed 2 years ago

giordano commented 2 years ago

Following up from #84, after solving that issue (it turned out to be an upstream one), now I'm stuck at configuring libgomp:

checking whether the C compiler works... no
configure: error: in `/workspace/srcdir/gcc_build/aarch64-apple-darwin20/libgomp':
configure: error: C compiler cannot create executables
See `config.log' for more details

The config.log shows:

configure:3917: checking whether the C compiler works
configure:3939: /workspace/srcdir/gcc_build/./gcc/xgcc -B/workspace/srcdir/gcc_build/./gcc/ -B/workspace/destdir/aarch64-apple-darwin20/bin/ -B/workspace/destdir/aarch64-apple-darwin20/lib/ -isystem /workspace\
/destdir/aarch64-apple-darwin20/include -isystem /workspace/destdir/aarch64-apple-darwin20/sys-include    -g -O2   conftest.c  >&5
ld: warning: building for macOS, but linking in object file (/tmp/ccdfigOA.o) built for iOS
/workspace/srcdir/gcc_build/./gcc/dsymutil: exec: line 114: a.out: not found
collect2: fatal error: /workspace/srcdir/gcc_build/./gcc/dsymutil returned 127 exit status
compilation terminated.
configure:3943: $? = 1
configure:3981: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU Offloading and Multi Processing Runtime Library"
| #define PACKAGE_TARNAME "libgomp"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU Offloading and Multi Processing Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgomp/"
| #define PACKAGE "libgomp"
| #define VERSION "1.0"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:3986: error: in `/workspace/srcdir/gcc_build/aarch64-apple-darwin20/libgomp':
configure:3988: error: C compiler cannot create executables

It looks like this is trying to run a foreign executable built for the target (!= host == build) platform.

iains commented 2 years ago

configure:3939: /workspace/srcdir/gcc_build/./gcc/xgcc -B/workspace/srcdir/gcc_build/./gcc/ -B/workspace/destdir/aarch64-apple-darwin20/bin/ -B/workspace/destdir/aarch64-apple-darwin20/lib/ -isystem /workspace\
/destdir/aarch64-apple-darwin20/include -isystem /workspace/destdir/aarch64-apple-darwin20/sys-include    -g -O2   conftest.c  >&5
ld: warning: building for macOS, but linking in object file (/tmp/ccdfigOA.o) built for iOS
/workspace/srcdir/gcc_build/./gcc/dsymutil: exec: line 114: a.out: not found
collect2: fatal error: /workspace/srcdir/gcc_build/./gcc/dsymutil returned 127 exit status

It looks like this is trying to run a foreign executable built for the target (!= host == build) platform.

No, I don't think so, the complaint is that the .o file has been built with an identifier that is for iOS (Darwin object files can embed markers for the target system) but the linker knows you are trying to link for macOS ...

... so please take a piece of trivial code (the config.c there is an empty main() function)

and do (in the build dir)

./gcc/xgcc -Bgcc /path/to/source/xxx.c -save-temps -v -Wl,-v and post the output.

You are using "binutils" from the LLVM project, right - or do you have a build of cctools and/or ld64?

if not using cctools/ld64

giordano commented 2 years ago

No, I don't think so

You're right, I was confused by something I found in dsymutil: at line 114 there is exec $original ${1+"$@"}, where $original is empty and ${1+"$@"} is a.out, so I got it wrong what exec a.out would do. I presume the fact that $original is empty is wrong?

and post the output.

sandbox:${WORKSPACE}/srcdir/gcc_build/aarch64-apple-darwin20/libgomp # /workspace/srcdir/gcc_build/./gcc/xgcc -B/workspace/srcdir/gcc_build/./gcc/ conftest.c -save-temps -v -Wl,-v                               
Reading specs from /workspace/srcdir/gcc_build/./gcc/specs                                                                                                                                                        
COLLECT_GCC=/workspace/srcdir/gcc_build/./gcc/xgcc                                                                                                                                                                
COLLECT_LTO_WRAPPER=/workspace/srcdir/gcc_build/./gcc/lto-wrapper                                                                                                                                                 
Target: aarch64-apple-darwin20                                                                                                                                                                                    
Configured with: /workspace/srcdir/gcc-darwin-arm64/configure --prefix=/workspace/destdir --target=aarch64-apple-darwin20 --host=x86_64-linux-musl --build=x86_64-linux-musl --disable-multilib --disable-werror -
-enable-shared --enable-host-shared --enable-threads=posix --with-sysroot=/workspace/destdir/aarch64-apple-darwin20/sys-root --program-prefix=aarch64-apple-darwin20- --disable-bootstrap --with-ld=/workspace/des
tdir/bin/aarch64-apple-darwin20-ld --with-as=/workspace/destdir/bin/aarch64-apple-darwin20-as --enable-lto --enable-plugin --enable-languages=c,c++,fortran,objc,obj-c++                                          
Thread model: posix                                                                                                                                                                                               
Supported LTO compression algorithms: zlib                                                                                                                                                                        
gcc version 12.0.1 20220219 (experimental) (GCC)                                                                                                                                                                  
COLLECT_GCC_OPTIONS='-B' '/workspace/srcdir/gcc_build/./gcc/' '-save-temps' '-v' '-mmacosx-version-min=11.0' '-asm_macosx_version_min=11.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a-'     
 /workspace/srcdir/gcc_build/./gcc/cc1 -E -quiet -v -iprefix /workspace/srcdir/gcc_build/gcc/../lib/gcc/aarch64-apple-darwin20/12.0.1/ -isystem /workspace/srcdir/gcc_build/./gcc/include -isystem /workspace/srcd
ir/gcc_build/./gcc/include-fixed -D__DYNAMIC__ conftest.c -fPIC -mmacosx-version-min=11.0 -mlittle-endian -mabi=lp64 -fpch-preprocess -o a-conftest.i                                                             
ignoring nonexistent directory "/workspace/srcdir/gcc_build/gcc/../lib/gcc/aarch64-apple-darwin20/12.0.1/include"                                                                                                 
ignoring nonexistent directory "/workspace/srcdir/gcc_build/gcc/../lib/gcc/aarch64-apple-darwin20/12.0.1/include-fixed"                                                                                           
ignoring nonexistent directory "/workspace/srcdir/gcc_build/gcc/../lib/gcc/aarch64-apple-darwin20/12.0.1/../../../../aarch64-apple-darwin20/include"                                                              
ignoring nonexistent directory "/workspace/srcdir/gcc_build/gcc/../lib/gcc/../../lib/gcc/aarch64-apple-darwin20/12.0.1/include"                                                                                   
ignoring nonexistent directory "/workspace/srcdir/gcc_build/gcc/../lib/gcc/../../lib/gcc/aarch64-apple-darwin20/12.0.1/include-fixed"                                                                             
ignoring nonexistent directory "/workspace/srcdir/gcc_build/gcc/../lib/gcc/../../lib/gcc/aarch64-apple-darwin20/12.0.1/../../../../aarch64-apple-darwin20/include"                                                
ignoring nonexistent directory "/workspace/destdir/aarch64-apple-darwin20/sys-root/Library/Frameworks"                                                                                                            
#include "..." search starts here:
#include <...> search starts here:
 /workspace/srcdir/gcc_build/./gcc/include
 /workspace/srcdir/gcc_build/./gcc/include-fixed
 /workspace/destdir/aarch64-apple-darwin20/sys-root/usr/local/include
 /workspace/destdir/aarch64-apple-darwin20/sys-root/usr/include
 /workspace/destdir/aarch64-apple-darwin20/sys-root/System/Library/Frameworks
End of search list.
COLLECT_GCC_OPTIONS='-B' '/workspace/srcdir/gcc_build/./gcc/' '-save-temps' '-v' '-mmacosx-version-min=11.0' '-asm_macosx_version_min=11.0' '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a-'
 /workspace/srcdir/gcc_build/./gcc/cc1 -fpreprocessed a-conftest.i -fPIC -quiet -dumpdir a- -dumpbase conftest.c -dumpbase-ext .c -mmacosx-version-min=11.0 -mlittle-endian -mabi=lp64 -version -o a-conftest.s
GNU C17 (GCC) version 12.0.1 20220219 (experimental) (aarch64-apple-darwin20)
        compiled by GNU C version 10.3.1 20211027, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C17 (GCC) version 12.0.1 20220219 (experimental) (aarch64-apple-darwin20)
        compiled by GNU C version 10.3.1 20211027, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: c5bcea9a05eede9b0ec2540bf6ac7e6f
COLLECT_GCC_OPTIONS='-B' '/workspace/srcdir/gcc_build/./gcc/' '-save-temps' '-v' '-mmacosx-version-min=11.0'  '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a-'
 /workspace/destdir/bin/aarch64-apple-darwin20-as -arch arm64 -v -o a-conftest.o a-conftest.s
clang version 8.0.0 
Target: aarch64-apple-darwin
Thread model: posix
InstalledDir: /workspace/aarch64-apple-darwin20/destdir/bin
 "/workspace/aarch64-apple-darwin20/destdir/bin/clang-8" -cc1as -triple arm64-apple-ios5.0.0 -filetype obj -main-file-name a-conftest.s -target-cpu cyclone -target-feature +fp-armv8 -target-feature +neon -targe
t-feature +crypto -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -fdebug-compilation-dir /workspace/srcdir/gcc_build/aarch64-apple-darwin20/libgomp -dwarf-debug-producer cl
ang version 8.0.0  -dwarf-version=2 -mrelocation-model pic -o a-conftest.o a-conftest.s
COMPILER_PATH=/workspace/srcdir/gcc_build/./gcc/
LIBRARY_PATH=/workspace/srcdir/gcc_build/./gcc/
COLLECT_GCC_OPTIONS='-B' '/workspace/srcdir/gcc_build/./gcc/' '-save-temps' '-v' '-mmacosx-version-min=11.0'  '-nodefaultexport' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a.'
 /workspace/srcdir/gcc_build/./gcc/collect2 -syslibroot /workspace/destdir/aarch64-apple-darwin20/sys-root/ -dynamic -arch arm64 -macosx_version_min 11.0 -o a.out -L/workspace/srcdir/gcc_build/./gcc a-conftest.
o -v -lemutls_w -lgcc -lSystem -lgcc -no_compact_unwind
collect2 version 12.0.1 20220219 (experimental)
/workspace/destdir/bin/aarch64-apple-darwin20-ld -syslibroot /workspace/destdir/aarch64-apple-darwin20/sys-root/ -dynamic -arch arm64 -macosx_version_min 11.0 -o a.out -L/workspace/srcdir/gcc_build/./gcc a-conf
test.o -v -lemutls_w -lgcc -lSystem -lgcc -no_compact_unwind
@(#)PROGRAM:ld  PROJECT:ld64-530
BUILD 20:32:09 Mar  5 2022
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
        /workspace/srcdir/gcc_build/./gcc
        /workspace/destdir/aarch64-apple-darwin20/sys-root/usr/lib
        /workspace/destdir/aarch64-apple-darwin20/sys-root/usr/local/lib
Framework search paths:
        /workspace/destdir/aarch64-apple-darwin20/sys-root/System/Library/Frameworks/
ld: warning: building for macOS, but linking in object file (a-conftest.o) built for iOS

You are using "binutils" from the LLVM project, right - or do you have a build of cctools and/or ld64?

We build cctools, in particular commit https://github.com/tpoechtrager/cctools-port/commit/634a084377ee2e2932c66459b0396edf76da2e9f

iains commented 2 years ago

"/workspace/aarch64-apple-darwin20/destdir/bin/clang-8" -cc1as -triple arm64-apple-ios5.0.0

^^ this is your problem

something about the /workspace/destdir/bin/aarch64-apple-darwin20-as does not understand that you are building for macOS now - and it is generating a binary marked for iOS...

... and then the linker is (quite correctly) complaining.

This is nothing to do with the compiler

giordano commented 2 years ago

Ok, the problem which was causing the error reported above was that dsymutil couldn't be found, which was also indicated by the warning

WARNING: dsymutil is a required tool for this system, but not found

in config.log. It never occurred with all previous builds of GCC for macOS we've done, but it's easy to set the environment variable DSYMUTIL_FOR_TARGET to tell gcc where the utility is. With this, I can finally successfully build a newer version of GCC for this platform!

However I still need to test whether it produces working binaries and I'll look into the as warnings, but I see the same warnings also in the log of the old build of this fork of GCC, which has been working well for us so far.

Thanks for the support and sorry for the noise, however discussing here has been extremely helpful for pointing me into the right directions!

iains commented 2 years ago

For dsymutil, you should be able to pick that up from the LLVM build you're using.

I recently(-ish) added the --with-dsymutil= configuration option to match the --with-as= and --with-ld=.

The environment variables will work during the build, but if you want the built compiler to be specific about which version it uses - the --with-{as, ld,dsymutil_= versions lock the specified one into the built compiler.

good luck.