staticdata: fix many mistakes in staticdata stripping (#58166)
While #58156 was supposed to be fairly trivial, it ended up uncovering
many bugs in the unusual ways that trimming and binding partition had
been added to the serialization format. This attempts to reorganize them
to be handled more consistently and with fewer mistakes.