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

opam switch create with static option fails on Ubuntu aarch64 #26216

Open
cknitt opened this issue Jul 7, 2024 · 6 comments · May be fixed by #26323
Open

opam switch create with static option fails on Ubuntu aarch64 #26216

cknitt opened this issue Jul 7, 2024 · 6 comments · May be fixed by #26323

Comments

@cknitt
Copy link
Contributor

cknitt commented Jul 7, 2024

Consider this Dockerfile:

FROM ubuntu:latest

RUN apt update
RUN apt install -y --no-install-recommends ca-certificates git rsync opam musl-tools
RUN opam init -y --bare --disable-sandboxing
RUN opam switch create 5.2.0 --packages ocaml-option-static

On x64, it works perfectly fine.

However, on aarch64, opam switch create gives me the following error:

11.15 [ERROR] The compilation of ocaml-variants.5.2.0+options failed at "make -j9".
11.16
11.16 #=== ERROR while compiling ocaml-variants.5.2.0+options =======================#
11.16 # context              2.1.5 | linux/arm64 | ocaml-option-static.1 | https://opam.ocaml.org#f11abb65
11.16 # path                 ~/.opam/5.2.0/.opam-switch/build/ocaml-variants.5.2.0+options
11.16 # command              /usr/bin/make -j9
11.16 # exit-code            2
11.16 # env-file             ~/.opam/log/ocaml-variants-7-75a8ef.env
11.16 # output-file          ~/.opam/log/ocaml-variants-7-75a8ef.out
11.16 ### output ###
11.16 # make[1]: Entering directory '/root/.opam/5.2.0/.opam-switch/build/ocaml-variants.5.2.0+options'
11.16 # [...]
11.16 #   CC runtime/interp.b.o
11.16 #   CC runtime/startup_byt.b.o
11.16 #   CC runtime/zstd.b.o
11.16 #   MKLIB runtime/libcamlrun.a
11.16 #   MKEXE runtime/ocamlrun
11.16 # /usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/13/libgcc.a(lse-init.o): in function `init_have_lse_atomics':
11.16 # (.text.startup+0xc): undefined reference to `__getauxval'
11.16 # collect2: error: ld returned 1 exit status
11.16 # make[1]: *** [Makefile:1309: runtime/ocamlrun] Error 1
11.16 # make[1]: Leaving directory '/root/.opam/5.2.0/.opam-switch/build/ocaml-variants.5.2.0+options'
11.16 # make: *** [Makefile:830: world.opt] Error 2
@kit-ty-kate kit-ty-kate transferred this issue from ocaml/opam Jul 8, 2024
@cknitt
Copy link
Contributor Author

cknitt commented Aug 1, 2024

@kit-ty-kate I found that the problem might be solved by setting

CFLAGS=-mno-outline-atomics

see e.g.

rust-lang/rust#89626 (comment)

or

https://lists.cs.columbia.edu/pipermail/kvmarm/2020-July/041614.html

I wanted to try it out but unfortunately have no idea how to get the CFLAGS passed correctly through opam switch create. Can you help me there?

@kit-ty-kate
Copy link
Member

opam passes most environment variables as-is so if exporting CFLAGS before running the command doesn't work this would be more a question for the compiler developers: https://github.com/ocaml/ocaml/issues
Also if -mno-outline-atomics should always be given in these circumstances then it should probably be described in an issue for the compiler anyway, in hope it would be added automatically should the situation requires it.

@cknitt
Copy link
Contributor Author

cknitt commented Aug 1, 2024

I can confirm that CFLAGS=-mno-outline-atomics would indeed solve the problem if it was applied correctly.

It is not enough if this is set in the environment. It is not passed through to the configure call then and therefore has no effect.

By using -v, I determined that CFLAGS=-mno-outline-atomics opam switch create 5.2.0 --packages ocaml-option-static invoked the following configure command:

/root/.opam/5.2.0/.opam-switch/build/ocaml-variants.5.2.0+options/./configure "--prefix=/root/.opam/5.2.0" "--docdir=/root/.opam/5.2.0/doc/ocaml" "-C" "CC=musl-gcc" "CFLAGS=-Os" "ASPP=musl-gcc -c" "LIBS=-static" "--disable-warn-error

Note the CFLAGS=-Os, so the CFLAGS=-mno-outline-atomics from the environment were ignored. After this it invokes make -j9 which gives me the error I reported above.

Now if I do not clean up the broken switch and instead manually call configure as follows (with the -mno-outline-atomics), everything builds fine: 🎉

cd /root/.opam/5.2.0/.opam-switch/build/ocaml-variants.5.2.0+options
rm config.cache
/root/.opam/5.2.0/.opam-switch/build/ocaml-variants.5.2.0+options/./configure "--prefix=/root/.opam/5.2.0" "--docdir=/root/.opam/5.2.0/doc/ocaml" "-C" "CC=musl-gcc" "CFLAGS=-Os -mno-outline-atomics" "ASPP=musl-gcc -c" "LIBS=-static" "--disable-warn-error"
make -j9
# Success!

@kit-ty-kate So I think what I would actually need is CFLAGS=-Os -mno-outline-atomics to be set here:

"CFLAGS=-Os" {ocaml-option-musl:installed}

(maybe conditional on platform Linux ARM64)

@kit-ty-kate
Copy link
Member

Sure, a PR would be welcome if you have the time

@cknitt
Copy link
Contributor Author

cknitt commented Aug 1, 2024

Great! If I fork opam-repository and fix this there, I can even test with setup-ocaml by specifying my fork in opam-repositories, right?

@kit-ty-kate
Copy link
Member

yes that's right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants