From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id E95AC3857439 for ; Thu, 20 May 2021 19:29:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E95AC3857439 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-wA5E4QY0NyaFolbOZ6NpoA-1; Thu, 20 May 2021 15:29:39 -0400 X-MC-Unique: wA5E4QY0NyaFolbOZ6NpoA-1 Received: by mail-qk1-f200.google.com with SMTP id b19-20020a05620a0893b02902e956b29f5dso13486644qka.16 for ; Thu, 20 May 2021 12:29:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=rjlgBb58qB8C0bQ0JD87hDxaBelJLn9J3/VfTt8K7MA=; b=eEiQ2qYiutUxb7I5y79b8C/exnWHl1OJuBpXCaoa3Kn+seg86czoaelh8ylKPsMjB4 SJTCbtwBxnVXXTVTUuCA+7zBkHzCGfQeQ8ETHWRXQFrnlMKOcgz589Bh2Ex15zPZ+9Rl YXNse3tG/ONrvpaxrBORF1pnMgfwITsgSJ14/6TG/pdGJCaNBuf7zMSagVU9uP3dsjFU jPxwDKXzUZpFxXBJF9IrWn5Gienq9SbH/vOtWFFIiYyUrQGoBpXrxc/gpWmNnwY4OFOQ 0CI+LY3+1GIiY2j29UkZPlHe6LEThXXe+8R2hhOEmIV/lXv5vFnIq+n1KYEHBeFs4hPk TMlQ== X-Gm-Message-State: AOAM53106jBRDE1U7HZ/JrT8mezsuKVWWALvsAy+jsfdJLh2NimoAwED 9cKs+0IVVAqq5Mi6VjCOsjb+WvJX47mswe1shBpXNOhfKACVkFrulnlu0cADUwPWBt//loX3tsf Dgb82F90= X-Received: by 2002:a05:620a:a:: with SMTP id j10mr7372313qki.195.1621538978424; Thu, 20 May 2021 12:29:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynqjYJ9JKHpH9bhbZy7BcT8N0RYU8MXrEa8RR4KLDVTmucBqQatVZQV+UH18q32Yof9PaSGA== X-Received: by 2002:a05:620a:a:: with SMTP id j10mr7372291qki.195.1621538978104; Thu, 20 May 2021 12:29:38 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.nh.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id 28sm3035064qkr.36.2021.05.20.12.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 12:29:37 -0700 (PDT) Message-ID: Subject: Re: [PATCH] libgccjit: Add support for setting the link section of global variables [PR100688] From: David Malcolm To: Antoni Boucher , jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Date: Thu, 20 May 2021 15:29:36 -0400 In-Reply-To: <7fde146d8c3aecb47f66f34c836e2733eb4d8a6d.camel@zoho.com> References: <7fde146d8c3aecb47f66f34c836e2733eb4d8a6d.camel@zoho.com> User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: jit@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Jit mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 19:29:42 -0000 On Wed, 2021-05-19 at 20:32 -0400, Antoni Boucher via Jit wrote: > Hello. > This patch adds support to set the link section of global variables. > I used the ABI 18 because I submitted other patches up to 17. > Thanks for the review. I didn't see this email until now, and put the review in bugzilla instead; sorry. Here's a copy-and-paste of what I put in bugzilla: Thanks for the patch; I like the idea; various nits below: > diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/expressions.rst > index 396259ef07e..b39f6c02527 100644 > --- a/gcc/jit/docs/topics/expressions.rst > +++ b/gcc/jit/docs/topics/expressions.rst > @@ -539,6 +539,18 @@ where the rvalue is computed by reading from the storage area. > > in C. > > +.. function:: void > + gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue, > + const char *name) > + > + Set the link section of a variable; analogous to: > + > + .. code-block:: c > + > + int variable __attribute__((section(".section"))); > + > + in C. Please rename param "name" to "section_name". Your implementation requires that it be non-NULL (rather than having NULL unset the section), so please specify that it must be non-NULL in the docs. Please add the usual "This entrypoint was added in" text to state which API version it was added in. > + > Global variables > **************** > > diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h > index 825a3e172e9..8b0f65e87e8 100644 > --- a/gcc/jit/jit-playback.h > +++ b/gcc/jit/jit-playback.h > @@ -650,6 +650,8 @@ public: > > private: > context *m_ctxt; > + > +protected: > tree m_inner; > }; I think you only use this... > > @@ -670,6 +672,12 @@ public: > rvalue * > get_address (location *loc); > > + void > + set_link_section (const char* name) > + { > + set_decl_section_name (m_inner, name); > + } ...here, and you can get at rvalue::m_inner using as_tree (), so I don't think we need to make m_inner protected. > diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c > index 117ff70114c..d54f878cc6b 100644 > --- a/gcc/jit/jit-recording.c > +++ b/gcc/jit/jit-recording.c > @@ -3713,6 +3713,11 @@ recording::lvalue::get_address (recording::location *loc) > return result; > } > > +void recording::lvalue::set_link_section (const char *name) > +{ > + m_link_section = new_string (name); > +} > + > /* The implementation of class gcc::jit::recording::param. */ > > /* Implementation of pure virtual hook recording::memento::replay_into > @@ -4547,8 +4552,7 @@ recording::block::dump_edges_to_dot (pretty_printer *pp) > void > recording::global::replay_into (replayer *r) > { > - set_playback_obj ( > - m_initializer > + playback::lvalue *global = m_initializer > ? r->new_global_initialized (playback_location (r, m_loc), > m_kind, > m_type->playback_type (), > @@ -4560,7 +4564,12 @@ recording::global::replay_into (replayer *r) > : r->new_global (playback_location (r, m_loc), > m_kind, > m_type->playback_type (), > - playback_string (m_name))); > + playback_string (m_name)); > + if (m_link_section != NULL) > + { > + global->set_link_section(m_link_section->c_str()); > + } Coding convention nits: don't use {} when it's just one statement (which I think is a bad convention, but it is the project's convention). Missing spaces between function name and open-paren in both calls here. > + set_playback_obj (global); > } > [...snip....] > diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h > index 03fa1160cf0..0691fac579d 100644 > --- a/gcc/jit/jit-recording.h > +++ b/gcc/jit/jit-recording.h > @@ -1105,7 +1105,8 @@ public: > lvalue (context *ctxt, > location *loc, > type *type_) > - : rvalue (ctxt, loc, type_) > + : rvalue (ctxt, loc, type_), > + m_link_section(NULL) > {} > > playback::lvalue * > @@ -1127,6 +1128,10 @@ public: > const char *access_as_rvalue (reproducer &r) OVERRIDE; > virtual const char *access_as_lvalue (reproducer &r); > virtual bool is_global () const { return false; } > + void set_link_section (const char *name); > + > +protected: > + string *m_link_section; > }; Can it be private, rather than protected? > diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c > index 7fa948007ad..8cfa48aae24 100644 > --- a/gcc/jit/libgccjit.c > +++ b/gcc/jit/libgccjit.c > @@ -1953,6 +1953,18 @@ gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue, > return (gcc_jit_rvalue *)lvalue->get_address (loc); > } > > +/* Public entrypoint. See description in libgccjit.h. > + > + After error-checking, the real work is done by the > + gcc::jit::recording::lvalue::set_section method in jit- recording.c. */ ^^^^^^^^^^^ set_link_section Also, a newline here please for consistency with the other entrypoints. > +void > +gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue, > + const char *name) > +{ > + RETURN_IF_FAIL (name, NULL, NULL, "NULL name"); > + lvalue->set_link_section(name); Missing a space between function name and open-paren. > diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h > index 5c722c2c57f..21553ede3de 100644 > --- a/gcc/jit/libgccjit.h > +++ b/gcc/jit/libgccjit.h > @@ -1072,6 +1072,19 @@ extern gcc_jit_rvalue * > gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue, > gcc_jit_location *loc); > > +#define LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section > + > +/* Set the link section of a global variable; analogous to: > + __attribute__((section("section_name"))) > + in C. > + > + This API entrypoint was added in LIBGCCJIT_ABI_18; you can test for its > + presence using > + #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_tls_model */ Wrong #ifdef in the comment. > +extern void > +gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue, > + const char *name); Rename param "name" to "section_name" to match the comment. > diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map > index 337ea6c7fe4..9e722c2bde1 100644 > --- a/gcc/jit/libgccjit.map > +++ b/gcc/jit/libgccjit.map > @@ -205,3 +205,14 @@ LIBGCCJIT_ABI_15 { > gcc_jit_extended_asm_add_clobber; > gcc_jit_context_add_top_level_asm; > } LIBGCCJIT_ABI_14; > + > +LIBGCCJIT_ABI_16 { > +} LIBGCCJIT_ABI_15; > + > +LIBGCCJIT_ABI_17 { > +} LIBGCCJIT_ABI_16; > + > +LIBGCCJIT_ABI_18 { > + global: > + gcc_jit_lvalue_set_link_section; > +} LIBGCCJIT_ABI_17; I have some other patches of yours to review (presumably where the other ABI things are); sorry about that. I'll try to get to them today. > diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h > index 4202eb7798b..7e3b59dee0d 100644 > --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h > +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h > @@ -181,6 +181,13 @@ > #undef create_code > #undef verify_code > > +/* test-link-section.c */ > +#define create_code create_code_link_section > +#define verify_code verify_code_link_section > +#include "test-link-section.c" > +#undef create_code > +#undef verify_code > + > /* test-hello-world.c */ > #define create_code create_code_hello_world > #define verify_code verify_code_hello_world > diff --git a/gcc/testsuite/jit.dg/test-link-section.c b/gcc/testsuite/jit.dg/test-link-section.c > new file mode 100644 > index 00000000000..546c1e95b92 > --- /dev/null > +++ b/gcc/testsuite/jit.dg/test-link-section.c > @@ -0,0 +1,25 @@ > +#include > +#include > + > +#include "libgccjit.h" > + > +#include "harness.h" > + > +void > +create_code (gcc_jit_context *ctxt, void *user_data) > +{ > + /* Let's try to inject the equivalent of: > + int foo __attribute__((section(".section"))); > + */ > + gcc_jit_type *int_type = > + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); > + gcc_jit_lvalue *foo = > + gcc_jit_context_new_global ( > + ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "foo"); > + gcc_jit_lvalue_set_link_section(foo, "section"); > +} > + > +extern void > +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) > +{ > +} This is OK, but ideally it would test that the section name made it into the generated assembler. test-compile-to-assembler.c has a testcase for this which does something similar, with a DejaGnu directive looking for a substring in the generated asm if you want to attempt it. One other thing: the docs should make it clear about the leading ".". If I want to create the equivalent of: __attribute__((section(".section"))) do I call it with: gcc_jit_lvalue_set_link_section(foo, "section"); or with: gcc_jit_lvalue_set_link_section(foo, ".section"); It's a bit unclear to me from just reading the patch. The example suggests it's the former. In either case, the documentation should be clearer about this. Hope this is constructive Dave