https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/213356
>From 2bcc36208ad31e737f684b983d6e7b7470a216e6 Mon Sep 17 00:00:00 2001 From: Jason Molenda <[email protected]> Date: Fri, 31 Jul 2026 14:21:13 -0700 Subject: [PATCH 1/3] [lldb] Change the Symbol rep for re-export symbols On Darwin system, we have re-export symbols. A library can have a symbol table entry for function A() that is a re-export symbol; it's only data is the name of the actual function to call, B(). When code calls A(), the dynamic loader will resolve this to B() in some other library. Previously, Symbol was using its AddressRange's Address object's offset field to point to lldb memory where the name of the target function, B(), was stored in the binary symbol table. In December Alex put up a PR to stop abusing the Address object in this way, and store (1) the name of the target function, and (2) once it has been looked up, the name of the target function's library. https://github.com/llvm/llvm-project/pull/172565 Alex originally added a ConstString target_name, FileSpec solib to Symbol, which increased the size of this object, and lldb stores many of them so this was a problem. I took Alex's PR and changed Symbol to hold a union of AddressRange or ReExportInfo; re-export symbols do not have address ranges, so only one of these can be in use. I used an old style union which means a lot of care is needed during construction, assignment, and destruction of these to ensure that the correct union member is initialized/freed (AddressRange has an Address which has a weak pointer). The size of the ReExportInfo is the same as the size of AddressRange. It's arguable if I should have used a std::variant<> instead of a union; that would provide for more strictly enforced correctness about type confusion of the two members, but at a cost of adding 8 bytes to the size of Symbol (currently 80 bytes on a 64-bit host). Alex suggested putting up a new PR instead of committing my union change to their original. --- lldb/include/lldb/Symbol/Symbol.h | 32 ++++++- lldb/source/Symbol/Symbol.cpp | 149 ++++++++++++++++++------------ 2 files changed, 117 insertions(+), 64 deletions(-) diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h index 47323b8ba5e56..895a1fed88cce 100644 --- a/lldb/include/lldb/Symbol/Symbol.h +++ b/lldb/include/lldb/Symbol/Symbol.h @@ -13,6 +13,7 @@ #include "lldb/Core/Mangled.h" #include "lldb/Core/Section.h" #include "lldb/Symbol/SymbolContextScope.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/UserID.h" #include "lldb/lldb-enumerations.h" @@ -50,6 +51,12 @@ class Symbol : public SymbolContextScope { Symbol(const Symbol &rhs); + ~Symbol() { + if (m_type != lldb::eSymbolTypeReExported && + m_type != lldb::eSymbolTypeInvalid) + m_addr_range.Clear(); + } + const Symbol &operator=(const Symbol &rhs); static llvm::Expected<Symbol> FromJSON(const JSONSymbol &symbol, @@ -319,12 +326,22 @@ class Symbol : public SymbolContextScope { // modules we've already seen to make sure we don't get caught in a cycle. Symbol *ResolveReExportedSymbolInModuleSpec( - Target &target, ConstString &reexport_name, + Target &target, ConstString reexport_name, lldb_private::ModuleSpec &module_spec, lldb_private::ModuleList &seen_modules) const; void SynthesizeNameIfNeeded() const; + // Initially, a ReExportInfo will only have a name: the symbol name + // that this Symbol will remap to, at runtime. + // We won't have the library that this symbol is defined in, + // until later, when we have other binaries loaded in the Target. + struct ReExportInfo { + ConstString name; + FileSpec library; + ReExportInfo() : name(), library() {} + }; + uint32_t m_uid = LLDB_INVALID_SYMBOL_ID; // User ID (usually the original // symbol table index) uint16_t m_type_data = 0; // data specific to m_type @@ -351,9 +368,16 @@ class Symbol : public SymbolContextScope { m_is_weak : 1, m_type : 6; // Values from the lldb::SymbolType enum. mutable Mangled m_mangled; // uniqued symbol name/mangled name pair - AddressRange m_addr_range; // Contains the value, or the section offset - // address when the value is an address in a - // section, and the size (if any) + union { + // Contains the value, or the section offset address when the value is an + // address in a section, and the size (if known). For non-re-export + // symbols. + AddressRange m_addr_range; + + // Stores re-export information if this symbol is of type + // eSymbolTypeReExported; no address information for these symbols. + ReExportInfo m_reexport_info; + }; uint32_t m_flags = 0; // A copy of the flags from the original symbol table, // the ObjectFile plug-in can interpret these }; diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 78d1fd2e569c3..79048c271f0ac 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -9,6 +9,7 @@ #include "lldb/Symbol/Symbol.h" #include "lldb/Core/Address.h" +#include "lldb/Core/DataFileCache.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -45,8 +46,13 @@ Symbol::Symbol(uint32_t symID, llvm::StringRef name, SymbolType type, m_size_is_synthesized(false), m_size_is_valid(size_is_valid || size > 0), m_demangled_is_synthesized(false), m_contains_linker_annotations(contains_linker_annotations), - m_is_weak(false), m_type(type), m_mangled(name), - m_addr_range(section_sp, offset, size), m_flags(flags) {} + m_is_weak(false), m_type(type), m_mangled(name), m_addr_range(), + m_flags(flags) { + if (m_type == eSymbolTypeReExported) + m_reexport_info = ReExportInfo(); + else + m_addr_range = AddressRange(section_sp, offset, size); +} Symbol::Symbol(uint32_t symID, const Mangled &mangled, SymbolType type, bool external, bool is_debug, bool is_trampoline, @@ -60,8 +66,13 @@ Symbol::Symbol(uint32_t symID, const Mangled &mangled, SymbolType type, m_size_is_valid(size_is_valid || range.GetByteSize() > 0), m_demangled_is_synthesized(false), m_contains_linker_annotations(contains_linker_annotations), - m_is_weak(false), m_type(type), m_mangled(mangled), m_addr_range(range), - m_flags(flags) {} + m_is_weak(false), m_type(type), m_mangled(mangled), m_addr_range(), + m_flags(flags) { + if (m_type == eSymbolTypeReExported) + m_reexport_info = ReExportInfo(); + else + m_addr_range = range; +} Symbol::Symbol(const Symbol &rhs) : SymbolContextScope(rhs), m_uid(rhs.m_uid), m_type_data(rhs.m_type_data), @@ -73,7 +84,12 @@ Symbol::Symbol(const Symbol &rhs) m_demangled_is_synthesized(rhs.m_demangled_is_synthesized), m_contains_linker_annotations(rhs.m_contains_linker_annotations), m_is_weak(rhs.m_is_weak), m_type(rhs.m_type), m_mangled(rhs.m_mangled), - m_addr_range(rhs.m_addr_range), m_flags(rhs.m_flags) {} + m_addr_range(), m_flags(rhs.m_flags) { + if (rhs.m_type == eSymbolTypeReExported) + m_reexport_info = rhs.m_reexport_info; + else + m_addr_range = rhs.m_addr_range; +} const Symbol &Symbol::operator=(const Symbol &rhs) { if (this != &rhs) { @@ -90,9 +106,14 @@ const Symbol &Symbol::operator=(const Symbol &rhs) { m_demangled_is_synthesized = rhs.m_demangled_is_synthesized; m_contains_linker_annotations = rhs.m_contains_linker_annotations; m_is_weak = rhs.m_is_weak; - m_type = rhs.m_type; m_mangled = rhs.m_mangled; - m_addr_range = rhs.m_addr_range; + if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) + m_addr_range.Clear(); + m_type = rhs.m_type; + if (rhs.m_type == eSymbolTypeReExported) + m_reexport_info = rhs.m_reexport_info; + else + m_addr_range = rhs.m_addr_range; m_flags = rhs.m_flags; } return *this; @@ -163,6 +184,8 @@ void Symbol::Clear() { } bool Symbol::ValueIsAddress() const { + if (m_type == eSymbolTypeReExported) + return false; return (bool)m_addr_range.GetBaseAddress().GetSection(); } @@ -171,47 +194,36 @@ ConstString Symbol::GetDisplayName() const { } ConstString Symbol::GetReExportedSymbolName() const { - if (m_type == eSymbolTypeReExported) { - // For eSymbolTypeReExported, the "const char *" from a ConstString is used - // as the offset in the address range base address. We can then make this - // back into a string that is the re-exported name. - intptr_t str_ptr = m_addr_range.GetBaseAddress().GetOffset(); - if (str_ptr != 0) - return ConstString((const char *)str_ptr); - else - return GetName(); - } - return ConstString(); + if (m_type != eSymbolTypeReExported) + return ConstString(); + + return m_reexport_info.name; } FileSpec Symbol::GetReExportedSymbolSharedLibrary() const { - if (m_type == eSymbolTypeReExported) { - // For eSymbolTypeReExported, the "const char *" from a ConstString is used - // as the offset in the address range base address. We can then make this - // back into a string that is the re-exported name. - intptr_t str_ptr = m_addr_range.GetByteSize(); - if (str_ptr != 0) - return FileSpec((const char *)str_ptr); - } - return FileSpec(); + if (m_type != eSymbolTypeReExported) + return FileSpec(); + + return m_reexport_info.library; } void Symbol::SetReExportedSymbolName(ConstString name) { - SetType(eSymbolTypeReExported); - // For eSymbolTypeReExported, the "const char *" from a ConstString is used - // as the offset in the address range base address. - m_addr_range.GetBaseAddress().SetOffset((uintptr_t)name.GetCString()); + if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) + m_addr_range.Clear(); + if (m_type != eSymbolTypeReExported) + m_reexport_info = ReExportInfo(); + m_type = eSymbolTypeReExported; + m_reexport_info.name = name; } bool Symbol::SetReExportedSymbolSharedLibrary(const FileSpec &fspec) { - if (m_type == eSymbolTypeReExported) { - // For eSymbolTypeReExported, the "const char *" from a ConstString is used - // as the offset in the address range base address. - m_addr_range.SetByteSize( - (uintptr_t)ConstString(fspec.GetPath()).GetCString()); - return true; - } - return false; + if (m_type != eSymbolTypeReExported) + return false; + if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) + m_addr_range.Clear(); + m_type = eSymbolTypeReExported; + m_reexport_info.library = fspec; + return true; } uint32_t Symbol::GetSiblingIndex() const { @@ -292,12 +304,12 @@ void Symbol::Dump(Stream *s, Target *target, uint32_t index, " 0x%8.8x %s", m_flags, name.AsCString("")); - ConstString reexport_name = GetReExportedSymbolName(); - intptr_t shlib = m_addr_range.GetByteSize(); + const FileSpec &shlib = GetReExportedSymbolSharedLibrary(); if (shlib) - s->Printf(" -> %s`%s\n", (const char *)shlib, reexport_name.GetCString()); + s->Printf(" -> %s`%s\n", shlib.GetPath().c_str(), + GetReExportedSymbolName().GetCString()); else - s->Printf(" -> %s\n", reexport_name.GetCString()); + s->Printf(" -> %s\n", GetReExportedSymbolName().GetCString()); } else { const char *format = m_size_is_sibling @@ -431,7 +443,7 @@ void Symbol::DumpSymbolContext(Stream *s) { lldb::addr_t Symbol::GetByteSize() const { return m_addr_range.GetByteSize(); } Symbol *Symbol::ResolveReExportedSymbolInModuleSpec( - Target &target, ConstString &reexport_name, ModuleSpec &module_spec, + Target &target, ConstString reexport_name, ModuleSpec &module_spec, ModuleList &seen_modules) const { ModuleSP module_sp; if (module_spec.GetFileSpec()) { @@ -632,16 +644,25 @@ bool Symbol::Decode(const DataExtractor &data, lldb::offset_t *offset_ptr, return false; if (!data.ValidOffsetForDataOfSize(*offset_ptr, 20)) return false; - const bool is_addr = data.GetU8(offset_ptr) != 0; - const uint64_t value = data.GetU64(offset_ptr); - if (is_addr) { - m_addr_range.GetBaseAddress().ResolveAddressUsingFileSections(value, - section_list); + if (m_type != eSymbolTypeReExported) { + const bool is_addr = data.GetU8(offset_ptr) != 0; + const uint64_t value = data.GetU64(offset_ptr); + if (is_addr) { + m_addr_range.GetBaseAddress().ResolveAddressUsingFileSections( + value, section_list); + } else { + m_addr_range.GetBaseAddress().Clear(); + m_addr_range.GetBaseAddress().SetOffset(value); + } + m_addr_range.SetByteSize(data.GetU64(offset_ptr)); } else { - m_addr_range.GetBaseAddress().Clear(); - m_addr_range.GetBaseAddress().SetOffset(value); + m_reexport_info.name = ConstString(strtab.Get(data.GetU32(offset_ptr))); + // m_reexport_info.library is calculated based on the + // binaries loaded in the target, lazily. It is not + // saved in the serialized Symbol format as it could vary + // depending on the Target libraries. + m_reexport_info.library = FileSpec(); } - m_addr_range.SetByteSize(data.GetU64(offset_ptr)); m_flags = data.GetU32(offset_ptr); return true; } @@ -698,14 +719,22 @@ void Symbol::Encode(DataEncoder &file, ConstStringTable &strtab) const { bitfields |= 1u << 6; file.AppendU16(bitfields); m_mangled.Encode(file, strtab); - // A symbol's value might be an address, or it might be a constant. If the - // symbol's base address doesn't have a section, then it is a constant value. - // If it does have a section, we will encode the file address and re-resolve - // the address when we decode it. - bool is_addr = m_addr_range.GetBaseAddress().GetSection().get() != nullptr; - file.AppendU8(is_addr); - file.AppendU64(m_addr_range.GetBaseAddress().GetFileAddress()); - file.AppendU64(m_addr_range.GetByteSize()); + if (m_type != eSymbolTypeReExported) { + // A symbol's value might be an address, or it might be a constant. If the + // symbol's base address doesn't have a section, then it is a constant + // value. If it does have a section, we will encode the file address and + // re-resolve the address when we decode it. + bool is_addr = m_addr_range.GetBaseAddress().GetSection().get() != nullptr; + file.AppendU8(is_addr); + file.AppendU64(m_addr_range.GetBaseAddress().GetFileAddress()); + file.AppendU64(m_addr_range.GetByteSize()); + } else { + file.AppendU32(strtab.Add(m_reexport_info.name)); + // m_reexport_info.library is calculated based on the + // binaries loaded in the target, lazily. It is not + // saved in the serialized Symbol format as it could vary + // depending on the Target libraries. + } file.AppendU32(m_flags); } >From b35a9dfe618b6657f62347cd398c6c745ddcf096 Mon Sep 17 00:00:00 2001 From: Jason Molenda <[email protected]> Date: Tue, 11 Aug 2026 17:30:19 -0700 Subject: [PATCH 2/3] Move the union {AddressRange, ReExportInfo} into a class and restrict access to them to go through getter/setter methods, and assert that the symbol type is correct for the object being requested in debug builds. Fix one place (Symbol::Dump calling GetByteSize()) where the incorrect version was being used for re-export symbols. --- lldb/include/lldb/Symbol/Symbol.h | 66 +++++++--- lldb/source/Symbol/Symbol.cpp | 207 +++++++++++++++++++++--------- 2 files changed, 194 insertions(+), 79 deletions(-) diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h index 895a1fed88cce..9e14c1cbab504 100644 --- a/lldb/include/lldb/Symbol/Symbol.h +++ b/lldb/include/lldb/Symbol/Symbol.h @@ -54,7 +54,7 @@ class Symbol : public SymbolContextScope { ~Symbol() { if (m_type != lldb::eSymbolTypeReExported && m_type != lldb::eSymbolTypeInvalid) - m_addr_range.Clear(); + m_addr_or_reexport.GetAddressRange(*this).Clear(); } const Symbol &operator=(const Symbol &rhs); @@ -77,9 +77,13 @@ class Symbol : public SymbolContextScope { // an Address object that contains an constant integer value in // m_addr_range.m_base_addr.m_offset which could be incorrectly used to // represent an absolute address since it has no section. - Address &GetAddressRef() { return m_addr_range.GetBaseAddress(); } + Address &GetAddressRef() { + return m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); + } - const Address &GetAddressRef() const { return m_addr_range.GetBaseAddress(); } + const Address &GetAddressRef() const { + return m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); + } // Makes sure the symbol's value is an address and returns the file address. // Returns LLDB_INVALID_ADDRESS if the symbol's value isn't an address. @@ -103,7 +107,7 @@ class Symbol : public SymbolContextScope { // GetAddress() accessor, we need to hand out an invalid address if the // symbol's value isn't an address. if (ValueIsAddress()) - return m_addr_range.GetBaseAddress(); + return m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); else return Address(); } @@ -115,7 +119,9 @@ class Symbol : public SymbolContextScope { /// no section, then getting the file address will return the correct value /// as it will return the offset in the base address which is the value. uint64_t GetRawValue() const { - return m_addr_range.GetBaseAddress().GetFileAddress(); + return m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetFileAddress(); } // When a symbol's value isn't an address, we need to access the raw value. @@ -129,7 +135,9 @@ class Symbol : public SymbolContextScope { return fail_value; } else { // The value is stored in the base address' offset - return m_addr_range.GetBaseAddress().GetOffset(); + return m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetOffset(); } } @@ -219,7 +227,7 @@ class Symbol : public SymbolContextScope { void SetByteSize(lldb::addr_t size) { m_size_is_valid = size > 0; - m_addr_range.SetByteSize(size); + m_addr_or_reexport.GetAddressRange(*this).SetByteSize(size); } bool GetSizeIsSibling() const { return m_size_is_sibling; } @@ -340,6 +348,7 @@ class Symbol : public SymbolContextScope { ConstString name; FileSpec library; ReExportInfo() : name(), library() {} + void Clear() { library.Clear(); } }; uint32_t m_uid = LLDB_INVALID_SYMBOL_ID; // User ID (usually the original @@ -368,16 +377,39 @@ class Symbol : public SymbolContextScope { m_is_weak : 1, m_type : 6; // Values from the lldb::SymbolType enum. mutable Mangled m_mangled; // uniqued symbol name/mangled name pair - union { - // Contains the value, or the section offset address when the value is an - // address in a section, and the size (if known). For non-re-export - // symbols. - AddressRange m_addr_range; - - // Stores re-export information if this symbol is of type - // eSymbolTypeReExported; no address information for these symbols. - ReExportInfo m_reexport_info; - }; + + // A wrapper around a `union {AddressRange, ReExportInfo}` to + // enforce the types being get/set match the Symbol's m_type, + // assert if there is a type mismatch. + struct AddrRangeOrReExport { + AddressRange &GetAddressRange(Symbol &sym); + const AddressRange &GetAddressRange(const Symbol &sym) const; + ReExportInfo &GetReExportInfo(Symbol &sym); + const ReExportInfo &GetReExportInfo(const Symbol &sym) const; + void SetAddressRange(Symbol &sym, const AddressRange addr_range); + void SetRexportInfo(Symbol &sym, const ReExportInfo reexport_info); + + AddrRangeOrReExport(const Symbol &sym) : m_addr_range() { + if (sym.GetType() == lldb::eSymbolTypeReExported) + m_reexport_info = ReExportInfo(); + } + // Proper destruction is handled by Symbol's dtor; supply a no-op + // impl to let the compiler know it's handled. + ~AddrRangeOrReExport() {} + + private: + union { + // Contains the value, or the section offset address when the value is an + // address in a section, and the size (if known). For non-re-export + // symbols. + AddressRange m_addr_range; + + // Stores re-export information if this symbol is of type + // eSymbolTypeReExported; no address information for these symbols. + ReExportInfo m_reexport_info; + }; + } m_addr_or_reexport; + uint32_t m_flags = 0; // A copy of the flags from the original symbol table, // the ObjectFile plug-in can interpret these }; diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 79048c271f0ac..3c40320434d31 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -33,7 +33,7 @@ Symbol::Symbol() m_size_is_synthesized(false), m_size_is_valid(false), m_demangled_is_synthesized(false), m_contains_linker_annotations(false), m_is_weak(false), m_type(eSymbolTypeInvalid), m_mangled(), - m_addr_range() {} + m_addr_or_reexport(*this) {} Symbol::Symbol(uint32_t symID, llvm::StringRef name, SymbolType type, bool external, bool is_debug, bool is_trampoline, @@ -46,12 +46,13 @@ Symbol::Symbol(uint32_t symID, llvm::StringRef name, SymbolType type, m_size_is_synthesized(false), m_size_is_valid(size_is_valid || size > 0), m_demangled_is_synthesized(false), m_contains_linker_annotations(contains_linker_annotations), - m_is_weak(false), m_type(type), m_mangled(name), m_addr_range(), - m_flags(flags) { + m_is_weak(false), m_type(type), m_mangled(name), + m_addr_or_reexport(*this), m_flags(flags) { if (m_type == eSymbolTypeReExported) - m_reexport_info = ReExportInfo(); + m_addr_or_reexport.SetRexportInfo(*this, ReExportInfo()); else - m_addr_range = AddressRange(section_sp, offset, size); + m_addr_or_reexport.SetAddressRange(*this, + AddressRange(section_sp, offset, size)); } Symbol::Symbol(uint32_t symID, const Mangled &mangled, SymbolType type, @@ -66,12 +67,12 @@ Symbol::Symbol(uint32_t symID, const Mangled &mangled, SymbolType type, m_size_is_valid(size_is_valid || range.GetByteSize() > 0), m_demangled_is_synthesized(false), m_contains_linker_annotations(contains_linker_annotations), - m_is_weak(false), m_type(type), m_mangled(mangled), m_addr_range(), - m_flags(flags) { + m_is_weak(false), m_type(type), m_mangled(mangled), + m_addr_or_reexport(*this), m_flags(flags) { if (m_type == eSymbolTypeReExported) - m_reexport_info = ReExportInfo(); + m_addr_or_reexport.SetRexportInfo(*this, ReExportInfo()); else - m_addr_range = range; + m_addr_or_reexport.SetAddressRange(*this, range); } Symbol::Symbol(const Symbol &rhs) @@ -84,11 +85,13 @@ Symbol::Symbol(const Symbol &rhs) m_demangled_is_synthesized(rhs.m_demangled_is_synthesized), m_contains_linker_annotations(rhs.m_contains_linker_annotations), m_is_weak(rhs.m_is_weak), m_type(rhs.m_type), m_mangled(rhs.m_mangled), - m_addr_range(), m_flags(rhs.m_flags) { + m_addr_or_reexport(*this), m_flags(rhs.m_flags) { if (rhs.m_type == eSymbolTypeReExported) - m_reexport_info = rhs.m_reexport_info; + m_addr_or_reexport.SetRexportInfo( + *this, rhs.m_addr_or_reexport.GetReExportInfo(*this)); else - m_addr_range = rhs.m_addr_range; + m_addr_or_reexport.SetAddressRange( + *this, rhs.m_addr_or_reexport.GetAddressRange(*this)); } const Symbol &Symbol::operator=(const Symbol &rhs) { @@ -108,12 +111,14 @@ const Symbol &Symbol::operator=(const Symbol &rhs) { m_is_weak = rhs.m_is_weak; m_mangled = rhs.m_mangled; if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) - m_addr_range.Clear(); + m_addr_or_reexport.GetAddressRange(*this).Clear(); m_type = rhs.m_type; if (rhs.m_type == eSymbolTypeReExported) - m_reexport_info = rhs.m_reexport_info; + m_addr_or_reexport.SetRexportInfo( + *this, rhs.m_addr_or_reexport.GetReExportInfo(*this)); else - m_addr_range = rhs.m_addr_range; + m_addr_or_reexport.SetAddressRange( + *this, rhs.m_addr_or_reexport.GetAddressRange(*this)); m_flags = rhs.m_flags; } return *this; @@ -180,13 +185,15 @@ void Symbol::Clear() { m_is_weak = false; m_type = eSymbolTypeInvalid; m_flags = 0; - m_addr_range.Clear(); + m_addr_or_reexport.GetAddressRange(*this).Clear(); } bool Symbol::ValueIsAddress() const { if (m_type == eSymbolTypeReExported) return false; - return (bool)m_addr_range.GetBaseAddress().GetSection(); + return (bool)m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetSection(); } ConstString Symbol::GetDisplayName() const { @@ -197,37 +204,39 @@ ConstString Symbol::GetReExportedSymbolName() const { if (m_type != eSymbolTypeReExported) return ConstString(); - return m_reexport_info.name; + return m_addr_or_reexport.GetReExportInfo(*this).name; } FileSpec Symbol::GetReExportedSymbolSharedLibrary() const { if (m_type != eSymbolTypeReExported) return FileSpec(); - return m_reexport_info.library; + return m_addr_or_reexport.GetReExportInfo(*this).library; } void Symbol::SetReExportedSymbolName(ConstString name) { if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) - m_addr_range.Clear(); + m_addr_or_reexport.GetAddressRange(*this).Clear(); if (m_type != eSymbolTypeReExported) - m_reexport_info = ReExportInfo(); + m_addr_or_reexport.SetRexportInfo(*this, ReExportInfo()); m_type = eSymbolTypeReExported; - m_reexport_info.name = name; + m_addr_or_reexport.GetReExportInfo(*this).name = name; } bool Symbol::SetReExportedSymbolSharedLibrary(const FileSpec &fspec) { if (m_type != eSymbolTypeReExported) return false; if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) - m_addr_range.Clear(); + m_addr_or_reexport.GetAddressRange(*this).Clear(); m_type = eSymbolTypeReExported; - m_reexport_info.library = fspec; + m_addr_or_reexport.GetReExportInfo(*this).library = fspec; return true; } uint32_t Symbol::GetSiblingIndex() const { - return m_size_is_sibling ? m_addr_range.GetByteSize() : UINT32_MAX; + return m_size_is_sibling + ? m_addr_or_reexport.GetAddressRange(*this).GetByteSize() + : UINT32_MAX; } bool Symbol::IsTrampoline() const { return m_type == eSymbolTypeTrampoline; } @@ -239,29 +248,36 @@ void Symbol::GetDescription( std::optional<Stream::HighlightSettings> settings) const { s->Printf("id = {0x%8.8x}", m_uid); - if (m_addr_range.GetBaseAddress().GetSection()) { + if (m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().GetSection()) { if (ValueIsAddress()) { const lldb::addr_t byte_size = GetByteSize(); if (byte_size > 0) { s->PutCString(", range = "); - m_addr_range.Dump(s, target, Address::DumpStyleLoadAddress, - Address::DumpStyleFileAddress); + m_addr_or_reexport.GetAddressRange(*this).Dump( + s, target, Address::DumpStyleLoadAddress, + Address::DumpStyleFileAddress); } else { s->PutCString(", address = "); - m_addr_range.GetBaseAddress().Dump(s, target, - Address::DumpStyleLoadAddress, - Address::DumpStyleFileAddress); + m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Dump( + s, target, Address::DumpStyleLoadAddress, + Address::DumpStyleFileAddress); } } else s->Printf(", value = 0x%16.16" PRIx64, - m_addr_range.GetBaseAddress().GetOffset()); + m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetOffset()); } else { if (m_size_is_sibling) s->Printf(", sibling = %5" PRIu64, - m_addr_range.GetBaseAddress().GetOffset()); + m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetOffset()); else s->Printf(", value = 0x%16.16" PRIx64, - m_addr_range.GetBaseAddress().GetOffset()); + m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetOffset()); } if (ConstString demangled = m_mangled.GetDemangledName()) { s->PutCString(", name=\""); @@ -286,14 +302,14 @@ void Symbol::Dump(Stream *s, Target *target, uint32_t index, ConstString name = GetMangled().GetName(name_preference); if (ValueIsAddress()) { - if (!m_addr_range.GetBaseAddress().Dump(s, nullptr, - Address::DumpStyleFileAddress)) + if (!m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Dump( + s, nullptr, Address::DumpStyleFileAddress)) s->Printf("%*s", 18, ""); s->PutChar(' '); - if (!m_addr_range.GetBaseAddress().Dump(s, target, - Address::DumpStyleLoadAddress)) + if (!m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Dump( + s, target, Address::DumpStyleLoadAddress)) s->Printf("%*s", 18, ""); const char *format = m_size_is_sibling ? " Sibling -> [%5llu] 0x%8.8x %s\n" @@ -317,8 +333,10 @@ void Symbol::Dump(Stream *s, Target *target, uint32_t index, " Sibling -> [%5llu] 0x%8.8x %s\n" : "0x%16.16" PRIx64 " 0x%16.16" PRIx64 " 0x%8.8x %s\n"; - s->Printf(format, m_addr_range.GetBaseAddress().GetOffset(), GetByteSize(), - m_flags, name.AsCString("")); + s->Printf( + format, + m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().GetOffset(), + GetByteSize(), m_flags, name.AsCString("")); } } @@ -327,7 +345,8 @@ uint32_t Symbol::GetPrologueByteSize() { if (!m_type_data_resolved) { m_type_data_resolved = true; - const Address &base_address = m_addr_range.GetBaseAddress(); + const Address &base_address = + m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); Function *function = base_address.CalculateSymbolContextFunction(); if (function) { // Functions have line entries which can also potentially have end of @@ -371,7 +390,8 @@ uint32_t Symbol::GetPrologueByteSize() { addr.Slide(sc_temp.line_entry.range.GetByteSize()); total_offset += sc_temp.line_entry.range.GetByteSize(); // If we've gone too far, bail out. - if (total_offset >= m_addr_range.GetByteSize()) + if (total_offset >= + m_addr_or_reexport.GetAddressRange(*this).GetByteSize()) break; } @@ -380,7 +400,8 @@ uint32_t Symbol::GetPrologueByteSize() { // entries surrounding us won't lie inside our function. In that // case, the line entry will be bigger than we are, so we do that // quick check and if that is true, we just return 0. - if (m_type_data >= m_addr_range.GetByteSize()) + if (m_type_data >= + m_addr_or_reexport.GetAddressRange(*this).GetByteSize()) m_type_data = 0; } else { // TODO: expose something in Process to figure out the @@ -440,7 +461,12 @@ void Symbol::DumpSymbolContext(Stream *s) { s->Printf("Symbol{0x%8.8x}", GetID()); } -lldb::addr_t Symbol::GetByteSize() const { return m_addr_range.GetByteSize(); } +lldb::addr_t Symbol::GetByteSize() const { + if (GetType() == eSymbolTypeReExported) + return 0; + else + return m_addr_or_reexport.GetAddressRange(*this).GetByteSize(); +} Symbol *Symbol::ResolveReExportedSymbolInModuleSpec( Target &target, ConstString reexport_name, ModuleSpec &module_spec, @@ -564,11 +590,13 @@ lldb::addr_t Symbol::ResolveCallableAddress(Target &target) const { lldb::DisassemblerSP Symbol::GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool prefer_file_cache) { - ModuleSP module_sp(m_addr_range.GetBaseAddress().GetModule()); + ModuleSP module_sp( + m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().GetModule()); if (module_sp && exe_ctx.HasTargetScope()) { return Disassembler::DisassembleRange( module_sp->GetArchitecture(), nullptr, flavor, nullptr, nullptr, - exe_ctx.GetTargetRef(), m_addr_range, !prefer_file_cache); + exe_ctx.GetTargetRef(), m_addr_or_reexport.GetAddressRange(*this), + !prefer_file_cache); } return lldb::DisassemblerSP(); } @@ -589,7 +617,8 @@ bool Symbol::GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, } bool Symbol::ContainsFileAddress(lldb::addr_t file_addr) const { - return m_addr_range.ContainsFileAddress(file_addr); + return m_addr_or_reexport.GetAddressRange(*this).ContainsFileAddress( + file_addr); } bool Symbol::IsSyntheticWithAutoGeneratedName() const { @@ -615,8 +644,10 @@ void Symbol::SynthesizeNameIfNeeded() const { llvm::SmallString<256> name; llvm::raw_svector_ostream os(name); os << GetSyntheticSymbolPrefix() - << llvm::format_hex_no_prefix( - m_addr_range.GetBaseAddress().GetFileAddress(), 0); + << llvm::format_hex_no_prefix(m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetFileAddress(), + 0); m_mangled.SetDemangledName(ConstString(os.str())); } } @@ -648,20 +679,24 @@ bool Symbol::Decode(const DataExtractor &data, lldb::offset_t *offset_ptr, const bool is_addr = data.GetU8(offset_ptr) != 0; const uint64_t value = data.GetU64(offset_ptr); if (is_addr) { - m_addr_range.GetBaseAddress().ResolveAddressUsingFileSections( - value, section_list); + m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .ResolveAddressUsingFileSections(value, section_list); } else { - m_addr_range.GetBaseAddress().Clear(); - m_addr_range.GetBaseAddress().SetOffset(value); + m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Clear(); + m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().SetOffset( + value); } - m_addr_range.SetByteSize(data.GetU64(offset_ptr)); + m_addr_or_reexport.GetAddressRange(*this).SetByteSize( + data.GetU64(offset_ptr)); } else { - m_reexport_info.name = ConstString(strtab.Get(data.GetU32(offset_ptr))); + m_addr_or_reexport.GetReExportInfo(*this).name = + ConstString(strtab.Get(data.GetU32(offset_ptr))); // m_reexport_info.library is calculated based on the // binaries loaded in the target, lazily. It is not // saved in the serialized Symbol format as it could vary // depending on the Target libraries. - m_reexport_info.library = FileSpec(); + m_addr_or_reexport.GetReExportInfo(*this).library = FileSpec(); } m_flags = data.GetU32(offset_ptr); return true; @@ -724,12 +759,17 @@ void Symbol::Encode(DataEncoder &file, ConstStringTable &strtab) const { // symbol's base address doesn't have a section, then it is a constant // value. If it does have a section, we will encode the file address and // re-resolve the address when we decode it. - bool is_addr = m_addr_range.GetBaseAddress().GetSection().get() != nullptr; + bool is_addr = m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetSection() + .get() != nullptr; file.AppendU8(is_addr); - file.AppendU64(m_addr_range.GetBaseAddress().GetFileAddress()); - file.AppendU64(m_addr_range.GetByteSize()); + file.AppendU64(m_addr_or_reexport.GetAddressRange(*this) + .GetBaseAddress() + .GetFileAddress()); + file.AppendU64(m_addr_or_reexport.GetAddressRange(*this).GetByteSize()); } else { - file.AppendU32(strtab.Add(m_reexport_info.name)); + file.AppendU32(strtab.Add(m_addr_or_reexport.GetReExportInfo(*this).name)); // m_reexport_info.library is calculated based on the // binaries loaded in the target, lazily. It is not // saved in the serialized Symbol format as it could vary @@ -767,9 +807,11 @@ bool Symbol::operator==(const Symbol &rhs) const { return false; if (m_mangled != rhs.m_mangled) return false; - if (m_addr_range.GetBaseAddress() != rhs.m_addr_range.GetBaseAddress()) + if (m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress() != + rhs.m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress()) return false; - if (m_addr_range.GetByteSize() != rhs.m_addr_range.GetByteSize()) + if (m_addr_or_reexport.GetAddressRange(*this).GetByteSize() != + rhs.m_addr_or_reexport.GetAddressRange(*this).GetByteSize()) return false; if (m_flags != rhs.m_flags) return false; @@ -849,6 +891,47 @@ lldb::SymbolType Symbol::GetTypeFromString(const char *str) { .Default(eSymbolTypeInvalid); } +AddressRange &Symbol::AddrRangeOrReExport::GetAddressRange(Symbol &sym) { + assert(sym.GetType() != eSymbolTypeReExported); + return m_addr_range; +} + +const AddressRange & +Symbol::AddrRangeOrReExport::GetAddressRange(const Symbol &sym) const { + assert(sym.GetType() != eSymbolTypeReExported); + return m_addr_range; +} + +Symbol::ReExportInfo & +Symbol::AddrRangeOrReExport::GetReExportInfo(Symbol &sym) { + assert(sym.GetType() == eSymbolTypeReExported); + return m_reexport_info; +} + +const Symbol::ReExportInfo & +Symbol::AddrRangeOrReExport::GetReExportInfo(const Symbol &sym) const { + assert(sym.GetType() == eSymbolTypeReExported); + return m_reexport_info; +} + +void Symbol::AddrRangeOrReExport::SetAddressRange( + Symbol &sym, const AddressRange addr_range) { + if (sym.GetType() == eSymbolTypeReExported) { + m_reexport_info.Clear(); + sym.SetType(eSymbolTypeInvalid); + } + m_addr_range = addr_range; +} + +void Symbol::AddrRangeOrReExport::SetRexportInfo( + Symbol &sym, const Symbol::ReExportInfo reexport_info) { + if (sym.GetType() != eSymbolTypeReExported) { + m_addr_range.Clear(); + sym.SetType(eSymbolTypeReExported); + } + m_reexport_info = reexport_info; +} + namespace llvm { namespace json { >From 088c545bfae2b84b99ef11cd30af6644feef4f2e Mon Sep 17 00:00:00 2001 From: Jason Molenda <[email protected]> Date: Tue, 11 Aug 2026 17:59:50 -0700 Subject: [PATCH 3/3] Revert "Move the union {AddressRange, ReExportInfo} into a class" Try reverting this and going back to a simple `union{}` to see if the `Symbol` size increase that is causing fails on the Windows/Linux PR testing still happens. I'm not sure I looked at the bot results back when it was a union. This reverts commit b35a9dfe618b6657f62347cd398c6c745ddcf096. --- lldb/include/lldb/Symbol/Symbol.h | 66 +++------- lldb/source/Symbol/Symbol.cpp | 207 +++++++++--------------------- 2 files changed, 79 insertions(+), 194 deletions(-) diff --git a/lldb/include/lldb/Symbol/Symbol.h b/lldb/include/lldb/Symbol/Symbol.h index 9e14c1cbab504..895a1fed88cce 100644 --- a/lldb/include/lldb/Symbol/Symbol.h +++ b/lldb/include/lldb/Symbol/Symbol.h @@ -54,7 +54,7 @@ class Symbol : public SymbolContextScope { ~Symbol() { if (m_type != lldb::eSymbolTypeReExported && m_type != lldb::eSymbolTypeInvalid) - m_addr_or_reexport.GetAddressRange(*this).Clear(); + m_addr_range.Clear(); } const Symbol &operator=(const Symbol &rhs); @@ -77,13 +77,9 @@ class Symbol : public SymbolContextScope { // an Address object that contains an constant integer value in // m_addr_range.m_base_addr.m_offset which could be incorrectly used to // represent an absolute address since it has no section. - Address &GetAddressRef() { - return m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); - } + Address &GetAddressRef() { return m_addr_range.GetBaseAddress(); } - const Address &GetAddressRef() const { - return m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); - } + const Address &GetAddressRef() const { return m_addr_range.GetBaseAddress(); } // Makes sure the symbol's value is an address and returns the file address. // Returns LLDB_INVALID_ADDRESS if the symbol's value isn't an address. @@ -107,7 +103,7 @@ class Symbol : public SymbolContextScope { // GetAddress() accessor, we need to hand out an invalid address if the // symbol's value isn't an address. if (ValueIsAddress()) - return m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); + return m_addr_range.GetBaseAddress(); else return Address(); } @@ -119,9 +115,7 @@ class Symbol : public SymbolContextScope { /// no section, then getting the file address will return the correct value /// as it will return the offset in the base address which is the value. uint64_t GetRawValue() const { - return m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetFileAddress(); + return m_addr_range.GetBaseAddress().GetFileAddress(); } // When a symbol's value isn't an address, we need to access the raw value. @@ -135,9 +129,7 @@ class Symbol : public SymbolContextScope { return fail_value; } else { // The value is stored in the base address' offset - return m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetOffset(); + return m_addr_range.GetBaseAddress().GetOffset(); } } @@ -227,7 +219,7 @@ class Symbol : public SymbolContextScope { void SetByteSize(lldb::addr_t size) { m_size_is_valid = size > 0; - m_addr_or_reexport.GetAddressRange(*this).SetByteSize(size); + m_addr_range.SetByteSize(size); } bool GetSizeIsSibling() const { return m_size_is_sibling; } @@ -348,7 +340,6 @@ class Symbol : public SymbolContextScope { ConstString name; FileSpec library; ReExportInfo() : name(), library() {} - void Clear() { library.Clear(); } }; uint32_t m_uid = LLDB_INVALID_SYMBOL_ID; // User ID (usually the original @@ -377,39 +368,16 @@ class Symbol : public SymbolContextScope { m_is_weak : 1, m_type : 6; // Values from the lldb::SymbolType enum. mutable Mangled m_mangled; // uniqued symbol name/mangled name pair - - // A wrapper around a `union {AddressRange, ReExportInfo}` to - // enforce the types being get/set match the Symbol's m_type, - // assert if there is a type mismatch. - struct AddrRangeOrReExport { - AddressRange &GetAddressRange(Symbol &sym); - const AddressRange &GetAddressRange(const Symbol &sym) const; - ReExportInfo &GetReExportInfo(Symbol &sym); - const ReExportInfo &GetReExportInfo(const Symbol &sym) const; - void SetAddressRange(Symbol &sym, const AddressRange addr_range); - void SetRexportInfo(Symbol &sym, const ReExportInfo reexport_info); - - AddrRangeOrReExport(const Symbol &sym) : m_addr_range() { - if (sym.GetType() == lldb::eSymbolTypeReExported) - m_reexport_info = ReExportInfo(); - } - // Proper destruction is handled by Symbol's dtor; supply a no-op - // impl to let the compiler know it's handled. - ~AddrRangeOrReExport() {} - - private: - union { - // Contains the value, or the section offset address when the value is an - // address in a section, and the size (if known). For non-re-export - // symbols. - AddressRange m_addr_range; - - // Stores re-export information if this symbol is of type - // eSymbolTypeReExported; no address information for these symbols. - ReExportInfo m_reexport_info; - }; - } m_addr_or_reexport; - + union { + // Contains the value, or the section offset address when the value is an + // address in a section, and the size (if known). For non-re-export + // symbols. + AddressRange m_addr_range; + + // Stores re-export information if this symbol is of type + // eSymbolTypeReExported; no address information for these symbols. + ReExportInfo m_reexport_info; + }; uint32_t m_flags = 0; // A copy of the flags from the original symbol table, // the ObjectFile plug-in can interpret these }; diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp index 3c40320434d31..79048c271f0ac 100644 --- a/lldb/source/Symbol/Symbol.cpp +++ b/lldb/source/Symbol/Symbol.cpp @@ -33,7 +33,7 @@ Symbol::Symbol() m_size_is_synthesized(false), m_size_is_valid(false), m_demangled_is_synthesized(false), m_contains_linker_annotations(false), m_is_weak(false), m_type(eSymbolTypeInvalid), m_mangled(), - m_addr_or_reexport(*this) {} + m_addr_range() {} Symbol::Symbol(uint32_t symID, llvm::StringRef name, SymbolType type, bool external, bool is_debug, bool is_trampoline, @@ -46,13 +46,12 @@ Symbol::Symbol(uint32_t symID, llvm::StringRef name, SymbolType type, m_size_is_synthesized(false), m_size_is_valid(size_is_valid || size > 0), m_demangled_is_synthesized(false), m_contains_linker_annotations(contains_linker_annotations), - m_is_weak(false), m_type(type), m_mangled(name), - m_addr_or_reexport(*this), m_flags(flags) { + m_is_weak(false), m_type(type), m_mangled(name), m_addr_range(), + m_flags(flags) { if (m_type == eSymbolTypeReExported) - m_addr_or_reexport.SetRexportInfo(*this, ReExportInfo()); + m_reexport_info = ReExportInfo(); else - m_addr_or_reexport.SetAddressRange(*this, - AddressRange(section_sp, offset, size)); + m_addr_range = AddressRange(section_sp, offset, size); } Symbol::Symbol(uint32_t symID, const Mangled &mangled, SymbolType type, @@ -67,12 +66,12 @@ Symbol::Symbol(uint32_t symID, const Mangled &mangled, SymbolType type, m_size_is_valid(size_is_valid || range.GetByteSize() > 0), m_demangled_is_synthesized(false), m_contains_linker_annotations(contains_linker_annotations), - m_is_weak(false), m_type(type), m_mangled(mangled), - m_addr_or_reexport(*this), m_flags(flags) { + m_is_weak(false), m_type(type), m_mangled(mangled), m_addr_range(), + m_flags(flags) { if (m_type == eSymbolTypeReExported) - m_addr_or_reexport.SetRexportInfo(*this, ReExportInfo()); + m_reexport_info = ReExportInfo(); else - m_addr_or_reexport.SetAddressRange(*this, range); + m_addr_range = range; } Symbol::Symbol(const Symbol &rhs) @@ -85,13 +84,11 @@ Symbol::Symbol(const Symbol &rhs) m_demangled_is_synthesized(rhs.m_demangled_is_synthesized), m_contains_linker_annotations(rhs.m_contains_linker_annotations), m_is_weak(rhs.m_is_weak), m_type(rhs.m_type), m_mangled(rhs.m_mangled), - m_addr_or_reexport(*this), m_flags(rhs.m_flags) { + m_addr_range(), m_flags(rhs.m_flags) { if (rhs.m_type == eSymbolTypeReExported) - m_addr_or_reexport.SetRexportInfo( - *this, rhs.m_addr_or_reexport.GetReExportInfo(*this)); + m_reexport_info = rhs.m_reexport_info; else - m_addr_or_reexport.SetAddressRange( - *this, rhs.m_addr_or_reexport.GetAddressRange(*this)); + m_addr_range = rhs.m_addr_range; } const Symbol &Symbol::operator=(const Symbol &rhs) { @@ -111,14 +108,12 @@ const Symbol &Symbol::operator=(const Symbol &rhs) { m_is_weak = rhs.m_is_weak; m_mangled = rhs.m_mangled; if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) - m_addr_or_reexport.GetAddressRange(*this).Clear(); + m_addr_range.Clear(); m_type = rhs.m_type; if (rhs.m_type == eSymbolTypeReExported) - m_addr_or_reexport.SetRexportInfo( - *this, rhs.m_addr_or_reexport.GetReExportInfo(*this)); + m_reexport_info = rhs.m_reexport_info; else - m_addr_or_reexport.SetAddressRange( - *this, rhs.m_addr_or_reexport.GetAddressRange(*this)); + m_addr_range = rhs.m_addr_range; m_flags = rhs.m_flags; } return *this; @@ -185,15 +180,13 @@ void Symbol::Clear() { m_is_weak = false; m_type = eSymbolTypeInvalid; m_flags = 0; - m_addr_or_reexport.GetAddressRange(*this).Clear(); + m_addr_range.Clear(); } bool Symbol::ValueIsAddress() const { if (m_type == eSymbolTypeReExported) return false; - return (bool)m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetSection(); + return (bool)m_addr_range.GetBaseAddress().GetSection(); } ConstString Symbol::GetDisplayName() const { @@ -204,39 +197,37 @@ ConstString Symbol::GetReExportedSymbolName() const { if (m_type != eSymbolTypeReExported) return ConstString(); - return m_addr_or_reexport.GetReExportInfo(*this).name; + return m_reexport_info.name; } FileSpec Symbol::GetReExportedSymbolSharedLibrary() const { if (m_type != eSymbolTypeReExported) return FileSpec(); - return m_addr_or_reexport.GetReExportInfo(*this).library; + return m_reexport_info.library; } void Symbol::SetReExportedSymbolName(ConstString name) { if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) - m_addr_or_reexport.GetAddressRange(*this).Clear(); + m_addr_range.Clear(); if (m_type != eSymbolTypeReExported) - m_addr_or_reexport.SetRexportInfo(*this, ReExportInfo()); + m_reexport_info = ReExportInfo(); m_type = eSymbolTypeReExported; - m_addr_or_reexport.GetReExportInfo(*this).name = name; + m_reexport_info.name = name; } bool Symbol::SetReExportedSymbolSharedLibrary(const FileSpec &fspec) { if (m_type != eSymbolTypeReExported) return false; if (m_type != eSymbolTypeReExported && m_type != eSymbolTypeInvalid) - m_addr_or_reexport.GetAddressRange(*this).Clear(); + m_addr_range.Clear(); m_type = eSymbolTypeReExported; - m_addr_or_reexport.GetReExportInfo(*this).library = fspec; + m_reexport_info.library = fspec; return true; } uint32_t Symbol::GetSiblingIndex() const { - return m_size_is_sibling - ? m_addr_or_reexport.GetAddressRange(*this).GetByteSize() - : UINT32_MAX; + return m_size_is_sibling ? m_addr_range.GetByteSize() : UINT32_MAX; } bool Symbol::IsTrampoline() const { return m_type == eSymbolTypeTrampoline; } @@ -248,36 +239,29 @@ void Symbol::GetDescription( std::optional<Stream::HighlightSettings> settings) const { s->Printf("id = {0x%8.8x}", m_uid); - if (m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().GetSection()) { + if (m_addr_range.GetBaseAddress().GetSection()) { if (ValueIsAddress()) { const lldb::addr_t byte_size = GetByteSize(); if (byte_size > 0) { s->PutCString(", range = "); - m_addr_or_reexport.GetAddressRange(*this).Dump( - s, target, Address::DumpStyleLoadAddress, - Address::DumpStyleFileAddress); + m_addr_range.Dump(s, target, Address::DumpStyleLoadAddress, + Address::DumpStyleFileAddress); } else { s->PutCString(", address = "); - m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Dump( - s, target, Address::DumpStyleLoadAddress, - Address::DumpStyleFileAddress); + m_addr_range.GetBaseAddress().Dump(s, target, + Address::DumpStyleLoadAddress, + Address::DumpStyleFileAddress); } } else s->Printf(", value = 0x%16.16" PRIx64, - m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetOffset()); + m_addr_range.GetBaseAddress().GetOffset()); } else { if (m_size_is_sibling) s->Printf(", sibling = %5" PRIu64, - m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetOffset()); + m_addr_range.GetBaseAddress().GetOffset()); else s->Printf(", value = 0x%16.16" PRIx64, - m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetOffset()); + m_addr_range.GetBaseAddress().GetOffset()); } if (ConstString demangled = m_mangled.GetDemangledName()) { s->PutCString(", name=\""); @@ -302,14 +286,14 @@ void Symbol::Dump(Stream *s, Target *target, uint32_t index, ConstString name = GetMangled().GetName(name_preference); if (ValueIsAddress()) { - if (!m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Dump( - s, nullptr, Address::DumpStyleFileAddress)) + if (!m_addr_range.GetBaseAddress().Dump(s, nullptr, + Address::DumpStyleFileAddress)) s->Printf("%*s", 18, ""); s->PutChar(' '); - if (!m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Dump( - s, target, Address::DumpStyleLoadAddress)) + if (!m_addr_range.GetBaseAddress().Dump(s, target, + Address::DumpStyleLoadAddress)) s->Printf("%*s", 18, ""); const char *format = m_size_is_sibling ? " Sibling -> [%5llu] 0x%8.8x %s\n" @@ -333,10 +317,8 @@ void Symbol::Dump(Stream *s, Target *target, uint32_t index, " Sibling -> [%5llu] 0x%8.8x %s\n" : "0x%16.16" PRIx64 " 0x%16.16" PRIx64 " 0x%8.8x %s\n"; - s->Printf( - format, - m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().GetOffset(), - GetByteSize(), m_flags, name.AsCString("")); + s->Printf(format, m_addr_range.GetBaseAddress().GetOffset(), GetByteSize(), + m_flags, name.AsCString("")); } } @@ -345,8 +327,7 @@ uint32_t Symbol::GetPrologueByteSize() { if (!m_type_data_resolved) { m_type_data_resolved = true; - const Address &base_address = - m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress(); + const Address &base_address = m_addr_range.GetBaseAddress(); Function *function = base_address.CalculateSymbolContextFunction(); if (function) { // Functions have line entries which can also potentially have end of @@ -390,8 +371,7 @@ uint32_t Symbol::GetPrologueByteSize() { addr.Slide(sc_temp.line_entry.range.GetByteSize()); total_offset += sc_temp.line_entry.range.GetByteSize(); // If we've gone too far, bail out. - if (total_offset >= - m_addr_or_reexport.GetAddressRange(*this).GetByteSize()) + if (total_offset >= m_addr_range.GetByteSize()) break; } @@ -400,8 +380,7 @@ uint32_t Symbol::GetPrologueByteSize() { // entries surrounding us won't lie inside our function. In that // case, the line entry will be bigger than we are, so we do that // quick check and if that is true, we just return 0. - if (m_type_data >= - m_addr_or_reexport.GetAddressRange(*this).GetByteSize()) + if (m_type_data >= m_addr_range.GetByteSize()) m_type_data = 0; } else { // TODO: expose something in Process to figure out the @@ -461,12 +440,7 @@ void Symbol::DumpSymbolContext(Stream *s) { s->Printf("Symbol{0x%8.8x}", GetID()); } -lldb::addr_t Symbol::GetByteSize() const { - if (GetType() == eSymbolTypeReExported) - return 0; - else - return m_addr_or_reexport.GetAddressRange(*this).GetByteSize(); -} +lldb::addr_t Symbol::GetByteSize() const { return m_addr_range.GetByteSize(); } Symbol *Symbol::ResolveReExportedSymbolInModuleSpec( Target &target, ConstString reexport_name, ModuleSpec &module_spec, @@ -590,13 +564,11 @@ lldb::addr_t Symbol::ResolveCallableAddress(Target &target) const { lldb::DisassemblerSP Symbol::GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool prefer_file_cache) { - ModuleSP module_sp( - m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().GetModule()); + ModuleSP module_sp(m_addr_range.GetBaseAddress().GetModule()); if (module_sp && exe_ctx.HasTargetScope()) { return Disassembler::DisassembleRange( module_sp->GetArchitecture(), nullptr, flavor, nullptr, nullptr, - exe_ctx.GetTargetRef(), m_addr_or_reexport.GetAddressRange(*this), - !prefer_file_cache); + exe_ctx.GetTargetRef(), m_addr_range, !prefer_file_cache); } return lldb::DisassemblerSP(); } @@ -617,8 +589,7 @@ bool Symbol::GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, } bool Symbol::ContainsFileAddress(lldb::addr_t file_addr) const { - return m_addr_or_reexport.GetAddressRange(*this).ContainsFileAddress( - file_addr); + return m_addr_range.ContainsFileAddress(file_addr); } bool Symbol::IsSyntheticWithAutoGeneratedName() const { @@ -644,10 +615,8 @@ void Symbol::SynthesizeNameIfNeeded() const { llvm::SmallString<256> name; llvm::raw_svector_ostream os(name); os << GetSyntheticSymbolPrefix() - << llvm::format_hex_no_prefix(m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetFileAddress(), - 0); + << llvm::format_hex_no_prefix( + m_addr_range.GetBaseAddress().GetFileAddress(), 0); m_mangled.SetDemangledName(ConstString(os.str())); } } @@ -679,24 +648,20 @@ bool Symbol::Decode(const DataExtractor &data, lldb::offset_t *offset_ptr, const bool is_addr = data.GetU8(offset_ptr) != 0; const uint64_t value = data.GetU64(offset_ptr); if (is_addr) { - m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .ResolveAddressUsingFileSections(value, section_list); + m_addr_range.GetBaseAddress().ResolveAddressUsingFileSections( + value, section_list); } else { - m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().Clear(); - m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress().SetOffset( - value); + m_addr_range.GetBaseAddress().Clear(); + m_addr_range.GetBaseAddress().SetOffset(value); } - m_addr_or_reexport.GetAddressRange(*this).SetByteSize( - data.GetU64(offset_ptr)); + m_addr_range.SetByteSize(data.GetU64(offset_ptr)); } else { - m_addr_or_reexport.GetReExportInfo(*this).name = - ConstString(strtab.Get(data.GetU32(offset_ptr))); + m_reexport_info.name = ConstString(strtab.Get(data.GetU32(offset_ptr))); // m_reexport_info.library is calculated based on the // binaries loaded in the target, lazily. It is not // saved in the serialized Symbol format as it could vary // depending on the Target libraries. - m_addr_or_reexport.GetReExportInfo(*this).library = FileSpec(); + m_reexport_info.library = FileSpec(); } m_flags = data.GetU32(offset_ptr); return true; @@ -759,17 +724,12 @@ void Symbol::Encode(DataEncoder &file, ConstStringTable &strtab) const { // symbol's base address doesn't have a section, then it is a constant // value. If it does have a section, we will encode the file address and // re-resolve the address when we decode it. - bool is_addr = m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetSection() - .get() != nullptr; + bool is_addr = m_addr_range.GetBaseAddress().GetSection().get() != nullptr; file.AppendU8(is_addr); - file.AppendU64(m_addr_or_reexport.GetAddressRange(*this) - .GetBaseAddress() - .GetFileAddress()); - file.AppendU64(m_addr_or_reexport.GetAddressRange(*this).GetByteSize()); + file.AppendU64(m_addr_range.GetBaseAddress().GetFileAddress()); + file.AppendU64(m_addr_range.GetByteSize()); } else { - file.AppendU32(strtab.Add(m_addr_or_reexport.GetReExportInfo(*this).name)); + file.AppendU32(strtab.Add(m_reexport_info.name)); // m_reexport_info.library is calculated based on the // binaries loaded in the target, lazily. It is not // saved in the serialized Symbol format as it could vary @@ -807,11 +767,9 @@ bool Symbol::operator==(const Symbol &rhs) const { return false; if (m_mangled != rhs.m_mangled) return false; - if (m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress() != - rhs.m_addr_or_reexport.GetAddressRange(*this).GetBaseAddress()) + if (m_addr_range.GetBaseAddress() != rhs.m_addr_range.GetBaseAddress()) return false; - if (m_addr_or_reexport.GetAddressRange(*this).GetByteSize() != - rhs.m_addr_or_reexport.GetAddressRange(*this).GetByteSize()) + if (m_addr_range.GetByteSize() != rhs.m_addr_range.GetByteSize()) return false; if (m_flags != rhs.m_flags) return false; @@ -891,47 +849,6 @@ lldb::SymbolType Symbol::GetTypeFromString(const char *str) { .Default(eSymbolTypeInvalid); } -AddressRange &Symbol::AddrRangeOrReExport::GetAddressRange(Symbol &sym) { - assert(sym.GetType() != eSymbolTypeReExported); - return m_addr_range; -} - -const AddressRange & -Symbol::AddrRangeOrReExport::GetAddressRange(const Symbol &sym) const { - assert(sym.GetType() != eSymbolTypeReExported); - return m_addr_range; -} - -Symbol::ReExportInfo & -Symbol::AddrRangeOrReExport::GetReExportInfo(Symbol &sym) { - assert(sym.GetType() == eSymbolTypeReExported); - return m_reexport_info; -} - -const Symbol::ReExportInfo & -Symbol::AddrRangeOrReExport::GetReExportInfo(const Symbol &sym) const { - assert(sym.GetType() == eSymbolTypeReExported); - return m_reexport_info; -} - -void Symbol::AddrRangeOrReExport::SetAddressRange( - Symbol &sym, const AddressRange addr_range) { - if (sym.GetType() == eSymbolTypeReExported) { - m_reexport_info.Clear(); - sym.SetType(eSymbolTypeInvalid); - } - m_addr_range = addr_range; -} - -void Symbol::AddrRangeOrReExport::SetRexportInfo( - Symbol &sym, const Symbol::ReExportInfo reexport_info) { - if (sym.GetType() != eSymbolTypeReExported) { - m_addr_range.Clear(); - sym.SetType(eSymbolTypeReExported); - } - m_reexport_info = reexport_info; -} - namespace llvm { namespace json { _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
