diff --git a/include/emilpro/i_symbol.hh b/include/emilpro/i_symbol.hh index 3770a40..fbfc403 100644 --- a/include/emilpro/i_symbol.hh +++ b/include/emilpro/i_symbol.hh @@ -37,6 +37,12 @@ public: virtual std::span> Instructions() const = 0; + /** + * @brief A pointer to an alias for this symbol (dynamic + static for example) + * + * @return the other symbol, or nullptr for none + */ + virtual const ISymbol* Alias() const = 0; virtual void WaitForCommit() = 0; }; diff --git a/include/emilpro/mock/mock_symbol.hh b/include/emilpro/mock/mock_symbol.hh index 9d7eb2b..f6f6e93 100644 --- a/include/emilpro/mock/mock_symbol.hh +++ b/include/emilpro/mock/mock_symbol.hh @@ -13,6 +13,7 @@ public: MAKE_CONST_MOCK0(Offset, uint64_t(), final); MAKE_CONST_MOCK0(Size, size_t(), final); MAKE_CONST_MOCK0(Section, (const ISection&)(), final); + MAKE_CONST_MOCK0(Alias, (const ISymbol*)(), final); MAKE_CONST_MOCK0(Data, std::span(), final); MAKE_CONST_MOCK0(Flags, const std::string&(), final); MAKE_CONST_MOCK0(Instructions, diff --git a/qt/emilpro/mainwindow.cc b/qt/emilpro/mainwindow.cc index 8850a96..e7bba85 100644 --- a/qt/emilpro/mainwindow.cc +++ b/qt/emilpro/mainwindow.cc @@ -630,7 +630,7 @@ MainWindow::UpdateRefersToView(const emilpro::ISymbol& symbol) { m_refers_to_view_model->removeRows(0, m_refers_to_view_model->rowCount()); - auto symbol_refs = symbol.RefersTo(); + auto symbol_refs = symbol.Alias()->RefersTo(); for (const auto& ref : symbol_refs) { auto section = ref.section; @@ -700,7 +700,7 @@ MainWindow::UpdateReferredByView(const emilpro::ISymbol& symbol) { m_referred_by_view_model->removeRows(0, m_referred_by_view_model->rowCount()); - auto symbol_refs = symbol.ReferredBy(); + auto symbol_refs = symbol.Alias()->ReferredBy(); for (const auto& ref : symbol_refs) { auto section = ref.section; diff --git a/src/section/section.cc b/src/section/section.cc index 2ea1d1a..e88c350 100644 --- a/src/section/section.cc +++ b/src/section/section.cc @@ -83,8 +83,16 @@ Section::FixupSymbolSizes() { const auto& symbols = it->second; + if (symbols.empty()) + { + continue; + } + auto adjust = last_offset; - for (auto* symbol : symbols) + + // Use the last symbol as alias for all symbols (including itself) + auto alias = symbols.back(); + for (auto symbol : symbols) { if (int64_t size = adjust - symbol->Offset(); size >= 0) { @@ -93,6 +101,7 @@ Section::FixupSymbolSizes() last_offset = symbol->Offset(); m_symbol_refs.push_back(*symbol); + symbol->SetAlias(alias); } } } diff --git a/src/symbol/include/symbol.hh b/src/symbol/include/symbol.hh index 04a68e7..fd43028 100644 --- a/src/symbol/include/symbol.hh +++ b/src/symbol/include/symbol.hh @@ -30,6 +30,7 @@ public: std::span> Instructions() const final; std::span ReferredBy() const final; std::span RefersTo() const final; + const ISymbol* Alias() const final; void WaitForCommit() final; @@ -40,6 +41,10 @@ public: void AddReferredBy(std::span referers); void AddRefersTo(const IInstruction::Referer& referer); + void SetAlias(Symbol* alias); + + Symbol *DoGetAlias(); + // Called when all referrers/referred by are done void Commit(); @@ -61,6 +66,7 @@ private: std::vector m_referred_by_store; std::vector m_refers_to_store; + Symbol *m_alias; mutable std::mutex m_mutex; diff --git a/src/symbol/symbol.cc b/src/symbol/symbol.cc index 1779726..4f34af0 100644 --- a/src/symbol/symbol.cc +++ b/src/symbol/symbol.cc @@ -21,6 +21,7 @@ Symbol::Symbol(const ISection& section, , m_flags(flags) , m_name(name) , m_data(section.Data().subspan(offset)) + , m_alias(this) { // Use what c++filt uses... int demangle_flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE; @@ -122,6 +123,12 @@ Symbol::RefersTo() const return m_refers_to; } +const ISymbol* +Symbol::Alias() const +{ + return m_alias; +} + std::vector>& Symbol::InstructionsStore() { @@ -143,6 +150,18 @@ Symbol::AddRefersTo(const IInstruction::Referer& referer) m_refers_to_store.emplace_back(referer); } +void +Symbol::SetAlias(Symbol* alias) +{ + m_alias = alias; +} + +Symbol* +Symbol::DoGetAlias() +{ + return m_alias; +} + void Symbol::SetInstructions(std::span> instructions) {