Skip to content

Fix -no-shared-libs support#2160

Merged
damiendoligez merged 10 commits intoocaml:trunkfrom
dra27:fix-no-shared-libs
Feb 1, 2019
Merged

Fix -no-shared-libs support#2160
damiendoligez merged 10 commits intoocaml:trunkfrom
dra27:fix-no-shared-libs

Conversation

@dra27
Copy link
Copy Markdown
Member

@dra27 dra27 commented Nov 23, 2018

While trying to get Cygwin64 CI to do something useful, I came across various -no-shared-libs limitations.

  • Make (nat)dynlink sound (also fixes MPR#4208, MPR#4229, MPR#4839, MPR#6462, MPR#6957, MPR#6950) #1063 didn't update the nodynlink.ml file, which is done here
  • Export SUPPORTS_SHARED_LIBRARIES in ocamlc -config #1691 failed to update utils/config.mli, which is now done here
  • A small bug in the error message for ocamlc -compat-32 when running with -custom is included (the name of the temporary bytecode executable in /tmp would be displayed instead of the final executable name)
  • The caml-tex test requires a new no-shared-libraries ocamltest action. It would also be possible to do something more intelligent in ocamlrun here (i.e. have ocamlrun ./something-compiled-with-custom realise that it doesn't need interpreting)
  • When shared library support is not available, ocamltest should link with -custom if any of the libraries (e.g. unix.cma) have C stubs. This is done by querying the cma files directly.
  • A similar check is made for running the toplevel with a library. In theory, this could build a custom toplevel but as it only affects the unboxed-primitive-args test, I opted just to skip it.

Detail added to the printed output in GPR#1691, but not exposed from the
module itself.
Changes in GPR#1063 weren't applied to nodynlink.ml
In -custom mode, then bytecode executable is first made in /tmp and this
filename leaked if the executable fails the -compat-32 test.
ocamltest links bytecode executables in custom-runtime mode if they have
C files, but it should also do this for any .cma files which require C
stubs on platforms which don't support dynamic C libraries.
If the toplevel doesn't support shared libraries, skip any toplevel
tests which will load cma files which have C stubs (e.g. unix.cma). The
present implementation is suboptimal - really, it would be better to
create a custom toplevel, but it only affects one test at the moment.
what (String.concat " " commandline) exit_status) in
(Result.fail_with_reason reason, env)
end
end else (result, env)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The code of the else branch has just been updated for indentation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(oh, and to use the backend variable declared earlier)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also libraries.

@dra27 dra27 force-pushed the fix-no-shared-libs branch from f6a30c4 to 66417aa Compare November 28, 2018 20:02
@damiendoligez damiendoligez added this to the 4.08 milestone Dec 6, 2018
@dra27 dra27 mentioned this pull request Dec 12, 2018
@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 12, 2018

(I ran another precheck job: https://ci.inria.fr/ocaml/job/precheck/168/ . I'm afraid there is not much else I can do to help. )

@dra27 dra27 force-pushed the fix-no-shared-libs branch from 66417aa to a397b18 Compare December 13, 2018 09:07
@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Dec 13, 2018

Thanks @gasche! Perhaps @mshinwell can cast an eye over 4190b3b quickly? a813fe7 just adds Config.supports_shared_libraries which should arguably have been there already, so just needs a quick nod.

The remainder of the commits affect the testsuite only, so if @shindere has time to review then great, but equally the changes only affect the tests and do allow us to get CI fully working again.

@mshinwell
Copy link
Copy Markdown
Contributor

@dra27 Could you just replace the nodynlink.ml changes with the contents of #2197?

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 13, 2018 via email

Copy link
Copy Markdown
Member

@damiendoligez damiendoligez left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and I have only one real change to suggest (removing the assert false). This PR will be good to merge as soon as you deal with that.

close_in ic;
List.compare_length_with toc.Cmo_format.lib_dllibs 0 <> 0
else
assert false (* How have non-cma files ended up on the libraries? *)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A corrupted or truncated cma file would trigger this assertion. Better to output a nice error message. Or maybe just ignore the file: I presume it will be passed to the compiler, which will report the error to the user.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've put the fix for this in a separate commit as it'll want reviewing

what (String.concat " " commandline) exit_status) in
(Result.fail_with_reason reason, env)
end
end else (result, env)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also libraries.

let iter_initial_units _ = ()
let num_globals_inited = not_available

let fold_initial_units ~init ~f:_ = not_available init
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only functional difference with @mshinwell's patch is that adapt_filename, num_globals_inited and fold_initial_units raise Failure here instead of returning dummy values. Unless Mark has an objection, I think that's OK.

Copy link
Copy Markdown
Member Author

@dra27 dra27 Jan 15, 2019

Choose a reason for hiding this comment

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

I don't follow the "Also libraries." comment? GitHub UI being unclear...

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jan 9, 2019

@dra27 do you need some help with that one?

Let me know if you'd like me to propose a rebase

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Jan 14, 2019

Sorry for the lag - I have this rebased and fixed the relevant parts of configure.ac, but I have two tests which are unexpectedly failing (I think one will need a trivial update for Cygwin and the other is autoconf-related). I'll push a revised branch once I've fixed those two.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jan 14, 2019 via email

dra27 added 2 commits January 15, 2019 09:22
The --disable-shared option is not presently possible on the native
Windows ports, though this isn't (yet) enforced by configure.
@dra27 dra27 force-pushed the fix-no-shared-libs branch from a397b18 to b8bc678 Compare January 15, 2019 09:24
@dra27 dra27 force-pushed the fix-no-shared-libs branch 2 times, most recently from 4c95820 to 27def61 Compare January 15, 2019 12:03
@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Jan 15, 2019

Tsk, wrong branch in recheck. Now testing the correct code in precheck#179.

@shindere / @damiendoligez - has something happened to the mingw32 worker? It was missing the OCAML_ARCH variable, which I've restored but it also seems to be missing flexdll (see https://ci.inria.fr/ocaml/job/precheck/179/flambda=false,label=ocaml-mingw-32/console). I have finally uploaded a public key to Inria CI, but I don't think I have access to the workers at the moment?

@dra27 dra27 force-pushed the fix-no-shared-libs branch from 27def61 to c0040e1 Compare January 15, 2019 12:48
# Allow the MSVC linker to be found even if ld isn't installed.
# User-specified LD still takes precedence.
AC_CHECK_TOOLS([LD],[ld link])
# libtool expects host_os=mingw for native Windows
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since the autoconf, I've allowed getting --disable-shared to work as expected to form part of this GPR. That has also expanded on a problem @shindere identified that --enable-shared doesn't work on MSVC (it does work for Cygwin and the mingw-w64 compilers). I did some in-depth poking into the code generated by LT_INIT and determined that the problem is that autoconf appears to assume that "native Windows" will be an OS called mingw - there is code in LT_INIT which will happily detect the output of cl, but it can't work with $host_os = windows.

This is making me wonder if it would be better for the MSVC ports to be identified not by pc-windows but by pc-mingw32 or cl-mingw32 or msvc-mingw32 - i.e. use a different part of the triple to identify it? I don't know - and haven't yet made any effort to find out - what other projects have done about this, but it seems worth determining this now, before i686-pc-windows becomes the only way of identifying MSVC.

Thoughts @shindere?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds fishy. Is autoconf really that ill-adapted to MSVC toolchains? What is $host_os when we run on cygwin?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not quite the right question - autoconf has reasonable support for cl as a compiler, but it does expect a Unix-like OS to be running on ... i.e. it expects the OS to be either cygwin or mingw (they're just the only two it's aware of). So it's objecting to (or rather, ignoring!) windows as the declared OS.

@damiendoligez
Copy link
Copy Markdown
Member

We fixed the mingw-32 worker, it was just missing the flexdll directory in its PATH.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jan 22, 2019 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jan 22, 2019 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jan 22, 2019 via email

@damiendoligez
Copy link
Copy Markdown
Member

@dra27 Is this good to merge now? I'm waiting for this before I do the beta.
I've relaunched the precheck as https://ci.inria.fr/ocaml/job/precheck/187/ after telling Jenkins to keep precheck builds a little longer...

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Feb 1, 2019

I think my only question was whether we wanted to rename the osname for Windows ... as long as we're happy with the "hack" at the moment for LT_INIT, I think this is good to go.

@damiendoligez
Copy link
Copy Markdown
Member

Perfect, thanks!

Should I squash the commits or do you think it's better to keep the history?

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Feb 1, 2019

Could we keep the history, just for bisection purposes?

@damiendoligez damiendoligez merged commit 23d582f into ocaml:trunk Feb 1, 2019
@damiendoligez
Copy link
Copy Markdown
Member

Merged, thanks!

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Feb 2, 2019

Has it been cherry-picked? (not sure from GH interface if it's displaying 4.08 commits in the wrong order, or if they're missing...)

@dra27 dra27 mentioned this pull request Mar 1, 2019
@dra27 dra27 deleted the fix-no-shared-libs branch July 6, 2021 14:05
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.

5 participants