Skip to content

Commit 9282807

Browse files
committed
Add new option --ignore-manifest-main-class
If the option is specified, any main class that may be specified in the manifest file of a JAR will be ignored in the class loading stage. This is useful when we want to e.g. load all classes in a JAR file, some of which may not be referenced from the specified main class.
1 parent 8c7ee00 commit 9282807

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ void parse_java_language_options(const cmdlinet &cmd, optionst &options)
6969
options.set_option(
7070
"symex-driven-lazy-loading", cmd.isset("symex-driven-lazy-loading"));
7171

72+
options.set_option(
73+
"ignore-manifest-main-class", cmd.isset("ignore-manifest-main-class"));
74+
7275
if(cmd.isset("context-include"))
7376
options.set_option("context-include", cmd.get_values("context-include"));
7477

@@ -201,6 +204,9 @@ void java_bytecode_languaget::set_language_options(const optionst &options)
201204
nondet_static = options.get_bool_option("nondet-static");
202205
static_values_file = options.get_option("static-values");
203206

207+
ignore_manifest_main_class =
208+
options.get_bool_option("ignore-manifest-main-class");
209+
204210
if(options.is_set("context-include") || options.is_set("context-exclude"))
205211
method_in_context = get_context(options);
206212

@@ -288,7 +294,7 @@ bool java_bytecode_languaget::parse(
288294
std::string manifest_main_class = manifest["Main-Class"];
289295

290296
// if the manifest declares a Main-Class line, we got a main class
291-
if(!manifest_main_class.empty())
297+
if(!manifest_main_class.empty() && !ignore_manifest_main_class)
292298
main_class = manifest_main_class;
293299
}
294300
}

jbmc/src/java_bytecode/java_bytecode_language.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Author: Daniel Kroening, [email protected]
4040
"(max-nondet-tree-depth):" \
4141
"(java-max-vla-length):" \
4242
"(java-cp-include-files):" \
43+
"(ignore-manifest-main-class)" \
4344
"(context-include):" \
4445
"(context-exclude):" \
4546
"(no-lazy-methods)" \
@@ -73,6 +74,11 @@ Author: Daniel Kroening, [email protected]
7374
" --java-max-vla-length N limit the length of user-code-created arrays\n" /* NOLINT(*) */ \
7475
" --java-cp-include-files r regexp or JSON list of files to load\n" \
7576
" (with '@' prefix)\n" \
77+
" --ignore-manifest-main-class ignore Main-Class entries in JAR manifest files.\n" /* NOLINT(*) */ \
78+
" If this option is specified and the options\n" /* NOLINT(*) */ \
79+
" --function and --main-class are not, we can be\n" /* NOLINT(*) */ \
80+
" certain that all classes in the JAR file are\n" /* NOLINT(*) */ \
81+
" loaded." \
7682
" --context-include i only analyze code matching specification i that\n" /* NOLINT(*) */ \
7783
" --context-exclude e does not match specification e.\n" \
7884
" A specification is any prefix of a package, class\n" /* NOLINT(*) */ \
@@ -215,6 +221,7 @@ class java_bytecode_languaget:public languaget
215221
bool language_options_initialized;
216222
irep_idt main_class;
217223
std::vector<irep_idt> main_jar_classes;
224+
bool ignore_manifest_main_class;
218225
java_class_loadert java_class_loader;
219226
bool threading_support;
220227
bool assume_inputs_non_null; // assume inputs variables to be non-null

0 commit comments

Comments
 (0)