Datapin deduplication to fix EXPORT_SYMBOL issues

This commit is contained in:
York Jasper Niebuhr 2026-04-08 11:32:00 +02:00
parent 1ab19d488c
commit 8a5628bd11

View File

@ -1,11 +1,15 @@
#include <stage0.h>
#include <final.h>
#include <unordered_set>
#include <string>
#include <pinpoint_error.h>
#include <pinpoint_config.h>
static UID next_dpin_uid = 0;
static std::list<DataPin> pins;
static std::unordered_set<std::string> seen_dpin_symbols;
void DataPin::reset() {
pins.clear();
@ -152,6 +156,17 @@ static void on_static_var(tree var) {
if (!type)
return;
tree symbol_tree = DECL_ASSEMBLER_NAME(var);
const char* symbol;
if (!symbol_tree || !(symbol = IDENTIFIER_POINTER(symbol_tree)))
pinpoint_fatal("on_static_var failed to get symbol of static variable");
std::string sym{symbol};
// Deduplicate multiple decls that name the same object (e.g. EXPORT_SYM situations)
if (!seen_dpin_symbols.insert(sym).second)
return;
DataPin pin;
if (!compile_datapin(type, pin))
return;
@ -159,12 +174,7 @@ static void on_static_var(tree var) {
DECL_PRESERVE_P(var) = 1;
// pin.global = static_cast<bool>(TREE_PUBLIC(var));
tree symbol_tree = DECL_ASSEMBLER_NAME(var);
const char* symbol;
if (!symbol_tree || !(symbol = IDENTIFIER_POINTER(symbol_tree)))
pinpoint_fatal("on_static_var failed to get symbol of static variable");
pin.symbol = std::string{ symbol };
pin.symbol = sym;
pin.pin_symbol = make_dpin_symbol();
pins.emplace_back(std::move(pin));
}