Only dump metadata for used targets

This commit is contained in:
York Jasper Niebuhr 2026-04-05 20:24:38 +02:00
parent bef55c1266
commit c57b3f03a3
2 changed files with 20 additions and 1 deletions

View File

@ -44,3 +44,6 @@ Plugin is per compilation unit
-> structs with same name can habe different definitions in different CUs (disallow this for now)
-> anonymous structs can not really be matched between CUs without type hash (disallow this for now)
-> later, use hash(type) to match structs between CUs to randomize as one
Symbols must be object symbols because untyped/function symbols cause objtool issues in kernel build
-> can not find starting instruction of function

View File

@ -5,6 +5,7 @@
#include <string>
#include <filesystem>
#include <fstream>
#include <unordered_set>
#include <safe-input.h>
#include <safe-output.h>
@ -153,9 +154,24 @@ void on_finish_unit(void* plugin_data, void* user_data) {
out << "SPSLR " << get_src_file() << " " << cu_uid << std::endl;
// Dump all target structs
// Construct set of all targets that are used by at least 1 ipin or dpin
std::unordered_set<UID> used_targets;
for (const DataPin& dpin : DataPin::all()) {
for (const DataPin::Component& c : dpin.components)
used_targets.insert(c.target);
}
for (const auto& [uid, ipin] : s2_pins())
used_targets.insert(ipin.target);
// Dump all USED target structs
for (const auto& [uid, target] : TargetType::all()) {
if (used_targets.find(uid) == used_targets.end())
continue;
// target <name> <local uid> <size> <field count>
out << "target " << target.name() << " " << uid << " " << target.size()
<< " " << target.fields().size() << std::endl;