[Lldb-commits] [lldb] 73a7a55 - lldb/COFF: Create a separate "section" for the file header

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 25 15:12:03 PDT 2019


Author: Pavel Labath
Date: 2019-10-25T22:11:53Z
New Revision: 73a7a55c0ec976fecadd7a872d24d850f8cd793a

URL: https://github.com/llvm/llvm-project/commit/73a7a55c0ec976fecadd7a872d24d850f8cd793a
DIFF: https://github.com/llvm/llvm-project/commit/73a7a55c0ec976fecadd7a872d24d850f8cd793a.diff

LOG: lldb/COFF: Create a separate "section" for the file header

In an attempt to ensure that every part of the module's memory image is
accounted for, D56537 created a special "container section" spanning the
entire image. While that seemed reasonable at the time (and it still
mostly does), it did create a problem of what to put as the "file size"
of the section, because the image is not continuous on disk, as we
generally assume (which is why I put zero there). Additionally, this
arrangement makes it unclear what kind of permissions should be assigned
to that section (which is what my next patch does).

To get around these, this patch partially reverts D56537, and goes back
to top-level sections. Instead, what I do is create a new "section" for
the object file header, which is also being loaded into memory, though
its not considered to be a section in the strictest sense. This makes it
possible to correctly assign file size section, and we can later assign
permissions to it as well.

Reviewers: amccarth, mstorsjo

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D69100

Added: 
    lldb/test/Shell/ObjectFile/PECOFF/sections.yaml

Modified: 
    lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    lldb/test/Shell/ObjectFile/PECOFF/export-dllfunc.yaml

Removed: 
    lldb/test/Shell/ObjectFile/PECOFF/subsections.yaml


################################################################################
diff  --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 742b28d0aaf3..7e8bcb38e6f2 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -790,13 +790,15 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
   if (module_sp) {
     std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
 
-    SectionSP image_sp = std::make_shared<Section>(
-        module_sp, this, ~user_id_t(0), ConstString(), eSectionTypeContainer,
-        m_coff_header_opt.image_base, m_coff_header_opt.image_size,
-        /*file_offset*/ 0, /*file_size*/ 0, m_coff_header_opt.sect_alignment,
+    SectionSP header_sp = std::make_shared<Section>(
+        module_sp, this, ~user_id_t(0), ConstString("PECOFF header"),
+        eSectionTypeOther, m_coff_header_opt.image_base,
+        m_coff_header_opt.header_size,
+        /*file_offset*/ 0, m_coff_header_opt.header_size,
+        m_coff_header_opt.sect_alignment,
         /*flags*/ 0);
-    m_sections_up->AddSection(image_sp);
-    unified_section_list.AddSection(image_sp);
+    m_sections_up->AddSection(header_sp);
+    unified_section_list.AddSection(header_sp);
 
     const uint32_t nsects = m_sect_headers.size();
     ModuleSP module_sp(GetModule());
@@ -901,15 +903,15 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
       }
 
       SectionSP section_sp(new Section(
-          image_sp,        // Parent section
           module_sp,       // Module to which this section belongs
           this,            // Object file to which this section belongs
           idx + 1,         // Section ID is the 1 based section index.
           const_sect_name, // Name of this section
           section_type,
-          m_sect_headers[idx].vmaddr, // File VM address == addresses as
-                                      // they are found in the object file
-          m_sect_headers[idx].vmsize, // VM size in bytes of this section
+          m_coff_header_opt.image_base +
+              m_sect_headers[idx].vmaddr, // File VM address == addresses as
+                                          // they are found in the object file
+          m_sect_headers[idx].vmsize,     // VM size in bytes of this section
           m_sect_headers[idx]
               .offset, // Offset to the data for this section in the file
           m_sect_headers[idx]
@@ -917,7 +919,8 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
           m_coff_header_opt.sect_alignment, // Section alignment
           m_sect_headers[idx].flags));      // Flags for this section
 
-      image_sp->GetChildren().AddSection(std::move(section_sp));
+      m_sections_up->AddSection(section_sp);
+      unified_section_list.AddSection(section_sp);
     }
   }
 }

diff  --git a/lldb/test/Shell/ObjectFile/PECOFF/export-dllfunc.yaml b/lldb/test/Shell/ObjectFile/PECOFF/export-dllfunc.yaml
index 1f858d735eca..c1ada73046dc 100644
--- a/lldb/test/Shell/ObjectFile/PECOFF/export-dllfunc.yaml
+++ b/lldb/test/Shell/ObjectFile/PECOFF/export-dllfunc.yaml
@@ -11,20 +11,24 @@
 # UUID should not be empty if the module is built with debug info.
 # BASIC-CHECK-DAG: UUID: {{[0-9A-F]{7,}[0-9A-F]}}-{{.*}}
 
-# BASIC-CHECK: Showing 3 subsections
+# BASIC-CHECK: Showing 4 sections
+#
 # BASIC-CHECK:  Index: 0
+# BASIC-CHECK:  Name: PECOFF header
+#
+# BASIC-CHECK:  Index: 1
 # BASIC-CHECK:  Name: .text
 # BASIC-CHECK:  Type: code
 # BASIC-CHECK:  VM size: 22
 # BASIC-CHECK:  File size: 512
 #
-# BASIC-CHECK:  Index: 1
+# BASIC-CHECK:  Index: 2
 # BASIC-CHECK:  Name: .rdata
 # BASIC-CHECK:  Type: data
 # BASIC-CHECK:  VM size: {{.}}
 # BASIC-CHECK:  File size: 512
 #
-# BASIC-CHECK:  Index: 2
+# BASIC-CHECK:  Index: 3
 # BASIC-CHECK:  Name: .pdata
 # BASIC-CHECK:  Type: data
 # BASIC-CHECK:  VM size: 12

diff  --git a/lldb/test/Shell/ObjectFile/PECOFF/subsections.yaml b/lldb/test/Shell/ObjectFile/PECOFF/sections.yaml
similarity index 65%
rename from lldb/test/Shell/ObjectFile/PECOFF/subsections.yaml
rename to lldb/test/Shell/ObjectFile/PECOFF/sections.yaml
index d7ecf68e84a2..715ef523c13c 100644
--- a/lldb/test/Shell/ObjectFile/PECOFF/subsections.yaml
+++ b/lldb/test/Shell/ObjectFile/PECOFF/sections.yaml
@@ -2,36 +2,36 @@
 # RUN: lldb-test object-file %t | FileCheck %s
 
 
-# CHECK:      Showing 1 sections
+# CHECK:      Showing 3 sections
 # CHECK-NEXT:   Index: 0
 # CHECK-NEXT:   ID: 0xffffffffffffffff
-# CHECK-NEXT:   Name:
-# CHECK-NEXT:   Type: container
+# CHECK-NEXT:   Name: PECOFF header
+# CHECK-NEXT:   Type: regular
 # CHECK-NEXT:   Permissions: ---
 # CHECK-NEXT:   Thread specific: no
 # CHECK-NEXT:   VM address: 0x40000000
-# CHECK-NEXT:   VM size: 12288
-# CHECK-NEXT:   File size: 0
-# CHECK-NEXT:   Showing 2 subsections
-# CHECK-NEXT:     Index: 0
-# CHECK-NEXT:     ID: 0x1
-# CHECK-NEXT:     Name: .text
-# CHECK-NEXT:     Type: code
-# CHECK-NEXT:     Permissions: ---
-# CHECK-NEXT:     Thread specific: no
-# CHECK-NEXT:     VM address: 0x40001000
-# CHECK-NEXT:     VM size: 64
-# CHECK-NEXT:     File size: 512
+# CHECK-NEXT:   VM size: 512
+# CHECK-NEXT:   File size: 512
 # CHECK-EMPTY: 
-# CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     ID: 0x2
-# CHECK-NEXT:     Name: .data
-# CHECK-NEXT:     Type: data
-# CHECK-NEXT:     Permissions: ---
-# CHECK-NEXT:     Thread specific: no
-# CHECK-NEXT:     VM address: 0x40002000
-# CHECK-NEXT:     VM size: 64
-# CHECK-NEXT:     File size: 512
+# CHECK-NEXT:   Index: 1
+# CHECK-NEXT:   ID: 0x1
+# CHECK-NEXT:   Name: .text
+# CHECK-NEXT:   Type: code
+# CHECK-NEXT:   Permissions: ---
+# CHECK-NEXT:   Thread specific: no
+# CHECK-NEXT:   VM address: 0x40001000
+# CHECK-NEXT:   VM size: 64
+# CHECK-NEXT:   File size: 512
+# CHECK-EMPTY:
+# CHECK-NEXT:   Index: 2
+# CHECK-NEXT:   ID: 0x2
+# CHECK-NEXT:   Name: .data
+# CHECK-NEXT:   Type: data
+# CHECK-NEXT:   Permissions: ---
+# CHECK-NEXT:   Thread specific: no
+# CHECK-NEXT:   VM address: 0x40002000
+# CHECK-NEXT:   VM size: 64
+# CHECK-NEXT:   File size: 512
 
 
 --- !COFF


        


More information about the lldb-commits mailing list