Skip to content
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

How to check if elf is statically linked? #682

Closed
NobodyXu opened this issue May 8, 2024 · 4 comments
Closed

How to check if elf is statically linked? #682

NobodyXu opened this issue May 8, 2024 · 4 comments

Comments

@NobodyXu
Copy link

NobodyXu commented May 8, 2024

I want to check if an elf object is statically linked.

I've found Object::kind, however I'm not sure which variants in ObjectKind refers to a statically linked.

@philipc
Copy link
Contributor

philipc commented May 8, 2024

There's nothing in the unified API, and even ObjectKind isn't completely accurate.

For now, you'll need to use the lower level ELF APIs to read the ELF header flags and the program headers (e.g. check for PT_INTERP and/or PT_DYNAMIC, I don't know what the exact check is).

@NobodyXu
Copy link
Author

NobodyXu commented May 8, 2024

Thanks for the quick reply!

I found that goblin supports getting program header https://docs.rs/goblin/latest/goblin/elf/struct.Elf.html and have PT_INTERP defined in the crate

@NobodyXu NobodyXu closed this as completed May 8, 2024
@philipc
Copy link
Contributor

philipc commented May 8, 2024

goblin is certainly the easiest way to do it, but if all you want is to check if it is statically linked then it's doing a lot of parsing that you don't need. I don't know if that matters.

@NobodyXu
Copy link
Author

NobodyXu commented May 8, 2024

For cargo-binstall, most of the time is spent on network and the elf shouldn't be too big, so I think it should be ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants