But requires the build system to read previous output files produced by the compiler and depend on them as inputs to the next build? (not dissimilar to the compare-and-swap approach, but that’s usually handled by the build system, not the compiler itself - having the compiler reading previous inputs would be a pretty significant departure/tool change)
And only applies when the previous build succeeded - and there wouldn’t be a way for the build system to know the previous build succeeded, right? maybe these objects are stale? (I guess that’d work out OK if we built successfully, then the build failed, and the next build happened to be a hash hit - means we changed the code back to something semantically equivalent)
There’s a few complications here - if the two copies of func get optimized differently, the linker will pick one and tombstone/zero-out the addresses in the debug info that references the removed copy. (because the debug info could describe variables as being in different locations, etc)
If the machine code/.text section for the functions are identical, then the debug info in both cases refers to the that one copy - so you’d have one copy in one DWARF CU that refers to the function and says it’s on line 5, and another that refers to the same function and says it’s on line 7. This isn’t particularly useful/necessary, but isn’t wrong either.
It’d still give a poor user experience if the DWARF was out of date and you couldn’t break on the function and get to the right line of source, or couldn’t step through it and see the right lines of code, etc.
Possible, but probably a poor user experience - the user wouldn’t be able to step into this code, print variables, etc. That seems pretty unfortunate.