32-bit and 64-bit multilib peer builds of libgccjit.so could share a driver binary. When such a libgccjit invokes the driver (e.g. to convert .s to .so) it needs to pass in options to the shared driver to get the appropriate assembler/linker options.
The simplest way to do this is for libgccjit to supply any arguments found in MULTILIB_DEFAULTS when invoking the driver. Tested on x86_64 Fedora 20, running "make check-jit"; jit.sum on trunk continues to have 8494 passes after the patch. The options are visible in the jit logfiles: after the patch I see: JIT: entering: void gcc::jit::playback::context::convert_to_dso(const char*) JIT: entering: void gcc::jit::playback::context::invoke_driver(const char*, const char*, const char*, timevar_id_t, bool, bool) JIT: entering: void gcc::jit::playback::context::add_multilib_driver_arguments(vec<char*>*) JIT: exiting: void gcc::jit::playback::context::add_multilib_driver_arguments(vec<char*>*) JIT: argv[0]: x86_64-unknown-linux-gnu-gcc-6.0.0 JIT: argv[1]: -m64 JIT: argv[2]: -shared JIT: argv[3]: /tmp/libgccjit-WH0Mxy/fake.s JIT: argv[4]: -o JIT: argv[5]: /tmp/libgccjit-WH0Mxy/fake.so JIT: argv[6]: -fno-use-linker-plugin JIT: argv[7]: (null) JIT: exiting: void gcc::jit::playback::context::invoke_driver(const char*, const char*, const char*, timevar_id_t, bool, bool) JIT: exiting: void gcc::jit::playback::context::convert_to_dso(const char*) (note the "argv[1]: -m64" line) Committed to trunk as r226126. gcc/jit/ChangeLog: * jit-playback.c (invoke_driver): Convert local "argvec" to an auto_argvec, so that it owns copies of the strings, rather than borrows them, updating ADD_ARG to use xstrdup and special-casing the NULL terminator to avoid xstrdup (NULL). Call add_multilib_driver_arguments at the front of the arguments. (MULTILIB_DEFAULTS): Provide a default definition. (multilib_defaults_raw): New constant array. (gcc::jit::playback::context::add_multilib_driver_arguments): New method. * jit-playback.h (gcc::jit::playback::context::add_multilib_driver_arguments): New method. * docs/internals/test-hello-world.exe.log.txt: Update. * docs/_build/texinfo/libgccjit.texi: Regenerate. --- .../docs/internals/test-hello-world.exe.log.txt | 26 +++++++-------- gcc/jit/jit-playback.c | 38 ++++++++++++++++++++-- gcc/jit/jit-playback.h | 3 ++ 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/gcc/jit/docs/internals/test-hello-world.exe.log.txt b/gcc/jit/docs/internals/test-hello-world.exe.log.txt index 5cb3aef..d82038b 100644 --- a/gcc/jit/docs/internals/test-hello-world.exe.log.txt +++ b/gcc/jit/docs/internals/test-hello-world.exe.log.txt @@ -1,4 +1,4 @@ -JIT: libgccjit (GCC) version 5.0.0 20150123 (experimental) (x86_64-unknown-linux-gnu) +JIT: libgccjit (GCC) version 6.0.0 20150723 (experimental) (x86_64-unknown-linux-gnu) JIT: compiled by GNU C version 4.8.3 20140911 (Red Hat 4.8.3-7), GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1 JIT: entering: gcc_jit_context_set_str_option JIT: GCC_JIT_STR_OPTION_PROGNAME: "./test-hello-world.c.exe" @@ -64,6 +64,7 @@ JIT: GCC_JIT_BOOL_OPTION_DUMP_SUMMARY: false JIT: GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING: false JIT: GCC_JIT_BOOL_OPTION_SELFCHECK_GC: true JIT: GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES: false +JIT: gcc_jit_context_set_bool_allow_unreachable_blocks: false JIT: entering: void gcc::jit::recording::context::validate() JIT: exiting: void gcc::jit::recording::context::validate() JIT: entering: gcc::jit::playback::context::context(gcc::jit::recording::context*) @@ -115,12 +116,6 @@ JIT: exiting: void gcc::jit::playback::function::postprocess() JIT: entering: void gcc::jit::playback::function::postprocess() JIT: exiting: void gcc::jit::playback::function::postprocess() JIT: exiting: void gcc::jit::playback::context::replay() -JIT: entering: void jit_langhook_write_globals() -JIT: entering: void gcc::jit::playback::context::write_global_decls_1() -JIT: exiting: void gcc::jit::playback::context::write_global_decls_1() -JIT: entering: void gcc::jit::playback::context::write_global_decls_2() -JIT: exiting: void gcc::jit::playback::context::write_global_decls_2() -JIT: exiting: void jit_langhook_write_globals() JIT: exiting: toplev::main JIT: entering: void gcc::jit::playback::context::extract_any_requested_dumps(vec<gcc::jit::recording::requested_dump>*) JIT: exiting: void gcc::jit::playback::context::extract_any_requested_dumps(vec<gcc::jit::recording::requested_dump>*) @@ -129,13 +124,16 @@ JIT: exiting: toplev::finalize JIT: entering: virtual void gcc::jit::playback::compile_to_memory::postprocess(const char*) JIT: entering: void gcc::jit::playback::context::convert_to_dso(const char*) JIT: entering: void gcc::jit::playback::context::invoke_driver(const char*, const char*, const char*, timevar_id_t, bool, bool) -JIT: argv[0]: x86_64-unknown-linux-gnu-gcc-5.0.0 -JIT: argv[1]: -shared -JIT: argv[2]: /tmp/libgccjit-CKq1M9/fake.s -JIT: argv[3]: -o -JIT: argv[4]: /tmp/libgccjit-CKq1M9/fake.so -JIT: argv[5]: -fno-use-linker-plugin -JIT: argv[6]: (null) +JIT: entering: void gcc::jit::playback::context::add_multilib_driver_arguments(vec<char*>*) +JIT: exiting: void gcc::jit::playback::context::add_multilib_driver_arguments(vec<char*>*) +JIT: argv[0]: x86_64-unknown-linux-gnu-gcc-6.0.0 +JIT: argv[1]: -m64 +JIT: argv[2]: -shared +JIT: argv[3]: /tmp/libgccjit-CKq1M9/fake.s +JIT: argv[4]: -o +JIT: argv[5]: /tmp/libgccjit-CKq1M9/fake.so +JIT: argv[6]: -fno-use-linker-plugin +JIT: argv[7]: (null) JIT: exiting: void gcc::jit::playback::context::invoke_driver(const char*, const char*, const char*, timevar_id_t, bool, bool) JIT: exiting: void gcc::jit::playback::context::convert_to_dso(const char*) JIT: entering: gcc::jit::result* gcc::jit::playback::context::dlopen_built_dso() diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index 8d0c210..c469863 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -2382,14 +2382,16 @@ invoke_driver (const char *ctxt_progname, TV_ASSEMBLE. */ auto_timevar assemble_timevar (tv_id); const char *errmsg; - auto_vec <const char *> argvec; -#define ADD_ARG(arg) argvec.safe_push (arg) + auto_argvec argvec; +#define ADD_ARG(arg) argvec.safe_push (xstrdup (arg)) int exit_status = 0; int err = 0; const char *gcc_driver_name = GCC_DRIVER_NAME; ADD_ARG (gcc_driver_name); + add_multilib_driver_arguments (&argvec); + if (shared) ADD_ARG ("-shared"); @@ -2410,7 +2412,7 @@ invoke_driver (const char *ctxt_progname, ADD_ARG ("-fno-use-linker-plugin"); /* pex argv arrays are NULL-terminated. */ - ADD_ARG (NULL); + argvec.safe_push (NULL); /* pex_one's error-handling requires pname to be non-NULL. */ gcc_assert (ctxt_progname); @@ -2451,6 +2453,36 @@ invoke_driver (const char *ctxt_progname, #undef ADD_ARG } +/* Extract the target-specific MULTILIB_DEFAULTS to + multilib_defaults_raw for use by + playback::context::add_multilib_driver_arguments (). */ + +#ifndef MULTILIB_DEFAULTS +#define MULTILIB_DEFAULTS { "" } +#endif + +static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS; + +/* Helper function for playback::context::invoke_driver (). + + 32-bit and 64-bit multilib peer builds of libgccjit.so may share + a driver binary. We need to pass in options to the shared driver + to get the appropriate assembler/linker options for this multilib + peer. */ + +void +playback::context:: +add_multilib_driver_arguments (vec <char *> *argvec) +{ + JIT_LOG_SCOPE (get_logger ()); + + /* Add copies of the arguments in multilib_defaults_raw to argvec, + prepending each with a "-". */ + for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++) + if (multilib_defaults_raw[i][0]) + argvec->safe_push (concat ("-", multilib_defaults_raw[i], NULL)); +} + /* Dynamically-link the built DSO file into this process, using dlopen. Wrap it up within a jit::result *, and return that. Return NULL if any errors occur, reporting them on this context. */ diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 13cc748..1d7de17 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -272,6 +272,9 @@ protected: bool shared, bool run_linker); + void + add_multilib_driver_arguments (vec <char *> *argvec); + result * dlopen_built_dso (); -- 1.8.5.3