[Lldb-commits] [lldb] Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created" (PR #108715)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sat Sep 14 10:50:16 PDT 2024
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/108715
Reverts llvm/llvm-project#106791 because it breaks `trap_frame_sym_ctx.test ` on x86_64.
https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/lldb-cmake/5745/
>From ba6e663299e1d7b54a3ac4a7c647d44f66d8699d Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Sat, 14 Sep 2024 10:49:27 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[lldb]=20Do=20not=20use=20LC=5FFUNCTI?=
=?UTF-8?q?ON=5FSTARTS=20data=20to=20determine=20symbol=20size=20as?=
=?UTF-8?q?=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit 0351dc522a25df0473a63b414a5bfde5814d3dc3.
---
.../ObjectFile/Mach-O/ObjectFileMachO.cpp | 63 +++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index c36748963db37b..06da83e26a26a5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,6 +3768,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
SymbolType type = eSymbolTypeInvalid;
SectionSP symbol_section;
+ lldb::addr_t symbol_byte_size = 0;
bool add_nlist = true;
bool is_gsym = false;
bool demangled_is_synthesized = false;
@@ -4353,6 +4354,47 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
if (symbol_section) {
const addr_t section_file_addr = symbol_section->GetFileAddress();
+ if (symbol_byte_size == 0 && function_starts_count > 0) {
+ addr_t symbol_lookup_file_addr = nlist.n_value;
+ // Do an exact address match for non-ARM addresses, else get the
+ // closest since the symbol might be a thumb symbol which has an
+ // address with bit zero set.
+ FunctionStarts::Entry *func_start_entry =
+ function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
+ if (is_arm && func_start_entry) {
+ // Verify that the function start address is the symbol address
+ // (ARM) or the symbol address + 1 (thumb).
+ if (func_start_entry->addr != symbol_lookup_file_addr &&
+ func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
+ // Not the right entry, NULL it out...
+ func_start_entry = nullptr;
+ }
+ }
+ if (func_start_entry) {
+ func_start_entry->data = true;
+
+ addr_t symbol_file_addr = func_start_entry->addr;
+ if (is_arm)
+ symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+
+ const FunctionStarts::Entry *next_func_start_entry =
+ function_starts.FindNextEntry(func_start_entry);
+ const addr_t section_end_file_addr =
+ section_file_addr + symbol_section->GetByteSize();
+ if (next_func_start_entry) {
+ addr_t next_symbol_file_addr = next_func_start_entry->addr;
+ // Be sure the clear the Thumb address bit when we calculate the
+ // size from the current and next address
+ if (is_arm)
+ next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+ symbol_byte_size = std::min<lldb::addr_t>(
+ next_symbol_file_addr - symbol_file_addr,
+ section_end_file_addr - symbol_file_addr);
+ } else {
+ symbol_byte_size = section_end_file_addr - symbol_file_addr;
+ }
+ }
+ }
symbol_value -= section_file_addr;
}
@@ -4459,6 +4501,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
if (nlist.n_desc & N_WEAK_REF)
sym[sym_idx].SetIsWeak(true);
+ if (symbol_byte_size > 0)
+ sym[sym_idx].SetByteSize(symbol_byte_size);
+
if (demangled_is_synthesized)
sym[sym_idx].SetDemangledNameIsSynthesized(true);
@@ -4577,7 +4622,23 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
Address symbol_addr;
if (module_sp->ResolveFileAddress(symbol_file_addr, symbol_addr)) {
SectionSP symbol_section(symbol_addr.GetSection());
+ uint32_t symbol_byte_size = 0;
if (symbol_section) {
+ const addr_t section_file_addr = symbol_section->GetFileAddress();
+ const FunctionStarts::Entry *next_func_start_entry =
+ function_starts.FindNextEntry(func_start_entry);
+ const addr_t section_end_file_addr =
+ section_file_addr + symbol_section->GetByteSize();
+ if (next_func_start_entry) {
+ addr_t next_symbol_file_addr = next_func_start_entry->addr;
+ if (is_arm)
+ next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+ symbol_byte_size = std::min<lldb::addr_t>(
+ next_symbol_file_addr - symbol_file_addr,
+ section_end_file_addr - symbol_file_addr);
+ } else {
+ symbol_byte_size = section_end_file_addr - symbol_file_addr;
+ }
sym[sym_idx].SetID(synthetic_sym_id++);
// Don't set the name for any synthetic symbols, the Symbol
// object will generate one if needed when the name is accessed
@@ -4589,6 +4650,8 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
add_symbol_addr(symbol_addr.GetFileAddress());
if (symbol_flags)
sym[sym_idx].SetFlags(symbol_flags);
+ if (symbol_byte_size)
+ sym[sym_idx].SetByteSize(symbol_byte_size);
++sym_idx;
}
}
More information about the lldb-commits
mailing list