serenity icon indicating copy to clipboard operation
serenity copied to clipboard

DynamicLoader: Add standard argument parsing for executing ELF binaries

Open supercomputer7 opened this issue 2 years ago • 10 comments
trafficstars

Relies on #20988.

Here's a picture of profiling the DynamicLoader itself: Screenshot_2023-09-16_12-11-33

Here's a picture of using --argv0 argument: Screenshot_2023-09-16_12-25-35

supercomputer7 avatar Sep 16 '23 09:09 supercomputer7

Keeping a reference of an interesting bug here: https://gist.github.com/supercomputer7/8ff4c47d7a64de44577f4239eaae33f4 https://discord.com/channels/830522505605283862/830526926569209917/1152623754971709581

I fixed it by specifying the cpp file of LibArgsParser directly in the sources of the DynamicLoader and removing -fno-rtti in LibArgsParser CMakeLists.txt (so I don't set another CMAKE_CXX_FLAGS variable here).

supercomputer7 avatar Sep 16 '23 15:09 supercomputer7

I hate to sound like a broken record again... but please don't overcomplicate things.

What's stopping us from just adding Userland/Libraries/LibCore/ArgsParser.cpp to the SOURCES list of DynamicLoader instead of coming up with a brand new library and changing almost a thousand lines of code?

Nothing stops us at doing this and I even thought about it. At first, the whole LibArgsParser was standalone (it had its own CMakeLists file - see this to understand what I mean).

I also thought it might be just neat to have a clear separation because LibCore will not be the only code to use this (and maybe also to split the gigantic ArgsParser file to many small CPP files to make it better). No need to get mad over this, I didn't intend to complicate things without any reason.

supercomputer7 avatar Sep 16 '23 17:09 supercomputer7

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Oct 08 '23 12:10 stale[bot]

This pull request has been closed because it has not had recent activity. Feel free to re-open if you wish to still contribute these changes. Thank you for your contributions!

stale[bot] avatar Oct 15 '23 14:10 stale[bot]

Let's try this again. Still awaiting for the previous PR to be merged.

supercomputer7 avatar Oct 16 '23 15:10 supercomputer7

Oh the previous PR is merged. Let's rebase it now then :)

supercomputer7 avatar Oct 16 '23 15:10 supercomputer7

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

stale[bot] avatar Nov 07 '23 18:11 stale[bot]

This pull request has been closed because it has not had recent activity. Feel free to re-open if you wish to still contribute these changes. Thank you for your contributions!

stale[bot] avatar Nov 15 '23 23:11 stale[bot]

Let's try this again :)

supercomputer7 avatar Apr 26 '24 14:04 supercomputer7

I had to fix a bug in which when we run the dynamic loader directly without any more arguments - it will crash with a null pointer de-reference. It turns out that it crashed on the LibC exit function, probably due to try to finalize something that wasn't even initialized in the first place (as the dynamic loader on itself really doesn't do a lot in such configuration).

Now it should all work properly so reviews and suggestions are welcome here!

supercomputer7 avatar Apr 26 '24 21:04 supercomputer7