Call linker even when Clflags.objfiles is empty #8877
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've encountered a surprising behavior of ocamlopt: it silently ignores some input .o and .a files, when compilation is done separately from linking. Here is how it happens:
It doesn't happen when at least one of the inputs is cmx or cmxa.
The linker is not called, because there are no input files to compile. That is, optmain discovers that Clflags.objfiles is empty and doesn't call link. The problem is that some link targets are in Clflags.ccobjs not in Clflags.objfiles.
This issue can cause missing files go unnoticed. For example, the following command returns successfully (i.e., with exit code 0), even when there is no
t.o
file:It does not report an error, as would happen with other input file types, such as .ml and .cmx. Of course, it does not generate test.exe either.
Normally, .o and .a files are passed to the linker directly, without checking if the files exist, because the linker would fail with an error if they don't. However, in the above example, the linker was not called, because there were no input files to compile.
This one line PR removes the check that Clflags.objfiles is not empty before link. I am not entirely sure that this won't have bad consequences, but it seems that asmlink works just fine with an empty Clflags.objfiles. Tests pass.