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

boehm-gc: fix cross build of dependent packages #54402

Merged
merged 1 commit into from Feb 20, 2019

Conversation

lopsided98
Copy link
Contributor

@lopsided98 lopsided98 commented Jan 21, 2019

boehm-gc tries to detect whether the compiler supports C11 atomic intrinsics, and if not, it links to libatomic_ops to provide equivalent functionality. This check requires running a program on the host architecture, so it cannot be done when cross-compiling. In that case, the configure script assumes the intrinsics are not available and links to libatomic_ops. This is not new behavior, but the upgrade to 8.0.2 includes ivmai/bdwgc@02a44ee, which requires that if boehm-gc links to libatomic_ops, all packages that depend on boehm-gc must also link to libatomic_ops. This broke cross-compiled guile, nix and probably anything else that depends on boehm-gc.

One solution is to make libatomic_ops a propagatedBuildInput, but this is not really a great solution because most of the time libatomic_ops is not really needed. On x86_64-linux, armv6l-linux, armv7l-linux and aarch64-linux, native builds of boehm-gc do not link to libatomic_ops and therefore it shouldn't be needed when cross-compiling to those platforms. I do not know of any supported architectures that do not have C11 atomic intrinsics, except that armv6l-linux requires libatomic (different from libatomic_ops) to support certain intrinsics. AFAICT, libatomic is not needed for boehm-gc.

Alternatively (and what this PR does), we can just unconditionally disable libatomic_ops when cross-compiling. This could possibly "break" (it would already be broken because of the missing dep) a platform I have not tested, but seems cleaner than propagating libatomic_ops.

Note that this problem is not specific to cross-compiling, any platform that actually needs libatomic_ops will be broken natively right now because of the missing propagation. We should actually remove libatomic_ops as a build input altogether, since it can't work correctly unless it is propagated. The only reason I didn't do that in this PR is that it would cause a mass rebuild.

I also removed the dontStrip line, which I believe is a relic from the past.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

The configure script can't detect whether C11 atomic intrinsics are available
when cross-compiling, so it links to libatomic_ops, which has to be propagated
to all dependencies. To avoid this, assume that the atomic intrinsics are
available.
@lopsided98
Copy link
Contributor Author

I got rid of the dontStrip commit because I realized it would case a mass rebuild. I'll add it in a different PR when I remove libatomic_ops from buildInputs.

@dtzWill
Copy link
Member

dtzWill commented Feb 3, 2019

FWIW I fixed a related (but in a way entirely unrelated) issue when cross-compiling boehmgc w/musl: #55133 .

I think builtin atomic support is reasonable assumption, and libatomic_ops's README.md opens with:

IN NEW CODE, PLEASE USE C11 OR C++14 STANDARD ATOMICS INSTEAD OF THIS PACKAGE.

I'm slightly uncertain about how a gc using C11 atomics would interact with C++ atomics or gcc/clang atomic compatibility. I suppose those issues are the same either way, that is unless libatomic_ops does something clever (so the atomics are only used for internal consistency)? Anyway this hopefully is not a concern and one I'm only even considering from reading discussions of similar on llvm/libc++ development (where circumstances are perhaps different).

On the "random things I read but aren't likely our situation but just in case" earlier this month glibc
moved to using builtin atomics (replacing routines that weren't libatomic_ops) and then reverted due to performance regressions on POWER and aarch32:
https://sourceware.org/ml/libc-alpha/2019-01/msg00381.html

So perhaps worth keeping an eye on. All that said I think this is fine, and all those concerns above aren't valid if this only aligns with non-cross behavior which is what it sounds like O:).

@@ -35,7 +35,12 @@ stdenv.mkDerivation rec {
configureFlags =
[ "--enable-cplusplus" ]
++ lib.optional enableLargeConfig "--enable-large-config"
++ lib.optional (stdenv.hostPlatform.libc == "musl") "--disable-static";
++ lib.optional (stdenv.hostPlatform.libc == "musl") "--disable-static"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I could remember why this is here, I'm not sure it's needed anymore but it's not hurting anyone as-is... xD

@lopsided98
Copy link
Contributor Author

Yes, C11 atomics are already being used in native builds.

@matthewbauer matthewbauer merged commit 55757a0 into NixOS:master Feb 20, 2019
@lopsided98 lopsided98 deleted the boehm-gc-cross-fix branch February 20, 2019 04:30
@c0bw3b c0bw3b changed the title beohm-gc: fix cross build of dependent packages boehm-gc: fix cross build of dependent packages Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants