DynamicLoader: Add an option to dry-run an ELF exectuable
This option is useful for measuring time of dynamic linking and profiling the DynamicLoader itself.
This commit is contained in:
parent
8fc1f470ef
commit
a5e2694ebf
Notes:
sideshowbarker
2024-07-17 18:13:59 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/a5e2694ebf Pull-request: https://github.com/SerenityOS/serenity/pull/21101 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/BertalanD Reviewed-by: https://github.com/DanShaders ✅ Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/kleinesfilmroellchen ✅
1 changed files with 4 additions and 0 deletions
|
@ -55,11 +55,13 @@ static int _main(int argc, char** argv, char** envp, bool is_secure)
|
|||
for (int i = 0; i < argc; ++i)
|
||||
arguments.unchecked_append({ argv[i], strlen(argv[i]) });
|
||||
|
||||
bool flag_dry_run { false };
|
||||
Vector<StringView> command;
|
||||
Core::ArgsParser args_parser;
|
||||
|
||||
args_parser.set_general_help("Run dynamically-linked ELF executables");
|
||||
args_parser.set_stop_on_first_non_option(true);
|
||||
args_parser.add_option(flag_dry_run, "Run in dry-run mode", "dry-run", 'd');
|
||||
args_parser.add_positional_argument(command, "Command to execute", "command");
|
||||
// NOTE: Don't use regular PrintUsageAndExit policy for ArgsParser, as it will simply
|
||||
// fail with a nullptr-dereference as the LibC exit function is not suitable for usage
|
||||
|
@ -90,6 +92,8 @@ static int _main(int argc, char** argv, char** envp, bool is_secure)
|
|||
argv[index] = const_cast<char*>(command_with_args[index].characters_without_null_termination());
|
||||
|
||||
auto entry_point = ELF::DynamicLinker::linker_main(move(main_program_path), main_program_fd, is_secure, envp);
|
||||
if (flag_dry_run)
|
||||
return 0;
|
||||
_invoke_entry(command.size(), argv, envp, entry_point);
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue