[Lldb-commits] [lldb] [LLDB][ELF] Fix section unification to not just use names. (PR #90099)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 29 06:27:39 PDT 2024


================
@@ -1854,6 +1854,49 @@ class VMAddressProvider {
 };
 }
 
+namespace {
+  // We have to do this because ELF doesn't have section IDs, and also
+  // doesn't require section names to be unique.  (We use the section index
+  // for section IDs, but that isn't guaranteed to be the same in separate
+  // debug images.)
+  SectionSP FindMatchingSection(const SectionList &section_list,
+                                SectionSP section) {
+    SectionSP sect_sp;
+
+    addr_t vm_addr = section->GetFileAddress();
+    ConstString name = section->GetName();
+    offset_t file_size = section->GetFileSize();
+    offset_t byte_size = section->GetByteSize();
+    SectionType type = section->GetType();
+    bool thread_specific = section->IsThreadSpecific();
+    uint32_t permissions = section->GetPermissions();
+    uint32_t alignment = section->GetLog2Align();
+
+    for (auto sect_iter = section_list.begin();
+         sect_iter != section_list.end();
+         ++sect_iter) {
+      if ((*sect_iter)->GetName() == name
+          && (*sect_iter)->GetType() == type
+          && (*sect_iter)->IsThreadSpecific() == thread_specific
+          && (*sect_iter)->GetPermissions() == permissions
+          && (*sect_iter)->GetFileSize() == file_size
+          && (*sect_iter)->GetByteSize() == byte_size
+          && (*sect_iter)->GetFileAddress() == vm_addr
+          && (*sect_iter)->GetLog2Align() == alignment) {
----------------
labath wrote:

The section type can also change. You can see that with .text, because there we have a name-based fallback, but with anything else, it changes from "code" to "regular":
```$ bin/lldb-test object-file /tmp/a.debug  | grep -e foo -C 3
  Showing 1 subsections
    Index: 0
    ID: 0x6
    Name: .foo
    Type: regular
    Permissions: r-x
    Thread specific: no
$ bin/lldb-test object-file /tmp/a.out  | grep -e foo -C 3
  Showing 1 subsections
    Index: 0
    ID: 0x6
    Name: .foo
    Type: code
    Permissions: r-x
    Thread specific: no
```

The other fields are _probably_ fine.

https://github.com/llvm/llvm-project/pull/90099


More information about the lldb-commits mailing list