feat(pe): add parse_imports option to ParseOptions#522
feat(pe): add parse_imports option to ParseOptions#522supervacuus wants to merge 3 commits intom4b:masterfrom
parse_imports option to ParseOptions#522Conversation
|
Just wanted to ping if this kind of change is of interest. I have also now added a new PR (#527) that fixes the underlying issue. It might still make sense to be able to turn off import parsing, but if #527 is accepted, I could understand if you didn't want to add another parser option. The resulting runtimes are now essentially the same for either PR. |
|
I'm ok with this i think, @kkent030315 is this something you think is fine? |
| if opts.parse_imports { | ||
| if let Some(&import_table) = optional_header.data_directories.get_import_table() { |
There was a problem hiding this comment.
can we merge it to one?
| if opts.parse_imports { | |
| if let Some(&import_table) = optional_header.data_directories.get_import_table() { | |
| if opts.parse_imports && let Some(&import_table) = optional_header.data_directories.get_import_table() |
There was a problem hiding this comment.
rust is pinned at 1.85 in CI which complains about the let chain.
Otherwise fixed in: 9f632ae
There was a problem hiding this comment.
We can use
if let (true, Some(&import_table)) = (
opts.parse_imports,
optional_header.data_directories.get_import_table(),
) {
}if you prefer it to if-nesting. However, that means get_import_table() will be called unconditionally (which is not a costly invocation, but a change in behavior nonetheless).
Changed here: db951f2
Parsing
PEimport tables is expensive: for each DLL, the parser does a full pass over the import lookup table (resolving every symbolRVAvia a linear scan over sections), a second pass over the import address table, and then a third reshaping pass inImport::parse. For binaries with large or malformed import tables, this adds up fast, especially when the caller only needs headers, debug info, or exports.This PR adds a
parse_importsflag toParseOptions(default:true) with awith_parse_importsbuilder method, allowing callers to skip import table parsing entirely. When set tofalse,import_data,imports, andlibrariesremain empty while everything else is parsed as usual.This is a follow-up to #506 (#508).