Fix an edge case missed by https://reviews.llvm.org/D78921. The Repro
debug entry (generated with the /Brepro linker flag) does not have a
debug-directory payload. Do not attempt to patch Debug entries of this
type.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM, thanks!
Do you happen to know if the same is the case for any other debug directory types, or is this the only one?
I'm not sure if this is also the case for other debug directory types. Maybe someone familiar with Windows debug info can help? (+thakis, rnk)
Looking at https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#debug-type, we should also exclude IMAGE_DEBUG_TYPE_UNKNOWN. I think all other entries could have a payload associated with it.
LGTM, thanks!
I’m considering if it’d be good to change the existing code even further; if the field in the file is zero, regardless of type, we’d just leave it as is, and one error out of its nonzero but can’t be found. WDYT?
llvm/tools/llvm-objcopy/COFF/Writer.cpp | ||
---|---|---|
432 | Are you suggesting we remove the error check here and call virtualAddressToFileAddress only if Debug->AddressOfRawData is not 0? I considered it but thought I didn't quite understand the connection between the conditional and the error message. I can amend the patch if you think this is a better choice. |
llvm/tools/llvm-objcopy/COFF/Writer.cpp | ||
---|---|---|
432 | Yes, exactly, I think that's a better/more robust choice - if there's a different directory entry which is payload-less (for one reason or another) we should just ignore it; it's only an error if there's a value which we can't reasonably rebase. And maybe it'd be even better to check PointerToRawData instead of AddressOfRawData for the main check - if the input file didn't have a raw file address to the payload, then we keep it as is (the virtual address should remain unchanged), but if there's a nonzero PointerToRawData, we need to recalculate that based on the new file layout. |
llvm/test/tools/llvm-objcopy/COFF/strip-brepro.test | ||
---|---|---|
2 ↗ | (On Diff #363881) | Why do you need both -S and -x? As I understand it, you only need one of them to strip the debug data. Also, this comment needs enhancing to explain why this case is special. |
5 ↗ | (On Diff #363881) | Shouldn't there be some check after this line to show that it's been stripped? |
llvm/test/tools/llvm-objcopy/COFF/strip-brepro.test | ||
---|---|---|
5 ↗ | (On Diff #363881) | I guess the intent of this test isn't to test stripping in itself, but that llvm-objcopy doesn't bail out while processing an executable with this content in it; the executable as such doesn't seem to contain anything that can be stripped out either. But making this clearer in the test comment would be good I guess. |
llvm/test/tools/llvm-objcopy/COFF/strip-brepro.test | ||
---|---|---|
2 ↗ | (On Diff #363881) |
This is a carry-over from our local build. Neither -S nor -x is needed to reproduce the issue. |
5 ↗ | (On Diff #363881) | Remove -S, -x. The test is mainly for absence of error but I can add any relevant check on the output if needed. |
llvm/test/tools/llvm-objcopy/COFF/debug-entry-no-payload.test | ||
---|---|---|
3 | "are handled correctly" usually implies that something needs to be checked, in my mind, namely that the debug directory entries look correct after the invocation of llvm-objcopy. It's this that should be checked. If on the other hand, you think it should be just checking for lack of an error, it's probably best to say just that. I'd check the debug entry though. | |
48 | If I'm not mistaken, there are two entries here below. If so, please update this comment. |
LGTM, with two inline nits.
Also super nit: in the llvm-objcopy world, it's one space after '.' :-)
llvm/test/tools/llvm-objcopy/COFF/debug-entry-no-payload.test | ||
---|---|---|
14 | As there are no other check prefixes used in this file, you can omit the check-prefix argument and just use CHECK instead of DEBUG-DIRS, if you want. | |
53–54 |
"are handled correctly" usually implies that something needs to be checked, in my mind, namely that the debug directory entries look correct after the invocation of llvm-objcopy. It's this that should be checked. If on the other hand, you think it should be just checking for lack of an error, it's probably best to say just that. I'd check the debug entry though.