Fix legacy PE COFF symbol addresses#8334
Open
plafosse wants to merge 3 commits into
Open
Conversation
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
IMAGE_DEBUG_TYPE_COFFsymbol tables by validating theirIMAGE_COFF_SYMBOLS_HEADERagainst the PE header's symbol-table pointer and count.IMAGE_SYMBOL.Valueas an RVA only for that validated legacy form.view/pe/tests/fixtures.Root cause
The PE loader always added the symbol's section RVA to
IMAGE_SYMBOL.Value. Visual C++ 6/DEBUGTYPE:COFFimages can instead store an image-relative value in the legacy COFF debug table, so the section RVA was added twice. In the issue sample,_FXCLI_DebugDispatchwas consequently created at0x57eb80instead of0x57db80.The discriminator is deliberately structural rather than heuristic: the debug entry must be
IMAGE_DEBUG_TYPE_COFF, its raw data must contain a completeIMAGE_COFF_SYMBOLS_HEADER, and that header's symbol count and first-symbol location must exactly match the PE header.PointerToRawDatais used becauseAddressOfRawDatamay be zero when debug data is outside mapped sections.Fixes #4308.
Compatibility
The normal section-relative behavior introduced for #1956 remains the fallback. This avoids changing ordinary COFF tables, including MinGW-produced images without the legacy debug wrapper.
Validation
view_pewithcmake --build cmake-build-relwithdebinfo --target view_pe -j 8._FXCLI_DebugDispatchto0x57db80_FXCLI_IF_NotifyOraBRto0x57db01pre_c_initat0x401010pre_cpp_initat0x401130__tmainCRTStartupat0x401180llvm-readobj:0x1020legacyfunction symbol whose value is RVA0x1010IMAGE_DEBUG_TYPE_COFF,AddressOfRawData = 0, andPointerToRawData = 0x16007d3d2b3a45405e542d4c5644712cd11b27d5c08b968f7020e2960ecffb8dcba7_startat0x401020but incorrectly createslegacyat0x402010legacyat0x401010and_startat0x401020, with no symbol or function at0x402010git diff --check.References