Skip to content

Commit 73a7a55

Browse files
committed
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
1 parent 4c0251d commit 73a7a55

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -790,13 +790,15 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
790790
if (module_sp) {
791791
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
792792

793-
SectionSP image_sp = std::make_shared<Section>(
794-
module_sp, this, ~user_id_t(0), ConstString(), eSectionTypeContainer,
795-
m_coff_header_opt.image_base, m_coff_header_opt.image_size,
796-
/*file_offset*/ 0, /*file_size*/ 0, m_coff_header_opt.sect_alignment,
793+
SectionSP header_sp = std::make_shared<Section>(
794+
module_sp, this, ~user_id_t(0), ConstString("PECOFF header"),
795+
eSectionTypeOther, m_coff_header_opt.image_base,
796+
m_coff_header_opt.header_size,
797+
/*file_offset*/ 0, m_coff_header_opt.header_size,
798+
m_coff_header_opt.sect_alignment,
797799
/*flags*/ 0);
798-
m_sections_up->AddSection(image_sp);
799-
unified_section_list.AddSection(image_sp);
800+
m_sections_up->AddSection(header_sp);
801+
unified_section_list.AddSection(header_sp);
800802

801803
const uint32_t nsects = m_sect_headers.size();
802804
ModuleSP module_sp(GetModule());
@@ -901,23 +903,24 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
901903
}
902904

903905
SectionSP section_sp(new Section(
904-
image_sp, // Parent section
905906
module_sp, // Module to which this section belongs
906907
this, // Object file to which this section belongs
907908
idx + 1, // Section ID is the 1 based section index.
908909
const_sect_name, // Name of this section
909910
section_type,
910-
m_sect_headers[idx].vmaddr, // File VM address == addresses as
911-
// they are found in the object file
912-
m_sect_headers[idx].vmsize, // VM size in bytes of this section
911+
m_coff_header_opt.image_base +
912+
m_sect_headers[idx].vmaddr, // File VM address == addresses as
913+
// they are found in the object file
914+
m_sect_headers[idx].vmsize, // VM size in bytes of this section
913915
m_sect_headers[idx]
914916
.offset, // Offset to the data for this section in the file
915917
m_sect_headers[idx]
916918
.size, // Size in bytes of this section as found in the file
917919
m_coff_header_opt.sect_alignment, // Section alignment
918920
m_sect_headers[idx].flags)); // Flags for this section
919921

920-
image_sp->GetChildren().AddSection(std::move(section_sp));
922+
m_sections_up->AddSection(section_sp);
923+
unified_section_list.AddSection(section_sp);
921924
}
922925
}
923926
}

lldb/test/Shell/ObjectFile/PECOFF/export-dllfunc.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@
1111
# UUID should not be empty if the module is built with debug info.
1212
# BASIC-CHECK-DAG: UUID: {{[0-9A-F]{7,}[0-9A-F]}}-{{.*}}
1313

14-
# BASIC-CHECK: Showing 3 subsections
14+
# BASIC-CHECK: Showing 4 sections
15+
#
1516
# BASIC-CHECK: Index: 0
17+
# BASIC-CHECK: Name: PECOFF header
18+
#
19+
# BASIC-CHECK: Index: 1
1620
# BASIC-CHECK: Name: .text
1721
# BASIC-CHECK: Type: code
1822
# BASIC-CHECK: VM size: 22
1923
# BASIC-CHECK: File size: 512
2024
#
21-
# BASIC-CHECK: Index: 1
25+
# BASIC-CHECK: Index: 2
2226
# BASIC-CHECK: Name: .rdata
2327
# BASIC-CHECK: Type: data
2428
# BASIC-CHECK: VM size: {{.}}
2529
# BASIC-CHECK: File size: 512
2630
#
27-
# BASIC-CHECK: Index: 2
31+
# BASIC-CHECK: Index: 3
2832
# BASIC-CHECK: Name: .pdata
2933
# BASIC-CHECK: Type: data
3034
# BASIC-CHECK: VM size: 12

lldb/test/Shell/ObjectFile/PECOFF/subsections.yaml renamed to lldb/test/Shell/ObjectFile/PECOFF/sections.yaml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22
# RUN: lldb-test object-file %t | FileCheck %s
33

44

5-
# CHECK: Showing 1 sections
5+
# CHECK: Showing 3 sections
66
# CHECK-NEXT: Index: 0
77
# CHECK-NEXT: ID: 0xffffffffffffffff
8-
# CHECK-NEXT: Name:
9-
# CHECK-NEXT: Type: container
8+
# CHECK-NEXT: Name: PECOFF header
9+
# CHECK-NEXT: Type: regular
1010
# CHECK-NEXT: Permissions: ---
1111
# CHECK-NEXT: Thread specific: no
1212
# CHECK-NEXT: VM address: 0x40000000
13-
# CHECK-NEXT: VM size: 12288
14-
# CHECK-NEXT: File size: 0
15-
# CHECK-NEXT: Showing 2 subsections
16-
# CHECK-NEXT: Index: 0
17-
# CHECK-NEXT: ID: 0x1
18-
# CHECK-NEXT: Name: .text
19-
# CHECK-NEXT: Type: code
20-
# CHECK-NEXT: Permissions: ---
21-
# CHECK-NEXT: Thread specific: no
22-
# CHECK-NEXT: VM address: 0x40001000
23-
# CHECK-NEXT: VM size: 64
24-
# CHECK-NEXT: File size: 512
13+
# CHECK-NEXT: VM size: 512
14+
# CHECK-NEXT: File size: 512
2515
# CHECK-EMPTY:
26-
# CHECK-NEXT: Index: 1
27-
# CHECK-NEXT: ID: 0x2
28-
# CHECK-NEXT: Name: .data
29-
# CHECK-NEXT: Type: data
30-
# CHECK-NEXT: Permissions: ---
31-
# CHECK-NEXT: Thread specific: no
32-
# CHECK-NEXT: VM address: 0x40002000
33-
# CHECK-NEXT: VM size: 64
34-
# CHECK-NEXT: File size: 512
16+
# CHECK-NEXT: Index: 1
17+
# CHECK-NEXT: ID: 0x1
18+
# CHECK-NEXT: Name: .text
19+
# CHECK-NEXT: Type: code
20+
# CHECK-NEXT: Permissions: ---
21+
# CHECK-NEXT: Thread specific: no
22+
# CHECK-NEXT: VM address: 0x40001000
23+
# CHECK-NEXT: VM size: 64
24+
# CHECK-NEXT: File size: 512
25+
# CHECK-EMPTY:
26+
# CHECK-NEXT: Index: 2
27+
# CHECK-NEXT: ID: 0x2
28+
# CHECK-NEXT: Name: .data
29+
# CHECK-NEXT: Type: data
30+
# CHECK-NEXT: Permissions: ---
31+
# CHECK-NEXT: Thread specific: no
32+
# CHECK-NEXT: VM address: 0x40002000
33+
# CHECK-NEXT: VM size: 64
34+
# CHECK-NEXT: File size: 512
3535

3636

3737
--- !COFF

0 commit comments

Comments
 (0)