Fix legacy PE COFF symbol addresses - #8334
Conversation
zznop
left a comment
There was a problem hiding this comment.
Changes look good. Just recommend changing the way this is being tested so it runs under CI.
| @@ -0,0 +1,223 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
Do we need to check in this script as opposed to just checking in the binary that it outputs?
| @@ -0,0 +1,21 @@ | |||
| # Legacy COFF debug fixture | |||
There was a problem hiding this comment.
Did you mean to check in this README?
| @@ -3440,6 +3442,91 @@ uint64_t PEView::RVAToFileOffset(uint64_t offset, bool except) | |||
| } | |||
|
|
|||
|
|
|||
| bool PEView::CoffSymbolValuesAreRvas(const PEHeader& header) | |||
There was a problem hiding this comment.
I'm surprised to learn that there is no flag in IMAGE_SYMBOL that identifies whether a value is section-relative or image-relative. This looks like a decent approach.
There was a problem hiding this comment.
Recommend moving this to tests/special_cases and writing a regression test that asserts we're handling it correctly. Currently, none of the added test fixtures in the PR are tested under CI.

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