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
bytecode -custom supply missing externs #12791
Conversation
1e16420
to
25f3b03
Compare
I have a problem with this fix: it produces dubious C code. At least according to gcc and to clang, an
|
i'll refine the fix. let's make |
i've pushed and verified that change. the generated code now reads like,
it's taking a long time for the changes to get reflected here. i suspect github is having an incident (downdetector seems to indicate so). |
9445317
to
4586466
Compare
Two suggestions: you could also put just the #if defined __cplusplus
extern
#endif
const c_primitive caml_builtin_cprim[] = { or separate declaration and definition: extern const c_primitive caml_builtin_cprim[];
const c_primitive caml_builtin_cprim[] = { both of these work with C and C++. |
a0d4c1d
to
e269a22
Compare
i agree. i think (1) is ever so slightly less verbose and the best phrasing so far. #if defined __cplusplus
extern
#endif
const char * const caml_names_of_builtin_cprim[] = { have pushed that. thanks for having a look @MisterDA ! |
I wonder if the symbol should be protected against C++ name mangling with |
the symbols get C mangling correctly as things are ( |
@MisterDA having a look at the change this seems mostly a safe change that could be backported to 5.1, what is your opinion ? |
I still think it is wrong to compile C code contained in a
|
I guess the correct invocation would be |
It is indeed wrong to compile a C file with a C++ compiler. But... you need to compile a C file, then link C++ objects. That requires two distinct command lines. The fact that currently OCaml uses the linker to compile a C file is the root cause, as it mixes the compilation of one language (C) with the linking of another (C++). One option would be to have two distinct command lines, and compile the .c file in a separate operation. That seems a more invasive change than this diff. We did try |
|
Thanks for pointing this out. For the linking phase we need g++ or clang++, but then they interpret .c source files as C++ files. I agree we're kind of cornered here... |
@xavierleroy , does your comment count as a reluctant approval for this PR ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the proposed changes to bytecomp/symtable.ml
. Some suggestions below.
e269a22
to
4a25769
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @shayne-fletcher for the updates. I'm fine with the current state of this PR. Now merging!
@xavierleroy , I am considering cherry-picking to 5.1 to avoid a feature hole between OCaml 5.0 and OCaml 5.2. Any objections? |
No objections, thanks for asking. |
Since ocaml-5.1.0, bytecode
-custom
executables fail to link if given-cc
a C++ compiler.This is a consequence of certain symbols in generated code being assigned internal linkage by default. This PR addresses the issue by arranging to qualify these constants as
extern
. Fixes #12790