Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building cgreen-runner on MacOS no longer works since switch to libbfd #288

Closed
thoni56 opened this issue Dec 31, 2021 · 5 comments
Closed

Comments

@thoni56
Copy link
Contributor

thoni56 commented Dec 31, 2021

Unfortunately MacOS is another platform that no longer makes building cgreen-runner possible after the replacement of nm by libbfd introduced in #255.

I should have checked that before merging, after all, it was I who raised the less portable nature of the libbfd solution... Although I made it work for Cygwin and MSYS2...

MacOS has two major "environments", native Darwin with Apple Clang, and Homebrew. For Homebrew libbfd seems to exist in binutils as per "usual", but I haven´t been able to build that yet. Also it ties us to GNU gcc. I don't yet know if the library formats are similar so that we could run a Apple Clang-compiled library with a GNU gcc-compiled cgreen-runner. If that is not a case, we are even less portable...

Add to that the fact that GNU gcc does not work reliably for arm64e, in my experience, and we have a problematic matrix of environments to handle.

@thoni56
Copy link
Contributor Author

thoni56 commented Jan 1, 2022

At least loading a fat Mach-O library generated from Apple Clang into a cgreen-runner build using gcc-11 for x86_64 does work.

That means that building the libbfd version of cgreen-runner with "real" gcc from Homebrew would probably allow a user to use it on any project, even if that in itself is not using gcc. That is a small bit of good news since we are then not forcing users to have a cgreen-runner for each of the "environments".

@thoni56
Copy link
Contributor Author

thoni56 commented Jan 1, 2022

Also a GCC-11 built cgreen-runner can load and run an Apple Clang-created test library, which obviously is a fat library. So the GCC DL code seems to be able to select the correct arch to load. Amazing!

And that goes both for arm64 and x86_64 compiled versions.

So the only compatibility "problem" we have here is that GCC-11 does not compile for both architectures at the same time, but only for the "current" one.

So back to the problem of linking with libbfd, which exists in the Homebrew distributions, so it should be possible for a GCC-compiled version. Currently I get unresolved linkage trying that.

Unfortunately, I have not been able to find anything similar to libbfd for Apple Clang.

@thoni56
Copy link
Contributor Author

thoni56 commented Jan 1, 2022

libbfd is available in Homebrew (binutils) but currently, at least, it also requires linking with libiberty which isn't available unless you reinstall binutils with --enable-install-libiberty as per the README.md (or https://stackoverflow.com/a/65978315/204658). This is a bummer, but at least we can build on MacOS.

The good news is that it is possible to compile with Apple Clang and link with the Homebrew libraries. So that's a partial win.

The only drawback is that even if compiled with Apple Clang (which generates a fat binary) the linkage to the Homebrew libbfd will restrict loading/running libraries to the kind of the architecture you linked with.

@thoni56
Copy link
Contributor Author

thoni56 commented Mar 8, 2022

Keeping this open until there is some description on how to create a fat binary and library, probably by building on both archs and combining them using lipo, as described e.g. here.

Probably, by creating a fat version of relevant Homebrew libraries, Apple Clang will automatically create fat binaries and libraries of Cgreen.

@thoni56
Copy link
Contributor Author

thoni56 commented Jul 4, 2022

Closing this since we now (without the libbfd dependency forcing us to use gcc) can use CMake to build fat binaries with

cmake -DCMAKE_OSX_ARCHITECTURES="arm64e;x86_64" -S . -B build

@thoni56 thoni56 closed this as completed Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant