MacSourcePorts / MSPBuildSystem

Mac Source Ports Build System
10 stars 3 forks source link

Xash3D fails to link on arm64 macOS 13.2.1 #4

Closed chinese-soup closed 1 year ago

chinese-soup commented 1 year ago

Hello. First all of all I wanted to thank you for the project you're making here!

The build works just fine, apart from the occasional segfaults on startup (and shutdowns), I wanted to experiment around and built it myself from source, the HLSDK builds fine, however I am hitting a linker(?) error on macOS 13.2.1 with filesystem_stdio:


[58/93] Linking build/filesystem/filesystem_stdio.dylib
[59/93] Compiling engine/common/mod_studio.c
../engine/common/net_ws.c:259:49: warning: cast from 'uint8_t (*)[4]' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
                ((struct sockaddr_in *)s)->sin_addr.s_addr = *(uint32_t *)&a->ip;
                                                              ^~~~~~~~~~~~~~~~~~
../engine/common/net_ws.c:299:4: warning: cast from 'uint8_t (*)[4]' to 'int *' increases required alignment from 1 to 4 [-Wcast-align]
                *(int *)&a->ip = ((struct sockaddr_in *)s)->sin_addr.s_addr;
                 ^~~~~~~~~~~~~
../engine/common/net_ws.c:1436:80: warning: passing 'WSAsize_t *' (aka 'int *') to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
                ret = recvfrom( net_socket, buf, sizeof( buf ), 0, (struct sockaddr *)&addr, &addr_len );
                                                                                             ^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:736:27: note: passing argument to parameter here
    socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
                          ^
../engine/common/net_ws.c:1945:97: warning: passing 'WSAsize_t *' (aka 'int *') to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
                        if( !NET_IsSocketError( getsockname( net.ip_sockets[NS_SERVER], (struct sockaddr *)&address, &namelen )))
                                                                                                                     ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:730:78: note: passing argument to parameter here
int     getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
                                                                             ^
../engine/common/net_ws.c:1968:98: warning: passing 'WSAsize_t *' (aka 'int *') to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
                        if( !NET_IsSocketError( getsockname( net.ip6_sockets[NS_SERVER], (struct sockaddr *)&address, &namelen )))
                                                                                                                      ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/socket.h:730:78: note: passing argument to parameter here
int     getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
                                                                             ^
5 warnings generated.

[60/93] Compiling engine/server/sv_save.c
[61/93] Compiling engine/common/soundlib/snd_mp3.c
[62/93] Compiling engine/common/host_state.c
ld: warning: object file (filesystem/VFileSystem009.cpp.2.o) was built for newer macOS version (13.2) than being linked (11.0)
ld: warning: ignoring file public/libpublic.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
  "_COM_DefaultExtension", referenced from:
      _FS_ParseGenericGameInfo in filesystem.c.2.o
      _FS_FindLibrary in filesystem.c.2.o
      _FS_FindFile_WAD in wad.c.2.o
      _FS_Search_WAD in wad.c.2.o
  "_COM_ExtractFilePath", referenced from:
      _FS_FindFile_WAD in wad.c.2.o
      _FS_Search_WAD in wad.c.2.o
  "_COM_FileBase", referenced from:
      _FS_FindFile_WAD in wad.c.2.o
      _FS_Search_WAD in wad.c.2.o
  "_COM_FileExtension", referenced from:
      _FS_AddGameDirectory in filesystem.c.2.o
      _FS_Rescan in filesystem.c.2.o
      _FS_FindLibrary in filesystem.c.2.o
      _FS_AddPak_Fullpath in pak.c.2.o
      _FS_AddWad_Fullpath in wad.c.2.o
      _W_TypeFromExt in wad.c.2.o
      _FS_AddZip_Fullpath in zip.c.2.o
      ...
  "_COM_FileWithoutPath", referenced from:
      _FS_AddWad_Fullpath in wad.c.2.o
  "_COM_FixSlashes", referenced from:
      CXashFS::AddSearchPath(char const*, char const*) in VFileSystem009.cpp.2.o
      CXashFS::FileExists(char const*) in VFileSystem009.cpp.2.o
      CXashFS::IsDirectory(char const*) in VFileSystem009.cpp.2.o
      CXashFS::Open(char const*, char const*, char const*) in VFileSystem009.cpp.2.o
      CXashFS::Size(char const*) in VFileSystem009.cpp.2.o
      CXashFS::GetFileTime(char const*) in VFileSystem009.cpp.2.o
      CXashFS::FindFirst(char const*, int*, char const*) in VFileSystem009.cpp.2.o
      ...
  "_COM_ParseFileSafe", referenced from:
      CXashFS::ParseFile(char*, char*, bool*) in VFileSystem009.cpp.2.o
      _FS_ParseGenericGameInfo in filesystem.c.2.o
  "_COM_StripExtension", referenced from:
      _FS_ParseGenericGameInfo in filesystem.c.2.o
  "_CRC32_Init", referenced from:
      _CRC32_File in filesystem.c.2.o
  "_CRC32_ProcessBuffer", referenced from:
      _CRC32_File in filesystem.c.2.o
  "_MD5Init", referenced from:
      _MD5_HashFile in filesystem.c.2.o
  "_MD5Update", referenced from:
      _MD5_HashFile in filesystem.c.2.o
  "_Q_atof", referenced from:
      _FS_ParseGenericGameInfo in filesystem.c.2.o
  "_Q_atoi", referenced from:
      _FS_ParseGenericGameInfo in filesystem.c.2.o
  "_Q_buildarch", referenced from:
      _FS_WriteGameInfo in filesystem.c.2.o
  "_Q_buildcommit", referenced from:
      _FS_WriteGameInfo in filesystem.c.2.o
  "_Q_buildos", referenced from:
      _FS_WriteGameInfo in filesystem.c.2.o
  "_Q_snprintf", referenced from:
      _FS_FindFile_DIR in dir.c.2.o
      _FS_Search_DIR in dir.c.2.o
      _FS_FileTime_DIR in dir.c.2.o
      _FS_OpenFile_DIR in dir.c.2.o
      _FS_FixFileCase in filesystem.c.2.o
      _FS_ParseGenericGameInfo in filesystem.c.2.o
      _FS_InitStdio in filesystem.c.2.o
      ...
  "_Q_sprintf", referenced from:
      _FS_AddGameDirectory in filesystem.c.2.o
      _FS_Open in filesystem.c.2.o
  "_Q_stricmpext", referenced from:
      _FS_ParseGenericGameInfo in filesystem.c.2.o
  "_Q_strncat", referenced from:
      _FS_FindFile in filesystem.c.2.o
  "_Q_strncpy", referenced from:
      CXashFS::AddSearchPath(char const*, char const*) in VFileSystem009.cpp.2.o
      CXashFS::FileExists(char const*) in VFileSystem009.cpp.2.o
      CXashFS::IsDirectory(char const*) in VFileSystem009.cpp.2.o
      CXashFS::Open(char const*, char const*, char const*) in VFileSystem009.cpp.2.o
      CXashFS::Size(char const*) in VFileSystem009.cpp.2.o
      CXashFS::GetFileTime(char const*) in VFileSystem009.cpp.2.o
      CXashFS::FileTimeToString(char*, int, long) in VFileSystem009.cpp.2.o
      ...
  "_Q_strnlwr", referenced from:
      _FS_AddWad_Fullpath in wad.c.2.o
  "_Q_tolower", referenced from:
      _FS_FindLibrary in filesystem.c.2.o
  "_Q_vsnprintf", referenced from:
      _FS_Printf in filesystem.c.2.o
      _FS_VPrintf in filesystem.c.2.o
  "_matchpattern", referenced from:
      _FS_Search_DIR in dir.c.2.o
      _FS_Search_PAK in pak.c.2.o
      _FS_Search_WAD in wad.c.2.o
      _FS_Search_ZIP in zip.c.2.o
  "_va", referenced from:
      CXashFS::CreateDirHierarchy(char const*, char const*) in VFileSystem009.cpp.2.o
      CXashFS::AddPackFile(char const*, char const*) in VFileSystem009.cpp.2.o
      _FS_ParseGenericGameInfo in filesystem.c.2.o
      _FS_AddGameHierarchy in filesystem.c.2.o
      _FS_Rescan in filesystem.c.2.o
      _FS_InitStdio in filesystem.c.2.o
      _FS_GetDiskPath in filesystem.c.2.o
      ...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

EDIT: with -v there's additional output:

* Node /Users/unko/repos/xashbs/xash3d-fwgs/build/engine/common/whereami.c.2.o is created more than once (full message on 'waf -v -v'). The task generators are:
  1. 'filesystem_stdio' in /Users/unko/repos/xashbs/xash3d-fwgs/filesystem
  2. 'xash' in /Users/unko/repos/xashbs/xash3d-fwgs/engine
If you think that this is an error, set no_errcheck_out on the task instance
Waf: Leaving directory `/Users/unko/repos/xashbs/xash3d-fwgs/build'
Build failed
 -> task in 'filesystem_stdio' failed with exit status 1: 
    {task 4395008288: cxxshlib VFileSystem009.cpp.2.o,dir.c.2.o,filesystem.c.2.o,pak.c.2.o,wad.c.2.o,watch.c.2.o,zip.c.2.o,whereami.c.2.o -> filesystem_stdio.dylib}
['/usr/bin/clang++', '-mmacosx-version-min=10.9', '-dynamiclib', '-dynamiclib', 'filesystem/VFileSystem009.cpp.2.o', 'filesystem/dir.c.2.o', 'filesystem/filesystem.c.2.o', 'filesystem/pak.c.2.o', 'filesystem/wad.c.2.o', 'filesystem/watch.c.2.o', 'filesystem/zip.c.2.o', 'engine/common/whereami.c.2.o', '-o/Users/unko/repos/xashbs/xash3d-fwgs/build/filesystem/filesystem_stdio.dylib', '-Lpublic', '-lpublic']

Environment:

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.3.0

Darwin asdf.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64

❯ xcodebuild -version 
Xcode 14.2
Build version 14C18

Could you help me with any clues as to what might be wrong? Thanks!

chinese-soup commented 1 year ago

Never mind, it was an ar(1) issue where clang doesn't like GNU binutils. As a workaround I didn't uninstall binutils (since Xash still needs objcopy, but just renamed /opt/homebrew/opt/binutils/bin/ar to /opt/homebrew/opt/binutils/bin/ar.gnu)

See here for more info: https://stackoverflow.com/a/74159799