Two implementations of one file name in different directories share one object: the link fails, or a debug build has one file's code twice and the other's not at all #50
Labels
No labels
bug
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Build#50
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
An implementation's object is named from its file's name alone,
<build dir>/<name>_impl.o. Soa/Thing.cppandb/Thing.cppin one configuration are compiled into the same object, each over the other, and the link names that object twice.A release build then fails at the link, with a message that points at neither source. A debug build of two such files that define nothing another file names (files that register themselves when the program starts, say) succeeds without a word, and the program has one file's code twice and the other's not at all. Which of the two it is differs from run to run, and need not be the file that was changed.
Reproduced with the stable Flatpak, 6.3.0 (
flatpak run net.catcrafts.CrafterBuild//stable, writtencrafter-buildbelow). Line numbers refer toc929dce(6.4.0); each cited line is the same text in 6.3.0.Met in a library that keeps one source file per method of an interface,
<package>/<Interface>/<method>.cpp: every interface has anInterface.cpp, and the same method name occurs under many interfaces.Reproduce
Two fixtures of three sources each,
main.cpp,a/Thing.cppandb/Thing.cpp(below).loud: eachThing.cppdefines a function thatmaincalls.crafter-build:A()is missing from the link and is not mentioned.crafter-build --debugfails the same way, in that run on the other file:silent: eachThing.cppdefines nothing another file names. A static object in an anonymous namespace registers it when the program starts.crafter-buildfails, since a release build's objects are bitcode (implementations/Crafter.Build-Clang.cpp:468):crafter-build --debugsucceeds. The build, and then the program:After
touch b/Thing.cpp,crafter-build --debugcompiles both again, and the program hasa's code twice:After
touch a/Thing.cppand another build it hadb's twice. In an earlier run of the same steps the outcomes were the other way about, and one of the rebuilds compiled only one of the two files.Fixtures
project.cpp, the same for both:loud/main.cpploud/a/Thing.cpploud/b/Thing.cppsilent/main.cppsilent/a/Thing.cpp, andsilent/b/Thing.cppwithbfora:Where
implementations/Crafter.Build-Implementation.cpp:17:Implementation::Checktakes the object to bebuildDir/path.filename()with_impl.o, and:22reads the dependency file beside it.implementations/Crafter.Build-Implementation.cpp:53:Implementation::Schedulecompiles to the same name,-MF {2}_impl.o.d … -o {2}_impl.o.implementations/Crafter.Build-Clang.cpp:1384: the link's list of objects is made fromimplementation.path.filename(), an entry for each implementation, so the shared object is on it twice.implementations/Crafter.Build-Clang.cpp:1502: the check whether to link again, by the same name._source.o(implementations/Crafter.Build-Clang.cpp:1178and:1192, and:1515for linking again). Read there and not run: a.cand a.cuof one name would share an object even in one directory.The directory a source lies in is in none of these. The two implementations share the dependency file as well, so each is checked for staleness against the source and the headers of whichever was compiled last. Not run: a change to a header that only the other one includes.
A module interface's BMI and object are named from the file's name too (
implementations/Crafter.Build-Interface.cpp:45,:48). The BMIs are found through-fprebuilt-module-path(implementations/Crafter.Build-Clang.cpp:337), which looks for a file of the module's name, so two interface files of one name would have to be one module. That is not this issue.Proposal
Name an implementation's object and its dependency file from the source's path relative to the project, and a C or CUDA source's likewise: a directory under the build directory for each source directory, or the path made part of the one name.
What that changes beside the fix:
popen, as one argument to the shell (implementations/Crafter.Build-Platform.cpp:708), and one argument may be 131,071 bytes here (Linux, x86_64): with 131,072, starting a program fails with "Argument list too long". For a library of 15 implementations the recorded link command (<name>.link) is 2,731 bytes, 1,498 of them the implementations' objects: 100 apiece on average, 69 of that the build directory with its slash. At that rate about 1,300 objects fit, and fewer with directories in their names. A response file for the objects would take that limit away. The link uses none today.Compiling Thing.cppcould carry the path, so that the two can be told apart.If the names are to stay as they are, the least that would help is to refuse a configuration in which two implementations, or two C sources, have the same file name, and to name both. That takes away the link error that points nowhere and the silent debug build. A layout like the one above still could not be built.
Not looked at
Windows and WebAssembly targets; a source named by a path with
..in it; what becomes of the objects of a file that is no longer in the project.