[BOLT] Compute local code section names lazily to reduce memory (#214890)
Every BinaryFunction eagerly materialized two std::string members at
construction: CodeSectionName (".local.text.<name>") and
ColdCodeSectionName (".local.cold.text.<name>"), built by appending the
full function name to a fixed prefix. On ELF the name is the (often
large, mangled) symbol name, which is already owned by the function's
MCSymbol. So every function stored two extra heap copies of its name --
for all functions, whether or not they were ever emitted into a
per-function section. During discoverFileObjects on a large binary, this
eager construction (buildSectionName -> Twine::str) accounted for 1-2%
of RSS (1770MB).
Here we make both members std::optional<std::string>, left empty by
default, and recompute the default name on demand in
getCodeSectionName() from the function's name. Only functions with an
explicitly assigned section name (via
setCodeSectionName/setColdCodeSectionName -- mostly short constants such
as ".text"/".text.cold" set during reordering, plus the injected/patch
cases) store a string. The common, unoptimized function stores nothing.