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

pkgsMusl.ocamlPackages.ocaml: -r and -pie may not be used together #124476

Closed
nomeata opened this issue May 26, 2021 · 8 comments
Closed

pkgsMusl.ocamlPackages.ocaml: -r and -pie may not be used together #124476

nomeata opened this issue May 26, 2021 · 8 comments

Comments

@nomeata
Copy link
Contributor

nomeata commented May 26, 2021

It used to be possible to build ocaml (it is possible on 20.09), but these days it fails with:

$ nix-build -A pkgsMusl.ocamlPackages.ocaml
…
../../ocamlopt.opt -g -nostdlib -I ../../stdlib -strict-sequence -principal -absname -w +a-4-9-40-41-42-44-45-48-66 -warn-error A -bin-annot -safe-string -strict-formats -I byte -function-sections -I native -pack -o native/dynlink_compilerlibs.cmx dynlink_compilerlibs/binutils.cmx dynlink_compilerlibs/config.cmx dynlink_compilerlibs/build_path_prefix_map.cmx dynlink_compilerlibs/misc.cmx dynlink_compilerlibs/identifiable.cmx dynlink_compilerlibs/numbers.cmx dynlink_compilerlibs/arg_helper.cmx dynlink_compilerlibs/clflags.cmx dynlink_compilerlibs/profile.cmx dynlink_compilerlibs/consistbl.cmx dynlink_compilerlibs/terminfo.cmx dynlink_compilerlibs/warnings.cmx dynlink_compilerlibs/local_store.cmx dynlink_compilerlibs/load_path.cmx dynlink_compilerlibs/int_replace_polymorphic_compare.cmx dynlink_compilerlibs/location.cmx dynlink_compilerlibs/longident.cmx dynlink_compilerlibs/docstrings.cmx dynlink_compilerlibs/syntaxerr.cmx dynlink_compilerlibs/ast_helper.cmx dynlink_compilerlibs/ast_mapper.cmx dynlink_compilerlibs/attr_helper.cmx dynlink_compilerlibs/builtin_attributes.cmx dynlink_compilerlibs/ident.cmx dynlink_compilerlibs/path.cmx dynlink_compilerlibs/primitive.cmx dynlink_compilerlibs/type_immediacy.cmx dynlink_compilerlibs/types.cmx dynlink_compilerlibs/btype.cmx dynlink_compilerlibs/subst.cmx dynlink_compilerlibs/predef.cmx dynlink_compilerlibs/datarepr.cmx dynlink_compilerlibs/cmi_format.cmx dynlink_compilerlibs/persistent_env.cmx dynlink_compilerlibs/env.cmx dynlink_compilerlibs/debuginfo.cmx dynlink_compilerlibs/lambda.cmx dynlink_compilerlibs/runtimedef.cmx dynlink_compilerlibs/instruct.cmx dynlink_compilerlibs/opcodes.cmx dynlink_compilerlibs/bytesections.cmx dynlink_compilerlibs/dll.cmx dynlink_compilerlibs/meta.cmx dynlink_compilerlibs/symtable.cmx dynlink_compilerlibs/asttypes.cmx dynlink_compilerlibs/parsetree.cmx dynlink_compilerlibs/outcometree.cmx dynlink_compilerlibs/cmo_format.cmx dynlink_compilerlibs/cmxs_format.cmx
/nix/store/30kg865p8ixsvblqypmfwzvqx72fglws-binutils-2.35.1/bin/ld: -r and -pie may not be used together
File "/build/ocaml-4.12.0/otherlibs/dynlink/native/dynlink_compilerlibs.cmx", line 1:
Error: Error during partial linking
make[4]: *** [Makefile:197: native/dynlink_compilerlibs.cmx] Error 2
make[4]: Leaving directory '/build/ocaml-4.12.0/otherlibs/dynlink'
make[3]: *** [Makefile:35: allopt] Error 2
make[3]: Leaving directory '/build/ocaml-4.12.0/otherlibs'
make[2]: *** [Makefile:896: otherlibrariesopt] Error 2
make[2]: Leaving directory '/build/ocaml-4.12.0'
make[1]: *** [Makefile:219: opt.opt] Error 2
make[1]: Leaving directory '/build/ocaml-4.12.0'
make: *** [Makefile:275: world.opt] Error 2
builder for '/nix/store/g8789fj4qsrzbicamlw772ldk9mp7hms-ocaml-4.12.0.drv' failed with exit code 2
error: build of '/nix/store/g8789fj4qsrzbicamlw772ldk9mp7hms-ocaml-4.12.0.drv' failed

I’ll try to bisect it…

@nomeata
Copy link
Contributor Author

nomeata commented May 26, 2021

Bisecting points to 4e9dc46 by @utsl42. Nathan, do you have a hunch?

commit 4e9dc46dea0ef8cf15c567fa863796bb23099d0b
Author: Nathan Hawkins <utsl@utsl.org>
Date:   Sat Oct 24 22:34:50 2020 +0000

    stdenv: Fix hardening default for pkgsMusl to reenable -pie
    
    defaultHardeningFlags is set to enable pie for Musl, but is not
    actually used because the default is never put into
    NIX_HARDENING_ENABLE. That still works for cases other than Musl
    only because NIX_HARDENING_ENABLE is defaulted in the binutils and
    cc-wrapper setup-hook.sh scripts.

 pkgs/stdenv/generic/make-derivation.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

@nomeata
Copy link
Contributor Author

nomeata commented May 26, 2021

Cargoculting what I saw in the GHC code, trying this right now:

diff --git a/pkgs/development/compilers/ocaml/generic.nix b/pkgs/development/compilers/ocaml/generic.nix
index d9853dd642a..ccf56140cf3 100644
--- a/pkgs/development/compilers/ocaml/generic.nix
+++ b/pkgs/development/compilers/ocaml/generic.nix
@@ -58,6 +58,9 @@ stdenv.mkDerivation (args // {
   ++ optional spaceTimeSupport (flags "--enable-spacetime" "-spacetime")
   ;
 
+  hardeningDisable = stdenv.lib.optional stdenv.targetPlatform.isMusl "pie";
+
+
   buildFlags = [ "world" ] ++ optionals useNativeCompilers [ "bootstrap" "world.opt" ];
   buildInputs = optional (!lib.versionAtLeast version "4.07") ncurses
     ++ optionals useX11 [ libX11 xorgproto ];

@nomeata
Copy link
Contributor Author

nomeata commented May 26, 2021

Seems to work, fix in #124498

@utsl42
Copy link
Contributor

utsl42 commented May 26, 2021

There appear to be multiple linker bugs affecting at least Rust and GHC with Musl . Both bfd or gold had issues, gold seems a little worse. I would suggest trying lld, it may fix it.

mergify bot pushed a commit to dfinity/motoko that referenced this issue May 28, 2021
to see what breaks, and also to get
NixOS/nixpkgs@5a923e5
which may allow us to use `rustc` from `nixpkgs` again (see #2519)

Issues encountered:

 * [x] in nixpks, various `cargoSHA256` were wrong. (NixOS/nixpkgs#123522, NixOS/nixpkgs#123348, NixOS/nixpkgs#123349)

 * [x] Ocaml built with musl, used for static builds, is currently broken. 
        
    Reported at NixOS/nixpkgs#124476.

    Found a possible fix, submitted at NixOS/nixpkgs#124498 and currently included in this branch.
 * [x] New ocamlformat version
 * [x] Running new formatter on these files
 * [x] The RTS fails to build or link the C files (`stddef.h` missing)
    This stuff was very hairy before, and that doesn’t get better :-(

    If I use the wrapped `wasm32-unknown-wasi-clang`, the build makes some progress, but then fails with https://bugs.llvm.org/show_bug.cgi?id=43393 (as it used to before, and then somehow we fixed that)

    In the end, surgically adding an include to `CLANG_FLAGS` works, it seems.
 * [x] Some upgraded tool produces new `names` subsections, presumably from this Wasm proposal: https://github.com/WebAssembly/extended-name-section/blob/master/proposals/extended-name-section/Overview.md
   Worked around by jumping over them, but otherwise ignoring them. Should be refined.
 * [x] Haskell code ought to be adjusted to latest GHC
 * [x] Bump the `niv` that we install into the shell (also because of Haskell changes)
 * [x] The darwin rebuild of `rustc` and `git` keeps timing out on hydra.
@sternenseemann
Copy link
Member

lld with gcc is currently not supported and I think last time I tried we can't build OCaml and all its dependencies with clang+lld fully yet…

@r-burns
Copy link
Contributor

r-burns commented Aug 25, 2021

The second commit of #135619 ("match leading/trailing arguments") should fix this

@nomeata
Copy link
Contributor Author

nomeata commented Aug 25, 2021

The second commit of #135619 ("match leading/trailing arguments") should fix this

That's great news!

@r-burns
Copy link
Contributor

r-burns commented Oct 22, 2021

Fixed by #135619

@r-burns r-burns closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants