From patchwork Fri Dec 5 06:27:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Drepper X-Patchwork-Id: 418023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 366E01400EA for ; Fri, 5 Dec 2014 17:27:52 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=don2qcCP0jvfOAKwGxmL3pp/x5pFoyBR5SoarTphmVijUWeM6BoKV e/4ixm0mEw2FiSum3nH+hnPct+X9NMiz1wUXj3iTaz+fFz3pCTzze/XqIH6Dc3B/ UYZ9ggZeOvKLmCMgFc263hEl1y9SYmtZtxm6dpro1b+x8hl5gojTLo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=47wijDZvMMrDBGjT9wa3XgTAQy0=; b=Dc9Y4FXu+JDDzjiz9/W1 VHRGrshbfUebsaNYdfx8BXyaWQo6os4Z4SLg8PcOZnf5dhTRbNFzDYvSCMaTpMU9 ZV/98on1dv/Qx9eD8MYR/R+b2ugxMzsem/RPs1vM25VG0GWNrov+mKqRK/R56kGR xxa2yq2tHOhh8kdZffwsUas= Received: (qmail 20943 invoked by alias); 5 Dec 2014 06:27:43 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 20933 invoked by uid 89); 5 Dec 2014 06:27:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f46.google.com Received: from mail-qg0-f46.google.com (HELO mail-qg0-f46.google.com) (209.85.192.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 05 Dec 2014 06:27:40 +0000 Received: by mail-qg0-f46.google.com with SMTP id z107so38359qgd.5 for ; Thu, 04 Dec 2014 22:27:38 -0800 (PST) X-Received: by 10.140.94.229 with SMTP id g92mr23000544qge.77.1417760858422; Thu, 04 Dec 2014 22:27:38 -0800 (PST) Received: from myware.local (pool-100-37-161-222.nycmny.fios.verizon.net. [100.37.161.222]) by mx.google.com with ESMTPSA id g44sm25666886qgd.27.2014.12.04.22.27.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Dec 2014 22:27:38 -0800 (PST) Received: from myware.local (localhost.localdomain [127.0.0.1]) by myware.local (8.14.9/8.14.9) with ESMTP id sB56Rbvv027063 for ; Fri, 5 Dec 2014 01:27:37 -0500 Received: (from drepper@localhost) by myware.local (8.14.9/8.14.9/Submit) id sB56RbO4027062; Fri, 5 Dec 2014 01:27:37 -0500 From: Ulrich Drepper To: gcc-patches@gcc.gnu.org Subject: [PATCH] allow passing argument to the JIT linker Date: Fri, 05 Dec 2014 01:27:37 -0500 Message-ID: <87wq66ehly.fsf@gmail.com> MIME-Version: 1.0 If you generate code with the JIT which references outside symbols there is currently no way to have a self-contained DSO created. The command line to invoke the linker is fixed. The patch below would change that. It builds upon the existing framework to specify options for the compiler. The linker optimization flag fits fully into the existing functionality. For additional files to link with I had to extend the mechanism a bit since it is not just one string that needs to be remembered. I've also added the set_str_option member function to the C++ interface of the library. That must have been an oversight. What do you think? gcc/ChangeLog: 2014-12-05 Ulrich Drepper * jit/libgccjit++.h (context): Add missing set_str_option member function. * jit/libgccjit.h (gcc_jit_int_option): Add GCC_JIT_INT_OPTION_LINK_OPTIMIZATION_LEVEL. (gcc_jit_str_option): Add GCC_JIT_STR_OPTION_LINKFILE. * jit/jit-playback.c (convert_to_dso): Use auto_vec instead of fixed-sized array for arguments. Define ADD_ARG macro to add to it. Adjust existing code. Additionally add optimization level and additional link files to the list. * jit/jit-playback.h (context::get_linkfiles): New member function. * jit/jit-recording.c (recording::context:set_str_option): Handle GCC_JIT_STR_OPTION_LINKFILE. * jit/jit-recording.h (recording::context:set_str_option): Add get_linkfiles member function. diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index ecdae80..9c4e45f 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -1726,18 +1726,19 @@ convert_to_dso (const char *ctxt_progname) TV_ASSEMBLE. */ auto_timevar assemble_timevar (TV_ASSEMBLE); const char *errmsg; - const char *argv[7]; + auto_vec argvec; +#define ADD_ARG(arg) argvec.safe_push (arg) int exit_status = 0; int err = 0; const char *gcc_driver_name = GCC_DRIVER_NAME; - argv[0] = gcc_driver_name; - argv[1] = "-shared"; + ADD_ARG (gcc_driver_name); + ADD_ARG ("-shared"); /* The input: assembler. */ - argv[2] = m_path_s_file; + ADD_ARG (m_path_s_file); /* The output: shared library. */ - argv[3] = "-o"; - argv[4] = m_path_so_file; + ADD_ARG ("-o"); + ADD_ARG (m_path_so_file); /* Don't use the linker plugin. If running with just a "make" and not a "make install", then we'd @@ -1746,17 +1747,39 @@ convert_to_dso (const char *ctxt_progname) libto_plugin is a .la at build time, with it becoming installed with ".so" suffix: i.e. it doesn't exist with a .so suffix until install time. */ - argv[5] = "-fno-use-linker-plugin"; + ADD_ARG ("-fno-use-linker-plugin"); + + /* Linker int options. */ + switch (get_int_option (GCC_JIT_INT_OPTION_LINK_OPTIMIZATION_LEVEL)) + { + default: + add_error (NULL, + "unrecognized linker optimization level: %i", + get_int_option (GCC_JIT_INT_OPTION_LINK_OPTIMIZATION_LEVEL)); + return; + + case 0: + break; + + case 1: + ADD_ARG ("-Wl,-O"); + break; + } + + const char *elt; + const auto_vec& linkfiles = get_linkfiles(); + for (unsigned ix = 0; linkfiles.iterate(ix, &elt); ++ix) + ADD_ARG (elt); /* pex argv arrays are NULL-terminated. */ - argv[6] = NULL; + ADD_ARG (NULL); /* pex_one's error-handling requires pname to be non-NULL. */ gcc_assert (ctxt_progname); errmsg = pex_one (PEX_SEARCH, /* int flags, */ gcc_driver_name, - const_cast (argv), + const_cast (argvec.address ()), ctxt_progname, /* const char *pname */ NULL, /* const char *outname */ NULL, /* const char *errname */ @@ -1783,6 +1806,7 @@ convert_to_dso (const char *ctxt_progname) getenv ("PATH")); return; } +#undef ADD_ARG } /* Top-level hook for playing back a recording context. diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 02f08ba..2726347 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -175,6 +175,12 @@ public: return m_recording_ctxt->get_bool_option (opt); } + const auto_vec & + get_linkfiles () const + { + return m_recording_ctxt->get_linkfiles (); + } + builtins_manager *get_builtins_manager () const { return m_recording_ctxt->get_builtins_manager (); diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c index 82ec399..a6d64f9 100644 --- a/gcc/jit/jit-recording.c +++ b/gcc/jit/jit-recording.c @@ -827,7 +827,17 @@ recording::context::set_str_option (enum gcc_jit_str_option opt, "unrecognized (enum gcc_jit_str_option) value: %i", opt); return; } + + switch (opt) + { + default: m_str_options[opt] = value; + break; + + case GCC_JIT_STR_OPTION_LINKFILE: + m_linkfiles.safe_push (value); + break; + } } /* Set the given integer option for this context, or add an error if diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 31fb304..4b21248 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -209,6 +209,12 @@ public: return m_bool_options[opt]; } + const auto_vec& + get_linkfiles (void) const + { + return m_linkfiles; + } + result * compile (); @@ -249,6 +255,7 @@ private: const char *m_str_options[GCC_JIT_NUM_STR_OPTIONS]; int m_int_options[GCC_JIT_NUM_INT_OPTIONS]; bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS]; + auto_vec m_linkfiles; /* Recorded API usage. */ auto_vec m_mementos; @@ -1584,4 +1591,3 @@ private: } // namespace gcc #endif /* JIT_RECORDING_H */ - diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h index 67ed5d5..232bb0f 100644 --- a/gcc/jit/libgccjit++.h +++ b/gcc/jit/libgccjit++.h @@ -99,6 +99,9 @@ namespace gccjit void dump_to_file (const std::string &path, bool update_locations); + void set_str_option (enum gcc_jit_str_option opt, + const char *value); + void set_int_option (enum gcc_jit_int_option opt, int value); @@ -535,6 +538,14 @@ context::dump_to_file (const std::string &path, } inline void +context::set_str_option (enum gcc_jit_str_option opt, + const char *value) +{ + gcc_jit_context_set_str_option (m_inner_ctxt, opt, value); + +} + +inline void context::set_int_option (enum gcc_jit_int_option opt, int value) { diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index ed6390e..da3a2bf 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -139,6 +139,11 @@ enum gcc_jit_str_option messages to stderr. If NULL, or default, "libgccjit.so" is used. */ GCC_JIT_STR_OPTION_PROGNAME, + /* Additional files added to the link command line. To be used to + name libraries needed to satisfy dependencies in the generated + code. */ + GCC_JIT_STR_OPTION_LINKFILE, + GCC_JIT_NUM_STR_OPTIONS }; @@ -152,6 +157,11 @@ enum gcc_jit_int_option The default value is 0 (unoptimized). */ GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, + /* Optimization level for the linker. + + The default value is 0 (unoptimized). */ + GCC_JIT_INT_OPTION_LINK_OPTIMIZATION_LEVEL, + GCC_JIT_NUM_INT_OPTIONS };