-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail to parse PE files compiled by Rust #424
Comments
@kkent030315 this seems directly related to the new tls parsing in #404 could you take a look? if a patch isn't available soon to fix this regression, I will likely disable the tls parsing in a minor patch and push that until it can be resolved better later on. |
@Berrysoft would you mind uploading a binary exhibiting the behavior here, so it's easier to repro/triage, thanks |
It contains the |
thank you, and yes i can repro on top of tree:
exhibits the failure. |
this is odd, doesn't seem to find the rva in the .data section:
this is returning false for whatever reason: fn is_in_section(rva: usize, section: §ion_table::SectionTable, file_alignment: u32) -> bool {
let section_rva = section.virtual_address as usize;
is_in_range(
rva,
section_rva,
section_rva + section_read_size(section, file_alignment),
)
}
not sure i haven't debugged this in a while; anyway that's probably all for me tonight :) EDIT: nope, I forgot to add the end_size to the start :) that's why don't debug late at night |
With updated prints, it does indeed seem like that value is not in any sections; it's quite odd
it's still possible there's something wrong with end calculation, but I'm not sure. anyway... |
There's nothing wrong with If this code is used to parse a loaded file then it probably makes sense to read the TLS index from memory, but in that case |
@m4b I'm back! and yes. I recognize this issue. Lemme take a look and I will put fixes for this. |
I can repro this behaviour by The address in question is the The binary Applicable codebase of Rust std (before significant changes applied) is following: Given that, we can reproduce the same behaviour with
Tip
or # proj-root/rust-toolchain.toml
[toolchain]
channel = "nightly-2024-10-07"
# then rustup do everything needed for you when you triggered builds #[link_section = ".CRT$XLB"]
#[used]
pub static TLS_CALLBACK: unsafe extern "system" fn(*mut i8, u32, *mut i8) = tls_callback;
#[inline(never)]
pub extern "system" fn tls_callback(_: *mut i8, reason: u32, _: *mut i8) {}
fn main() {
println!("Hello, world!");
} cargo run --example rdr -- "path\to\target\release\goblintlstest.exe"
Malformed entity: cannot map tls address_of_index rva (0x21270) into offset The The I'd like to use The VA This sounds a bit weird but is correct and behaves as expected. TLS indexes are literally the unique indexes for each threads when the executable is mapped being and prepared for execution by Windows Loader, so it shouldn't have to be in the raw data but should be exists in virtual address only when mapped into the memory.
So, possible fix is to be:
|
Somewhat similarly related, I found a human error: Lines 239 to 241 in b2505ec
It should check |
@m4b Sorry for verbose ping, I submitted PR for fixing this issue. :) |
thanks everyone for quick feedback, @kkent030315 fixed this for now in #425 please re-open if see issue in 0.9.1, which is published with this fix |
Note: This issue is technically problem with MSVC. Clang/LLD does not create To replicate this behaviour: # .cargo/config.toml
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe" # LLD
# linker = "link.exe" for MSVC Also, non-mangled EXTERN_C unsigned int _tls_index{}; I'll add tests for those cases to mitigate further regression. |
The error is:
This error only occurs with goblin 0.9.0. Goblin 0.8.2 works fine.
The error seems only applies to exe create by Rust, for example,
sudo.exe
.The text was updated successfully, but these errors were encountered: