Recent

Author Topic: Linker error with LLVM 15.0  (Read 3061 times)

ChrisR

  • Full Member
  • ***
  • Posts: 247
Linker error with LLVM 15.0
« on: September 25, 2023, 03:37:09 pm »
All Lazarus MacOS projects (even new ones created with RC1) do not compile with MacOS Sonoma RC with the linker error:

-macosx_version_min has been renamed to -macos_version_min

Using `ld -v` reports the linker is part of LLVM 15.0.

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Linker error with LLVM 15.0
« Reply #1 on: September 25, 2023, 04:25:44 pm »
How then lazarus is built on your machine ?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1067
Re: Linker error with LLVM 15.0
« Reply #2 on: September 25, 2023, 08:36:02 pm »
That's a pain. In clang they "fixed" this by changing the passed option name based on the name of the linker binary: https://reviews.llvm.org/D92037
Code: [Select]
      // FIXME: Remove lld.darwinnew here once it's the only MachO lld.
      if (LinkerIsLLD)
        *LinkerIsLLD = UseLinker == "lld" || UseLinker == "lld.darwinnew";
      if (LinkerIsLLDDarwinNew)
        *LinkerIsLLDDarwinNew = UseLinker == "lld.darwinnew";
 
And the FIXME suggests even that ugly hack won't keep working indefinitely.
« Last Edit: September 25, 2023, 08:38:42 pm by Jonas Maebe »

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Linker error with LLVM 15.0
« Reply #3 on: September 26, 2023, 01:36:49 pm »
Just to clarify, I downloaded the Lazarus 3.0 RC 1 files, including the fpc sources. Lazarus is provided as a binary - I am unable to compile Lazarus as the linker gives an error.

Indeed, even the most basic fpc program (removing Lazarus from the equation) fails to compile. Consider:

program Hello;
begin
  writeln ('Hello, world.');
end.

This generates the following error:

% fpc hello.pas
Free Pascal Compiler version 3.2.2 [2021/05/16] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling hello.pas
Assembling hello
Linking hello
ld: warning: -multiply_defined is obsolete
-macosx_version_min has been renamed to -macos_version_min
ld: library 'c' not found
An error occurred while linking
hello.pas(3,27) Error: Error while linking
hello.pas(3,27) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Further system details are

% clang -v
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
% uname -a
Darwin chriss-Virtual-Machine.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:40:03 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_VMAPPLE arm64
% xcode-select -v
xcode-select version 2399.


It is worth noting that I can compile large C programs fine - for example if you download my dcm2niix tool from Github you can simply run 'make' from the 'console' folder to compile and link from source.
« Last Edit: September 26, 2023, 01:44:32 pm by ChrisR »

geraldholdsworth

  • Full Member
  • ***
  • Posts: 214
Re: Linker error with LLVM 15.0
« Reply #4 on: October 02, 2023, 09:33:52 am »
I've got something similar. My install has suddenly started reporting, on every build:
Code: [Select]
Compile Project, Mode: Default, Target: lib/Debug/x86_64-darwin/Logger: Success, Errors: 4
Error: ld: warning: -multiply_defined is obsolete
Error: -macosx_version_min has been renamed to -macos_version_min
Error: ld: warning: ignoring duplicate libraries: '-lc'
Error: ld: warning: no platform load command found in '/Users/geraldholdsworth/Library/Mobile Documents/com~apple~CloudDocs/Programming/Lazarus/Logger/lib/Debug/x86_64-darwin/Logger.or', assuming: macOS
But it still builds/compiles and links. I'm on Ventura (although it's wanting to upgrade to Sonoma) with the x86_64 version of Lazarus 2.2.6. Not sure why these errors started appearing, or how to stop them.

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Linker error with LLVM 15.0
« Reply #5 on: October 05, 2023, 02:43:34 am »
So I did find a solution. I created a fpc configuration file:
 nano ~/.fpc.cfg
and added the line:
 
-Fu/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX..platform/Developer/SDKs/MacOSX.sdk/usr/lib/

This allows the linker to find the file `libc.tbd` I determined this by running fpc in verbose mode on a machine that did compile my code successfully:
 fpc hello.pas -k-t

Note that with this change, I do get warnings, but my code compiles correctly:

% fpc hello.pas
ld: warning: -multiply_defined is obsolete
-macosx_version_min has been renamed to -macos_version_min
% ./hello
Hello, world.

As an aside, things worked fine on a machine I upgraded to LLVM15 that had previous installs of FPC/Lazarus: the issue I had was with a clean install of the new OS on a virtual machine.




mischi

  • Full Member
  • ***
  • Posts: 170
Re: Linker error with LLVM 15.0
« Reply #6 on: October 06, 2023, 05:54:22 pm »
after updating the Xcode command line tools from 14 to 15, I get linker errors in addition to the warnings, which prevent building fpc with macports. I have tried various changes to build options or even patches to source files but without success. Passing -k-w to the linker suppresses the annoying warning and makes life a bit easier. As to expect, -k-w does not resolve the error ;-)

/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/ppcx64 -Ur -Xs -O2 -n -Fux86_64 -Fusystems -Fu/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/fpcbuild-3.2.2/fpcsrc/rtl/units/x86_64-darwin -Fix86_64 -FE. -FUx86_64/units/x86_64-darwin -dRELEASE -ap -v0 -XR/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk   -dx86_64 -dGDB -dBROWSERLOG -Fux86 pp.pas
ld: warning: -multiply_defined is obsolete
-macosx_version_min has been renamed to -macos_version_min
ld: warning: pointer not aligned at _RTTI_$SYSTEM_$$_openchararray+0x16 from /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/fpcbuild-3.2.2/fpcsrc/rtl/units/x86_64-darwin/system.o
.
... skipping many alike warnings
.
ld: warning: pointer not aligned at _THREADVARLIST_$FPWIDESTRING+0xC from /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/fpcbuild-3.2.2/fpcsrc/rtl/units/x86_64-darwin/fpwidestring.o
ld: pointer not 4-byte aligned at __DATA_CONST+0x9A6, fix alignment or disable chained fixups
An error occurred while linking
pp.pas(252,36) Error: Error while linking
pp.pas(252,36) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

This is building ppca64 on an M1 Macbook with macOS 13, Xcode command line tools 15 starting with ppcx64 as bootstrap compiler at the cycling stage.  Any help?

geraldholdsworth

  • Full Member
  • ***
  • Posts: 214
Re: Linker error with LLVM 15.0
« Reply #7 on: October 06, 2023, 05:56:46 pm »
Do you know that you can have SDKs from previous macOS versions and specifically point to them instead of using the default one?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1067
Re: Linker error with LLVM 15.0
« Reply #8 on: October 06, 2023, 08:55:34 pm »
So I did find a solution. I created a fpc configuration file:
 nano ~/.fpc.cfg
and added the line:
 
-Fu/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX..platform/Developer/SDKs/MacOSX.sdk/usr/lib/
This generally means that the Xcode command line tools are not installed. Does sudo xcode-select --install not solve it as well?

mischi

  • Full Member
  • ***
  • Posts: 170
Re: Linker error with LLVM 15.0
« Reply #9 on: October 16, 2023, 04:36:01 pm »
after updating the Xcode command line tools from 14 to 15, I get linker errors in addition to the warnings, which prevent building fpc with macports. I have tried various changes to build options or even patches to source files but without success. Passing -k-w to the linker suppresses the annoying warning and makes life a bit easier. As to expect, -k-w does not resolve the error ;-)

/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/ppcx64 -Ur -Xs -O2 -n -Fux86_64 -Fusystems -Fu/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/fpcbuild-3.2.2/fpcsrc/rtl/units/x86_64-darwin -Fix86_64 -FE. -FUx86_64/units/x86_64-darwin -dRELEASE -ap -v0 -XR/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk   -dx86_64 -dGDB -dBROWSERLOG -Fux86 pp.pas
ld: warning: -multiply_defined is obsolete
-macosx_version_min has been renamed to -macos_version_min
ld: warning: pointer not aligned at _RTTI_$SYSTEM_$$_openchararray+0x16 from /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/fpcbuild-3.2.2/fpcsrc/rtl/units/x86_64-darwin/system.o
.
... skipping many alike warnings
.
ld: warning: pointer not aligned at _THREADVARLIST_$FPWIDESTRING+0xC from /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_fpc/fpc/work/fpcbuild-3.2.2/fpcsrc/rtl/units/x86_64-darwin/fpwidestring.o
ld: pointer not 4-byte aligned at __DATA_CONST+0x9A6, fix alignment or disable chained fixups
An error occurred while linking
pp.pas(252,36) Error: Error while linking
pp.pas(252,36) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

This is building ppca64 on an M1 Macbook with macOS 13, Xcode command line tools 15 starting with ppcx64 as bootstrap compiler at the cycling stage.  Any help?

I finally found out that the problem shows up with the option -WM13.0. Replacing it by -WM11.0 resolved it.

 

TinyPortal © 2005-2018