labath created this revision. labath added reviewers: amccarth, mstorsjo. labath added a parent revision: D69100: COFF: Create a separate "section" for the file header. labath marked an inline comment as done. labath added inline comments.
================ Comment at: source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp:800 /*flags*/ 0); + header_sp->SetPermissions(ePermissionsReadable); m_sections_up->AddSection(header_sp); ---------------- Are these the right permissions for the header? This enables us to reason about whether a given address can be executable, for instance during unwinding. https://reviews.llvm.org/D69102 Files: source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp test/Shell/ObjectFile/PECOFF/sections.yaml Index: test/Shell/ObjectFile/PECOFF/sections.yaml =================================================================== --- test/Shell/ObjectFile/PECOFF/sections.yaml +++ test/Shell/ObjectFile/PECOFF/sections.yaml @@ -7,7 +7,7 @@ # CHECK-NEXT: ID: 0xffffffffffffffff # CHECK-NEXT: Name: 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 Index: source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp =================================================================== --- source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -797,6 +797,7 @@ /*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 @@ 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); }
Index: test/Shell/ObjectFile/PECOFF/sections.yaml =================================================================== --- test/Shell/ObjectFile/PECOFF/sections.yaml +++ test/Shell/ObjectFile/PECOFF/sections.yaml @@ -7,7 +7,7 @@ # CHECK-NEXT: ID: 0xffffffffffffffff # CHECK-NEXT: Name: 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 Index: source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp =================================================================== --- source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -797,6 +797,7 @@ /*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 @@ 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); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits