[PATCH] D126898: [COFF] Check table ptr more thoroughly and ignore empty sections

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 06:24:56 PDT 2022


mstorsjo added a comment.

In D126898#3566346 <https://reviews.llvm.org/D126898#3566346>, @alvinhochun wrote:

> Yeah, that seems fine as a workaround. https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#section-table-section-headers says:
>
>> If this (VirtualSize) value is greater than SizeOfRawData, the section is zero-padded.
>
> This means the RVA should technically be pointing to a block of zeros. If we pretend the section does not exist at all, it is probably still good enough, right?

Yep, that's probably good enough. For some tables, I guess it could be remotely useful to pretend it exists and allocate a temporary zero block to point into. (Previously you would have gotten random data from the neighbouring sections instead.) But that sounds like something to consider if that actually turns out to be needed...

> But I wonder if the code should always just use the `.reloc` section and ignore the Base Relocation Table RVA if it points to somewhere odd?

No, I think it's safer to use the data directories - that'd be what windows itself uses. After linking, the section names are generally mostly cosmetic. Some things stay in their own sections up until linking but get merged into e.g. the `.rdata` section when linked. (For dwarf unwind info in PE/COFF we do have a hack in libunwind though - libunwind introspects the modules and locates the section named `.eh_frame` at runtime. Due to how PE/COFF string tables and all that works, the section name is truncated to `.eh_fram` in practice.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126898/new/

https://reviews.llvm.org/D126898



More information about the llvm-commits mailing list