COFF: Set section permissions

Summary:
This enables us to reason about whether a given address can be
executable, for instance during unwinding.

Reviewers: amccarth, mstorsjo

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D69102
This commit is contained in:
Pavel Labath 2019-10-16 17:16:41 +02:00
parent 532815dd5c
commit f1e0ae3420
2 changed files with 13 additions and 3 deletions

View File

@ -797,6 +797,7 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
/*file_offset*/ 0, m_coff_header_opt.header_size,
m_coff_header_opt.sect_alignment,
/*flags*/ 0);
header_sp->SetPermissions(ePermissionsReadable);
m_sections_up->AddSection(header_sp);
unified_section_list.AddSection(header_sp);
@ -919,6 +920,15 @@ void ObjectFilePECOFF::CreateSections(SectionList &unified_section_list) {
m_coff_header_opt.sect_alignment, // Section alignment
m_sect_headers[idx].flags)); // Flags for this section
uint32_t permissions = 0;
if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_MEM_EXECUTE)
permissions |= ePermissionsExecutable;
if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_MEM_READ)
permissions |= ePermissionsReadable;
if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_MEM_WRITE)
permissions |= ePermissionsWritable;
section_sp->SetPermissions(permissions);
m_sections_up->AddSection(section_sp);
unified_section_list.AddSection(section_sp);
}

View File

@ -7,7 +7,7 @@
# CHECK-NEXT: ID: 0xffffffffffffffff
# CHECK-NEXT: Name: PECOFF header
# CHECK-NEXT: Type: regular
# CHECK-NEXT: Permissions: ---
# CHECK-NEXT: Permissions: r--
# CHECK-NEXT: Thread specific: no
# CHECK-NEXT: VM address: 0x40000000
# CHECK-NEXT: VM size: 512
@ -17,7 +17,7 @@
# CHECK-NEXT: ID: 0x1
# CHECK-NEXT: Name: .text
# CHECK-NEXT: Type: code
# CHECK-NEXT: Permissions: ---
# CHECK-NEXT: Permissions: r-x
# CHECK-NEXT: Thread specific: no
# CHECK-NEXT: VM address: 0x40001000
# CHECK-NEXT: VM size: 64
@ -27,7 +27,7 @@
# CHECK-NEXT: ID: 0x2
# CHECK-NEXT: Name: .data
# CHECK-NEXT: Type: data
# CHECK-NEXT: Permissions: ---
# CHECK-NEXT: Permissions: r--
# CHECK-NEXT: Thread specific: no
# CHECK-NEXT: VM address: 0x40002000
# CHECK-NEXT: VM size: 64