ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.7k stars 415 forks source link

x86 Mac OS Sonoma Compile Error with XCode 15 and #4454

Closed KieranP closed 11 months ago

KieranP commented 1 year ago

Upgraded from Ventura to Sonoma. Now getting the following error trying to compile code that used to work:

ponyc -d -b play
Building builtin -> /usr/local/Cellar/ponyc/0.56.2/packages/builtin
Building . -> /Users/kieran/Work/gol_implementations/pony
Building collections -> /usr/local/Cellar/ponyc/0.56.2/packages/collections
Building pony_test -> /usr/local/Cellar/ponyc/0.56.2/packages/pony_test
Building time -> /usr/local/Cellar/ponyc/0.56.2/packages/time
Building random -> /usr/local/Cellar/ponyc/0.56.2/packages/random
Building itertools -> /usr/local/Cellar/ponyc/0.56.2/packages/itertools
Building format -> /usr/local/Cellar/ponyc/0.56.2/packages/format
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Writing ./play.o
Linking ./play
ld: Missing -platform_version option
Error:
unable to link: ld -execute -arch x86_64 -o ./play ./play.o -L"/usr/local/Cellar/ponyc/0.56.2/bin/" -L"/usr/local/Cellar/ponyc/0.56.2/bin/../lib/native" -L"/usr/local/Cellar/ponyc/0.56.2/bin/../packages" -L"/usr/local/lib"  -lponyrt -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem
SeanTAllen commented 1 year ago

@KieranP we don't have access to Sonoma machines. Can you see if you can figure out what this new required option is and tomorrow when I'm back, I can point you to where it would be added and you can open a PR?

SeanTAllen commented 1 year ago

The new option would go in link_exe in genexe.c

KieranP commented 1 year ago

@SeanTAllen From the man ld docs:

     -platform_version platform min_version sdk_version
             This is set to indicate the platform, oldest supported version of that platform that output is to be used on, and the SDK that the output was built against.  platform is a numeric value as defined in <mach-o/loader.h>, or it may be one of the following
             strings:
             • macos
             • ios
             • tvos
             • watchos
             • bridgeos
             • visionos
             • xros
             • mac-catalyst
             • ios-simulator
             • tvos-simulator
             • watchos-simulator
             • visionos-simulator
             • xros-simulator
             • driverkit
             Specifying a newer min or SDK version enables the linker to assume features of that OS or SDK in the output file. The format of min_version and sdk_version is a version number such as 10.13 or 10.14
KieranP commented 1 year ago

@SeanTAllen Looks like this might not just be a Sonoma issue, but introduced with the newest Xcode 15 release.

If I compile my app with pony up to the failed ld command, then re-run the ld command with platform_version, it works:

ld -execute -arch x86_64 -o ./play ./play.o -L"/usr/local/Cellar/ponyc/0.56.2/bin/" -L"/usr/local/Cellar/ponyc/0.56.2/bin/../lib/native" -L"/usr/local/Cellar/ponyc/0.56.2/bin/../packages" -L"/usr/local/lib"  -lponyrt -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem -platform_version macos "13.0.0" "0.0.0"
SeanTAllen commented 1 year ago

Do you feel comfortable opening a PR for that?

Without testing on Apple Silicon, I'd want to keep it to x86 only for now as we have CI for it and we can wait for confirmation on Apple Silicon. If it doesn't cause issues with our CI which is an earlier Xcode, we can leave as general. Otherwise, we'll need to make it conditional on more than CPU.

d-led commented 1 year ago

can confirm on Ventura too.

Re-running ld with -platform_version macos "13.0.0" "0.0.0" produces a binary, however, also brings out a warning:

ld: warning: no platform load command found in '/Users/....my.o', assuming: macOS`

interesting reference found: the "old" linker behaviour can be switched back to: -ld_classic

via blender

SeanTAllen commented 1 year ago

@d-led are you comfortable with opening a PR to try out the "classic"? option to see if works in CI (assuming it works for you locally). CI has an older xcode so hopefully we can work across xcode versions.

d-led commented 1 year ago

@SeanTAllen not sure I'll manage it in a timely fashion, so if anyone has a ready environment, don't wait for me. Will read genexe.c a bit while libs build.

Upd: make build suffers from the same problem while linking the tests: ld: Missing -platform_version option 😄

d-led commented 1 year ago

I guess, the impact is not trivial. E.g. depending on which version of ld or other linker is used, -ld_classic might break the build for those linkers that don't support that flag

SeanTAllen commented 1 year ago

@d-led if you can open a PR that fixes for you, CI will catch if it isn't backwards compatible. That will eliminate any guessing.

SeanTAllen commented 1 year ago

@ergl @jemc can either of you address this?

d-led commented 1 year ago

make build and libponyc.tests succeed at least locally with the two changes. It's a quick fix but hopefully in the right places

SeanTAllen commented 1 year ago

It appears -ld_classic results in a link error on earlier xcode versions.

SeanTAllen commented 1 year ago

-platform_version macos "13.0.0" "0.0.0"

at least builds and links. what is a reasonable sdk version for us to be putting in?

SeanTAllen commented 1 year ago

@d-led I'm not getting any warnings in the CI logs for the change like this: https://github.com/ponylang/ponyc/pull/4466. Can you check with that change if you get the "ld: warning: no platform load command found in '/Users/....my.o', assuming: macOS`" warning?

d-led commented 1 year ago

-platform_version macos "13.0.0" "0.0.0" at least builds and links. what is a reasonable sdk version for us to be putting in?

unfortunately, I don't know. Perhaps, go with that proposal?

SeanTAllen commented 1 year ago

@d-led @KieranP can either of you test the change on this branch/PR and verify if that installation works for you with XCode 15?

https://github.com/ponylang/ponyc/pull/4466/files

jemc commented 12 months ago

I'm having trouble reproducing this on the M1 Mac mini.

I am on Sonoma (version 14) with version 15 of XCode CLI tools installed:

 > pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version
version: 15.0.0.0.1.1694021235
> sw_vers
ProductName:        macOS
ProductVersion:     14.0
BuildVersion:       23A344

Building a Pony program succeeds, including the link step, which I can print by increasing verbosity:

> build/debug/ponyc examples/ring --verbose=3
Building builtin -> /Users/main/Documents/code/ponyc/packages/builtin
Building examples/ring -> /Users/main/Documents/code/ponyc/examples/ring
Building collections -> /Users/main/Documents/code/ponyc/packages/collections
Building pony_test -> /Users/main/Documents/code/ponyc/packages/pony_test
Building time -> /Users/main/Documents/code/ponyc/packages/time
Building random -> /Users/main/Documents/code/ponyc/packages/random
Program signature: 08518DCBB88DEC0B049B3D937E814C8897D0F2499E32A0774EDA5BC3AD25A456ACCF5BF0C6FF8559EF5AF12E8CD9B1994F7D90A0B9D43B62A48376196C403B2B

Group 0
Signature: 303AC86CA35D8FC6E5FAD0ED1721C946CA087E7029FC4D5034FC6D6BBA2523E5830FDDA3C3312FFD05C2CDAB76A046A020BACFFD4EFE602C364AB525D09CFF2B
Members:
  builtin
Dependencies:

Group 1
Signature: 0C9E6903C8D66340B6787EE6FEE28B4E0430B07147FAF02CB08868DC1FD43D5B1CF68F4446A17A041A7A77A2EA3787C173EFC6CFBF33468CA0544827AF697A4D
Members:
  collections
  random
  time
  pony_test
Dependencies:
  builtin

Group 2
Signature: CC273648BAE9BFA2344E19CC83A2F3FBF7104CBD1B8032F397CA18C8BF3C883A6C6977D23AE1F368AB63EE1078EBC78FFC4EBEA81B911EBEB50AABC1E460D1E3
Members:
  ring
Dependencies:
  builtin
  collections

Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Writing ./ring.o
Linking ./ring
ld -execute -arch arm64 -o ./ring ./ring.o -L"/Users/main/Documents/code/ponyc/build/debug/" -L"/Users/main/Documents/code/ponyc/build/debug/../../packages" -L"/usr/local/lib"  -lponyrt -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem
SeanTAllen commented 12 months ago

Joe and I have a fix for this. We are getting the PR into a mergeable state.

@d-led @KieranP if you can test the 'ldclassic' branch again, that would be great.

SeanTAllen commented 12 months ago

I've updated the issue title to note that this is an X86 specific issue and that Apple Silicon is unaffected.

KieranP commented 11 months ago

@SeanTAllen I can confirm that this is now resolved in 0.57.1