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

[Doc] adds for -output-complete-obj option #1351

Merged
merged 4 commits into from Feb 8, 2021
Merged

Conversation

bobot
Copy link
Contributor

@bobot bobot commented Sep 18, 2017

Try to add documentation for -output-complete-obj. However the comment in the latex of @damiendoligez about the doc of -output-obj is still true:

% -- This seems completely wrong -- Damien
% The shared libraries produced by "ocamlc -output-obj" or by "ocamlopt
% -output-obj" already contains the OCaml runtime library as
% well as all the needed C libraries.

I'm wondering if the documentation shoudn't be written by saying that -output-obj is deprecated and just talk about -output-complete-obj. Is there a need for the building of not shared libraries that doesn't contains the runtime and C stub?

Closes #8882

@dbuenzli
Copy link
Contributor

is still true:

% -- This seems completely wrong -- Damien
% The shared libraries produced by "ocamlc -output-obj" or by "ocamlopt
% -output-obj" already contains the OCaml runtime library as
% well as all the needed C libraries.

AFAIR that's actually not the case, you have to link libasmrun and your libraries when you produce your executable.

Is there a need for the building of not shared libraries that doesn't contains the runtime and C stub?

You might want to link with a runtime variant.

@bobot
Copy link
Contributor Author

bobot commented Sep 19, 2017

AFAIR that's actually not the case, you have to link libasmrun and your libraries when you produce your executable.

When doing a .so (main_dll = true), the code does exactly the same thing for -output-obj and -output-complete-obj (main_obj_runtime = true) except for the linking of the C libraries of the runtime:

  let files, c_lib =
    if (not !Clflags.output_c_object) || main_dll || main_obj_runtime then
      files @ (List.rev !Clflags.ccobjs) @ runtime_lib () @ libunwind,
      (if !Clflags.nopervasives || main_obj_runtime
       then "" else Config.native_c_libraries)
    else
      files, ""

I tested it that work without linking the runtime. Perhaps a test should be added for the creation of shared libraries.

Is there a need for the building of not shared libraries that doesn't contains the runtime and C stub?

You might want to link with a runtime variant.

Differently than by using -runtime-variant? In fact -runtime-variant _pic is on some architecture needed.

  • Why linking with Config.native_c_libraries in -output-complete-obj since it exists shared libraries for them and the dependency are marked in the .so generated?

  • Does it makes sense to have a libasmrun_pic.so?

@dbuenzli
Copy link
Contributor

Sorry I missed the shared aspect what is written as a comment there seems consistant with what is written about the worfklow here, I thought .o generation was being discussed.

That said I don't really see why -output-obj should be deprecated. I still see the runtime system as a library (providing .pc files for them would actually be nice) rather than being intrisic to the .o generated and I don't see what is wrong with resolving it at the link step --- from a build perspective if you want to produce executables with multiple variants you will have to repeat the whole work for the .o for each of the variant without that option.

@bobot
Copy link
Contributor Author

bobot commented Sep 19, 2017

That said I don't really see why -output-obj should be deprecated

Ok, it just seemed difficult to grasp the differences, but keeping the simple variant seems indeed useful.

@damiendoligez damiendoligez added this to the 4.06.0 milestone Sep 25, 2017
@gasche gasche closed this Sep 27, 2017
@gasche gasche reopened this Sep 27, 2017
@gasche
Copy link
Member

gasche commented Oct 19, 2017

What is the current status of this PR, is it proposed for merge?

@bobot bobot changed the title WIP: [Doc] adds for -output-complete-obj option [Doc] adds for -output-complete-obj option Oct 19, 2017
@bobot
Copy link
Contributor Author

bobot commented Oct 19, 2017

@gasche I think it is.

@gasche
Copy link
Member

gasche commented Oct 19, 2017

@dbuenzli, do you like the current state? (Do you "approve" the PR?)

C object file (".o" file, ".obj" under Windows) containing the
bytecode for the OCaml part of the program, as well as a
"caml_startup" function. The C object file produced by "ocamlc
-output-complete-obj" also contains the runtime and autolink
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if the larger context defines the notion of autolink libraries. But I guess that's the C linking instructions that are embedded in ocaml object's files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wording is already used for the -noautolink option.

This use of "-output-complete-obj" is very similar to a normal linking
step, but instead of producing a main program that automatically runs
the OCaml code, it produces a shared library that can run the OCaml
code on demand. The three possible behaviors of "-output-complete-obj"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I don't understand something but isn't it the case that:

  1. -output-obj: .{o,a} -> only the ocaml program, .so -> ocaml program + runtime libraries + autolink (?)
  2. -output-complete-obj: .{o,a,so} -> ocaml program + runtime libraries + autolink

So I'm not sure I understand this "three possible behaviours" of -output-complete-obj.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With ocamlc a .c can be produced with the two options. And in fact a .a can never be produced.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I understand, the two options -output-obj and -output-complete-obj have the same behavior when producing a shared library or a c file. Would it not make sense to mention both of them in the previous paragraph?

@@ -1597,9 +1603,27 @@ With "ocamlopt", you should do:
% -output-obj" already contains the OCaml runtime library as
% well as all the needed C libraries.

For the final linking phase, in addition to the object file produced
by "-output-complete-obj", you will have only to provide all C
libraries that are required by the OCaml runtimes used.
Copy link
Contributor

Choose a reason for hiding this comment

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

provide the C libraries required by the OCaml runtime

Unix library. With "ocamlc", you should do:
\begin{alltt}
ocamlc -output-complete-obj -o camlcode.o unix.cma {\it{other}} .cmo {\it{and}} .cma {\it{files}}
cc -o myprog {\it{C objects and libraries}} \char92
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't find that particularly intelligible and rather ambiguous, maybe camlcode.o + -lc -lm ? In particular it seems to me that should not repeat the autolink libraries here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed strange that the autolink libraries are added but you still need the library of the runtime. It is not always -lc -lm it could be -lm -ldl, no? I can't add $(ocamlopt -config | sed -n -e "s/^native_c_libraries:\(.*\)$/\1/p") so perhaps {\it{C libraries required by the runtime, eg -lm -ldl}}.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just suggesting examples of what you may need to add here. It's just that it should be made clear that you should not add the autolink libs otherwise you will be subject to double linking. I just find that not very clear in the current text.

(Aside. For this reason I personally find the behaviour of -output-complete-obj dubious, you may have other C object files at that point that need the C libs that you autolinked via -output-complete-obj).

Copy link
Member

Choose a reason for hiding this comment

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

(In your case you are not the target audience for -output-complete-obj.)

With "ocamlopt", you should do:
\begin{alltt}
ocamlopt -output-complete-obj -o camlcode.o unix.cmxa {\it{other}} .cmx {\it{and}} .cmxa {\it{files}}
cc -o myprog {\it{C objects and libraries}} \char92
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@bobot
Copy link
Contributor Author

bobot commented Oct 24, 2017

I don't understand why -output-complete-obj doesn't add -lm -ldl for the linking of a .so like -output-obj because currently they don't appear in the list of dependency of the resulting .so using ldd.

@gasche
Copy link
Member

gasche commented Oct 26, 2017

So what's the current status of this? It looks like you are both slightly confused about some of the aspects of -output-complete-obj we are discussing documenting ( @whitequark might chime in ). Do you think it is more valuable to include a maybe-not-perfect documentation in 4.06, or to delay until you have something you both like?

@dbuenzli
Copy link
Contributor

Do you think it is more valuable to include a maybe-not-perfect documentation in 4.06, or to delay until you have something you both like?

I think that it would valuable to have correct and precise documentation and whoever added that command line switch should do it.

@Octachron
Copy link
Member

Reading the original mantis ticket, it seems to me that the original intent was to not link -ldl when building a .o object file. @whitequark , do you agree with me that it would be fine to add back -lm -ldl when linking a .so file?

@whitequark
Copy link
Member

@Octachron I agree.

@nojb
Copy link
Contributor

nojb commented Sep 24, 2019

We should try to merge this PR even if not perfect. But it needs to be updated for #8872 (if that PR is merged before).

@damiendoligez
Copy link
Member

@bobot #8872 was merged in the meantime. Do you want to update this PR?

@bobot
Copy link
Contributor Author

bobot commented Feb 15, 2020

@nojb Could you do the update? You already have the right to modify my repo.

@nojb
Copy link
Contributor

nojb commented Oct 13, 2020

Circling back to this one, I note that #8872 actually introduced a different flag (-output-complete-exe) so it is not relevant here. On the other hand, #1664 cleared up one subtle point about -output-complete-obj vs -output-obj. I will update the PR accordingly.

@nojb
Copy link
Contributor

nojb commented Oct 14, 2020

PR rebased. Formal review/approval would be appreciated.

Copy link
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.

Grammar corrections, cut long lines, and some rewording for the byte-code case. This PR is nearly ready for merge.

manual/manual/cmds/intf-c.etex Outdated Show resolved Hide resolved
manual/manual/cmds/intf-c.etex Outdated Show resolved Hide resolved
manual/manual/cmds/intf-c.etex Outdated Show resolved Hide resolved
manual/manual/cmds/intf-c.etex Outdated Show resolved Hide resolved
manual/manual/cmds/intf-c.etex Outdated Show resolved Hide resolved
manual/manual/cmds/native.etex Outdated Show resolved Hide resolved
manual/manual/cmds/unified-options.etex Outdated Show resolved Hide resolved
manual/manual/cmds/unified-options.etex Outdated Show resolved Hide resolved
manual/manual/cmds/intf-c.etex Outdated Show resolved Hide resolved
@nojb
Copy link
Contributor

nojb commented Jan 16, 2021

Thanks for the review @damiendoligez! I think all points have been addressed.

@damiendoligez
Copy link
Member

Good. All we need now is a rebase and a Changes entry (if you think it's needed).

@nojb
Copy link
Contributor

nojb commented Feb 8, 2021

Good. All we need now is a rebase and a Changes entry (if you think it's needed).

Done. Good to go once CI is green.

@nojb nojb merged commit 841607f into ocaml:trunk Feb 8, 2021
garrigue pushed a commit to garrigue/ocaml that referenced this pull request Mar 3, 2021
smuenzel pushed a commit to smuenzel/ocaml that referenced this pull request Mar 30, 2021
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Thibaut Mattio <thibaut.mattio@gmail.com>
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.

-output-complete-obj is not documented in the manual
7 participants