This is an archive of the discontinued LLVM Phabricator instance.

[lldb][PECOFF] Exclude alignment padding when reading section data
ClosedPublic

Authored by hjyamauchi on Aug 3 2023, 5:34 PM.

Details

Summary

There can be zero padding bytes at a section end for file alignment in PECOFF. Exclude those padding bytes when reading the section data.

Diff Detail

Event Timeline

hjyamauchi created this revision.Aug 3 2023, 5:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 5:34 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
hjyamauchi requested review of this revision.Aug 3 2023, 5:34 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 3 2023, 5:34 PM
hjyamauchi updated this revision to Diff 547086.Aug 3 2023, 7:40 PM
compnerd accepted this revision.Aug 3 2023, 9:16 PM

LGTM outside of the PE header check.

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

Can we use m_binary->getPEHeader() || m_binary->getPE32Header() here instead? We are technically ensuring that this is a linked (PE) binary rather than an object file. While a DOS header is present, it is not an absolute requirement (theoretically, it is practically never going to change).

This revision is now accepted and ready to land.Aug 3 2023, 9:16 PM
MrTrillian accepted this revision.Aug 4 2023, 7:33 AM
MrTrillian added a subscriber: MrTrillian.

Looking good!

hjyamauchi marked an inline comment as done.
hjyamauchi added inline comments.
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
1035

Done.

compnerd accepted this revision.Aug 4 2023, 10:25 AM
This revision was landed with ongoing or failed builds.Aug 4 2023, 1:45 PM
This revision was automatically updated to reflect the committed changes.
hjyamauchi marked an inline comment as done.

Hi, this is failing on swift-ci (runs on x86 bots) with the following error:

/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/build/Ninja-ReleaseAssert+stdlib-Release/lldb-macosx-x86_64/unittests/ObjectFile/PECOFF/./ObjectFilePECOFFTests --gtest_filter=SectionSizeTest.NoAlignmentPadding
--
YAML:12:5: error: unknown key 'SizeOfRawData'
    SizeOfRawData:   512
    ^~~~~~~~~~~~~
/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49: Failure
Value of: llvm::detail::TakeExpected(ExpectedFile)
Expected: succeeded
  Actual: failed  (convertYAML() failed)

/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49
Value of: llvm::detail::TakeExpected(ExpectedFile)
Expected: succeeded
  Actual: failed  (convertYAML() failed)

https://ci.swift.org/view/LLDB/job/oss-lldb-incremental-macos-cmake/

Could you take a look please?

Hi, this is failing on swift-ci (runs on x86 bots) with the following error:

/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/build/Ninja-ReleaseAssert+stdlib-Release/lldb-macosx-x86_64/unittests/ObjectFile/PECOFF/./ObjectFilePECOFFTests --gtest_filter=SectionSizeTest.NoAlignmentPadding
--
YAML:12:5: error: unknown key 'SizeOfRawData'
    SizeOfRawData:   512
    ^~~~~~~~~~~~~
/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49: Failure
Value of: llvm::detail::TakeExpected(ExpectedFile)
Expected: succeeded
  Actual: failed  (convertYAML() failed)

/Users/ec2-user/jenkins/workspace/oss-lldb-incremental-macos-cmake/llvm-project/lldb/unittests/ObjectFile/PECOFF/TestSectionSize.cpp:49
Value of: llvm::detail::TakeExpected(ExpectedFile)
Expected: succeeded
  Actual: failed  (convertYAML() failed)

https://ci.swift.org/view/LLDB/job/oss-lldb-incremental-macos-cmake/

Could you take a look please?

Fix: https://github.com/apple/llvm-project/pull/7218