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
-output-obj should support autolink #6797
Comments
Comment author: @whitequark It would seem as the same problem as when you don't pass -custom to ocamlc, however there is of course no ocamlopt -custom. |
Comment author: @whitequark It actually seems that ocamlc -output-obj suffers from the same problem. |
Comment author: @whitequark @gasche, I've attached a patch that fixes this. Specifically:
This also fixes issue 0006796 in the case where -runtime-variant is passed. The remove_Wl function is necessary now because some packages (ctypes specifically) rely on the fact that the linker options are processed by C compiler driver (the gcc or clang binary, usually), and try to pass arguments to actual linker by escaping them via -Wl. However, partial linking, on which -output-obj relies, invokes the linker (the ld binary, usually) directly. The remove_Wl function performs unescaping in the same way as the compiler driver would. Furthermore, it would be nonsensical to pass any options not recognized either directly by the driver (like -L) or escaped for passing to the linker (i.e. -Wl), so this should cover all reasonable behavior. Even if not, which is unlikely, this would not break any existing code. Normally the user would pass -runtime_variant '', or, equivalently, when 0006733 is merged, put runtime_variant() in _tags. The following line: Since the change is made to be noninvasive, I'd like to nominate it for 4.02.2. |
Comment author: @damiendoligez You need to protect the calls to Also, I don't understand how passing |
Comment author: @whitequark Oops. Okay, I need some other method to indicate "put the runtime and stubs into this object file". Suggestions? Introducing a separate flag just for this seems mildly fishy. |
Comment author: @damiendoligez I don't think it's a good idea to use You should probably introduce a new flag. How about |
Comment author: @whitequark
|
Comment author: @whitequark Patch updated to use -output-complete-obj and also extended to ocamlc for completeness. |
Comment author: @damiendoligez patch applied to 4.02 branch (rev 16054). |
Comment author: @whitequark Reopening because of a slight bug in ocamlc handlign (ocamlopt is fine), demonstrated by: $ ocamlfind -toolchain android ocamlc -verbose -package sqlite3 -linkpkg t.ml -o foo.o -passopt -output-complete-obj
The fix is to change bytecomp/bytelink.c:576:
to:
|
Comment author: @whitequark After the fix it should also be forward-ported to trunk, I think. |
Comment author: @damiendoligez I applied your fix to 4.02 (rev 16095). By default, this will be merged into trunk right after the release of 4.02.2. If you want it sooner, please say so. |
Comment author: @alainfrisch The -L options were not recognized by Microsoft linker, thus producing warnings when -pack'ing. I've changed them /libath:. |
Original bug ID: 6797
Reporter: @whitequark
Assigned to: @damiendoligez
Status: closed (set by @xavierleroy on 2017-02-16T14:18:15Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.02.2+dev / +rc1
Fixed in version: 4.02.2+dev / +rc1
Category: ~DO NOT USE (was: OCaml general)
Tags: patch
Related to: #6625 #6733 #6796 #6918 #6929
Monitored by: @gasche
Bug description
As I've just realized, in #6733 I actually abused -output-obj: the compiler thought it was building an executable and thus invoked gcc and not ld -r ($PARTIALLD in Makefile.config). Thus it also linked in the runtime and most importantly the C stubs.
In fact if you try to use -output-obj as "intended", it doesn't link in the runtime, which is not too problematic, but also it doesn't link in the C stubs. It is unreasonable to expect the user to hunt down the C stubs manually and link them in explicitly, therefore I think -output-obj is completely broken.
File attachments
The text was updated successfully, but these errors were encountered: