This is similar to this thread from 11 years ago, but my question is regarding “inline” assembly at the module level.
Currently, if I compile a C source file containing globally-scoped inline assembly with debug info requested (-g), no debug info is generated for that assembly. I understand why, though: all the module-level assembly is effectively concatenated together at the IR level. Have there been any attempts or are there any plans to try to add debug info for this?
To be fair, I haven’t tested this with function-level inline assembly; I assume it would receive debug metadata since that code is, effectively, converted to a series of call instructions. And even if it doesn’t, I believe it would be much easier to add.
(This may be better fit in the IR & Optimizations category, but I wasn’t sure since IR-level debug info is constructed in Clang’s codegen phases.)
I don’t recall seeing anything in that area fly by on the commits list. Note that Clang’s implementation of module-level assembly is pretty different from gcc’s, where you can intersperse module-level asm before/after functions and the asm will come out the other end in the correct relative source order. Clang lumps all the module-level asm together without preserving the source order relative to non-asm source.
Yes indeed, I can certainly understand that being a problem. And any changes to make module-level assembly something that could be enumerated in order would be a breaking change in IR serialization.
Unfortunately, the only thing I can think of that might be easier than that would also completely break the assembly representation: adding preprocessor file lines to the assembly string for the IR-to-native codegen phase to parse and add the proper debug directives. (I tried this; it doesn’t work because the debug information generated by parsing those CPP hash lines seems to be orthogonal to what gets generated by IR debug metadata. It ends up doing things like generating expressions that cross sections, for example.)