diff --git a/pinpoint/stage0/on_finish_decl.cpp b/pinpoint/stage0/on_finish_decl.cpp index 9ccd82d..b9f94ce 100644 --- a/pinpoint/stage0/on_finish_decl.cpp +++ b/pinpoint/stage0/on_finish_decl.cpp @@ -1,11 +1,15 @@ #include #include +#include +#include + #include #include static UID next_dpin_uid = 0; static std::list pins; +static std::unordered_set 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(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)); }