libctf: split up ctf_serialize
ctf_serialize and its various pieces may be split out into a separate
file now, but ctf_serialize is still far too long and disordered, mixing
header initialization, sizing of multiple CTF sections, sorting and
emission of multiple CTF sections, strtab construction and ctf_dict_t
copying into a single ugly organically-grown mess.
Fix the worst of this by migrating all section sizing and emission into
separate functions, two per section (or class of section in the case of
the symtypetabs). Only the variable section is now sized and emitted
directly in ctf_serialize (because it only takes about three lines to do
so).
The section sizes themselves are still maintained by ctf_serialize so
that it can work out the header offsets, but ctf_symtypetab_sect_sizes
and ctf_emit_symtypetab_sects share a lot of extra state: migrate that
into a shared structure, emit_symtypetab_state_t.
(Test results unchanged.)
libctf/ChangeLog
2021-03-18 Nick Alcock <nick.alcock@oracle.com>
* ctf-serialize.c: General reshuffling, and...
(emit_symtypetab_state_t): New, migrated from
local variables in ctf_serialize.
(ctf_serialize): Split out most section sizing and
emission.
(ctf_symtypetab_sect_sizes): New (split out).
(ctf_emit_symtypetab_sects): Likewise.
(ctf_type_sect_size): Likewise.
(ctf_emit_type_sect): Likewise.