Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/link: include declared constants in DWARF #14517
Currently the DWARF information does not include constant symbols (such as
We should include constants in the DWARF information. DWARF has a DW_TAG_constant for exactly this. The DW_AT_const_value attribute can be a string or any constant form, including DW_FORM_sdata, which is encoded as a LEB128, so in principle it can store arbitrary precision integers (though I don't know how well this is supported in practice). It's not clear to me how to represent floating point constants, though I suspect we'd have to truncate them to 64-bit precision to get them to actually work (despite DWARF's dizzying array of numeric type encodings; scaled packed decimal anyone?).
Doing this would be difficult right now because the compiler would have to emit constants in a way the linker could consume to produce DWARF information. It would probably be relatively straightforward if we switched to producing DWARF directly in the compiler.
This is somewhat easier now that DWARF is being generated by the compiler. It would still require that we keep track of the constants, since currently they disappear pretty early in the process.
This came up again in a discussion of how heap analysis from a core dump could get access to runtime constants. At the moment they just have to be hard-coded.