Skip to content

cmd/compile: record optimization level in binary #22168

Closed
@aclements

Description

@aclements

Go's debug information for optimized binaries needs a lot of improvement (we're working on it). In the mean time, it would be valuable for debuggers to know whether a binary optimized or unoptimized. For example, this could be used (in combination with the toolchain version already recorded in the binary) to warn users that local variable information may be incorrect and that they should consider recompiling with optimizations disabled.

One complication is that it's currently possible (and fairly common) to compile different packages with different optimization levels. If the cmd/go changes go as planned, this will no longer be possible in 1.10, but may again become possible in the future.

Some reasonable ways to record this information are:

  1. Create a per-package symbol to indicate the optimization level. We could create this symbol only if the package is unoptimized, so we don't bloat optimized binaries with lots of extra symbols. This would be easy to get at from any symbolic debugger.

  2. Record this as a custom attribute in each DWARF function (there is no DIE corresponding to a package). This is arguably the "right" place to record this, but it requires help from the debugger's DWARF decoder to access.

I think both are pretty easy to implement. I would lean toward solution 1.

/cc @rsc @dr2chase @zombiezen

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions