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

ocamlopt is incapable of building files using clock_gettime with glibc older than 2.17 #10329

Closed
JasonGross opened this issue Apr 10, 2021 · 4 comments

Comments

@JasonGross
Copy link

The OCaml 4.11.1 test-suite fails on Ubuntu Precise (12.04). Full logs are available here and here. The error message is:

 ... testing 'main.ml' with 1.1 (native) => failed (Compiling program /<<PKGBUILDDIR>>/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte/main.opt from modules  main.ml: command
/<<PKGBUILDDIR>>/runtime/ocamlrun /<<PKGBUILDDIR>>/ocamlopt  -I /<<PKGBUILDDIR>>/runtime  -nostdlib -I /<<PKGBUILDDIR>>/stdlib  -runtime-variant=i     -o /<<PKGBUILDDIR>>/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte/main.opt   main.ml 
failed with exit code 2)

By running this command locally in a VM with -verbose, I've discovered that the error is:

test@ubuntu:~/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte$ /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/ocamlrun /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/ocamlopt  -I /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime  -nostdlib -I /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib  -runtime-variant=i     -o /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte/main.opt -verbose  main.ml
+ i686-linux-gnu-as  -o 'main.o' '/tmp/camlasm412e31.s'
+ i686-linux-gnu-as  -o '/tmp/camlstartup184b86.o' '/tmp/camlstartupa4bb3d.s'
+ i686-linux-gnu-gcc -Wl,-z,notext -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -Wall -Wdeclaration-after-statement -fexcess-precision=standard -fno-tree-vrp -ffunction-sections -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  -Wl,-E -o '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte/main.opt'  '-L/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime' '-L/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib'  '/tmp/camlstartup184b86.o' '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib/std_exit.o' 'main.o' '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib/stdlib.a' '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/libasmruni.a' -lm -ldl 
/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/libasmruni.a(eventlog_ni.o): In function `time_counter':
/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/eventlog.c:113: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

According to https://stackoverflow.com/a/32649327/377022, versions of glibc older than 2.17 (ldd --version gives ldd (Ubuntu EGLIBC 2.15-0ubuntu10.6) 2.15 on this machine) require -lrt. However, even if I add -ccopt -lrt (which I should not have to do in the first place, I believe, as the test-suite should just work), this is not enough, because, according to https://stackoverflow.com/a/8088766/377022, -lrt must come after the object files, and instead it comes after the last -L but before the first object file. It seems there is no way to instruct ocamlopt to do this (unless I am missing something).

@JasonGross
Copy link
Author

Btw, it seems that -S does not keep all intermediate assembly files:

test@ubuntu:~/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte$ /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/ocamlrun /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/ocamlopt  -I /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime  -nostdlib -I /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib  -runtime-variant=i     -o /home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte/main.opt -verbose main.ml -S
+ i686-linux-gnu-as  -o 'main.o' 'main.s'
+ i686-linux-gnu-as  -o '/tmp/camlstartupd25cd5.o' '/tmp/camlstartupfdecb2.s'
+ i686-linux-gnu-gcc -Wl,-z,notext -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -Wall -Wdeclaration-after-statement -fexcess-precision=standard -fno-tree-vrp -ffunction-sections -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  -Wl,-E -o '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte/main.opt'  '-L/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime' '-L/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib'  '/tmp/camlstartupd25cd5.o' '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib/std_exit.o' 'main.o' '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/stdlib/stdlib.a' '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/libasmruni.a' -lm -ldl 
/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/libasmruni.a(eventlog_ni.o): In function `time_counter':
/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/eventlog.c:113: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)
test@ubuntu:~/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte$ ls /tmp/camlstartupfdecb2.s
ls: cannot access /tmp/camlstartupfdecb2.s: No such file or directory
test@ubuntu:~/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/testsuite/_ocamltest/tests/instrumented-runtime/main/ocamlopt.byte$ 

Is there any way to get access to the camlstartup assembly file, so I can actually test whether or not moving -lrt to the end works?

@nojb
Copy link
Contributor

nojb commented Apr 10, 2021

As mentioned in Discuss, I think you can use ocamlopt -dstartup to access the startup code.

@xavierleroy
Copy link
Contributor

xavierleroy commented Apr 10, 2021

1- Seeing the startup code will not help you. Just look at the very long line generated by ocamlopt -verbose, the one starting with i686-linux-gnu-gcc -Wl,-z,notext. All the C libraries are listed there.
2- To pass an extra library, use -cclib -lxxx. -ccopt zzz is for C compiler options.
3- Ubuntu 12.04 LTS reached end of support on 28 April 2017. You're wasting your time, our time, and electricity by including it in your CI.

@JasonGross
Copy link
Author

2- To pass an extra library, use -cclib -lxxx. -ccopt zzz is for C compiler options.

-cclib -lrt indeed moves -lrt later, but unfortunately not late enough. It gets moved to before '/home/test/coq-debian-build-scripts/ocaml-stuff/debian-sources/ocaml-4.11.1/runtime/libasmruni.a', but instead needs to come right after.

But, sure, this distribution reached end of support a while ago, and I can stop making Coq master packages for precise on launchpad.

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

No branches or pull requests

3 participants