From patchwork Sat Jan 27 15:10:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 193020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp533559dyb; Sat, 27 Jan 2024 07:11:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6Eb51my91zz+0FpuxvHhSRQOLJmasVvBeUQiHDg6okUqzl7ik/4iQmirMIM2kqtntS4TL X-Received: by 2002:a05:620a:40c1:b0:783:30d6:1c1e with SMTP id g1-20020a05620a40c100b0078330d61c1emr2261964qko.152.1706368297602; Sat, 27 Jan 2024 07:11:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706368297; cv=pass; d=google.com; s=arc-20160816; b=T/UtHmudqRDdT5VqEmc19TE3bqvxTkNYdIHwvHQUG/uwvEP+mAYxOV2e0+1KMGwmiB UgEXbhxsLWiUkJM2nqpENj4FOafPrnrm2pQWus9Zp/bUDm96lk826St/ohZYd5p6qguc zPlMzQS6cvfA+o5Ev7NDj9lziA4utBrYIXfQPbx06yK4jOmvv/CZW/Q3eda2TnC8KPbQ qIy4PvwLneCu7r7nZX14hNC3UTBBeToMXgLh/EbaHifuf/V56eFg91kk4ouKgXc8y5Jr Lhv0yjsvAGsSTln+5Ow/Nnq1GpNbJgvYNf9c+UsT17JYgGo8H4FkOcAsQ9Ib1+6oFkEG j2AQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=JHoHYgRMbYoWLcU2UYuAmdlBQ5aYvbRrU2xQ5FMyQ8w=; fh=K4AS3pFR26BR8zOf4IwrZlUeM0YSSQqO68Rjh5vfBKs=; b=jI8Pc9Y+Tx036LTFvBNisomHwqj4SW2sSxlB6hroZchDZJHD2x5uo4z4eaVRqpEbw5 lKfLY8Wq6qnFKsm5o8go5RcfG3r85ulzliSmu2YmT/ra5KGouI1KdXF7VaZ7wLjnzJox s4IIOUVOcU2ZNXOtFiMResvPQ827RDVbkFtoOehQQKVQ4olAfWYmrNjZW7fq/n/1kb07 1Mqj4Bkb3KJaUz05LhLgmzwsuFhxkz3SWMHON7wwkcxs4KrrokdH7GlZIAyDOYwilrCZ LOOs7IUdJeFMKqjbxkn/sVuoECAIZdftEC3/cHcuD/cC7sdf7IMSrT3iX2xCtzZE3336 YUNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lrdsYjlr; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 5-20020a05620a04c500b0078394900b65si3739503qks.257.2024.01.27.07.11.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 07:11:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lrdsYjlr; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E6AD3858281 for ; Sat, 27 Jan 2024 15:11:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 7A3493858C2D for ; Sat, 27 Jan 2024 15:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A3493858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7A3493858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706368260; cv=none; b=P3tXVsNcy1z5teQaGs7FtDmHnLFp0lngl9rYxN6T9v/JcE0T5GKquWsa2o0axVjlE0rlPgbTJ/g8I+mmTit6h3pDnZTpdwkBRAE9yOCA4DAxaLo6EK9cB4IxeusfvbNivv1WKtbmAuBuYnDHmmT2+OLP/phikj6kDZgp1X7cIms= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706368260; c=relaxed/simple; bh=d+Mpa3LqxrKilTHfuqLutzRJErwLDp3VOhs0xfRrjHg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ImbIL3VTN3og2Y8Kg7RmXFOdOiAv6MnxCMeTwaR4dVhEPs675th1bpnBy3WKoOUvJhIfXAh2Sow7Kmr7OtUMb65fG56ZhBSZi+CaQMuYKeTa4if6PWGXU5q4jjlApQrrmSru5y70YFPMPPb64Er3xg/COanZl8kDNQcAR4DeC0s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2906bcae4feso585318a91.3 for ; Sat, 27 Jan 2024 07:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706368257; x=1706973057; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JHoHYgRMbYoWLcU2UYuAmdlBQ5aYvbRrU2xQ5FMyQ8w=; b=lrdsYjlr99cVWcbUnqivNQu6LTsa6ok2ZCqQmW2ALGUQmV5XTtARprzHCQt56UQS4c gkdiQbS9FxcIKpRuebbSncywT2ypbKk1dRmSH1GkqHfZspCHdelOBau3ijWNRH6Nr8XQ Y27pHVemIxKOqMvDZvbAZth01NMvRmXA6lZJdWcezcciWjaQTDZ1eu/RwUwBMaHY7nM/ VTaOjCU3CqaWtxNvqXGpOw+CbK6zdmgGMl8Rw2IW4xt3XNGotgdHqiM53EAcCw73iI/O jD6D09VW0hbL0FyCAYEw6IBW1VuMVf7CpULRvqwcZv4lISNxvkX7EW8DDDDpEBxECQ1B Uesw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706368257; x=1706973057; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JHoHYgRMbYoWLcU2UYuAmdlBQ5aYvbRrU2xQ5FMyQ8w=; b=ULke22CqPkIWcwtV+wOykC9azU10ik0xq8SbtR5adM22ZufSYfsbeVUgELlLQDgwk2 pibi3aq6+/I7Wfe3+Ccc9hZZOm7pygllUB1g5FtVuHfhU1e444Jdgh5d7RyyvQS+6jXW mQkAOjJJ/LOXsuPJU3ko/eje45x3IBIYWnLGe8qFlDQmwuRYxgI2B5TlNOvjW584uh5i FaxWIFb/OtdoqcbCpxksyZBw7WHTDFjCup8kwew5tHvESndln6C5gq/JJGPJQTUdkN54 RSzAr4G4PForVx1SHj5e43LfKbQ6McHAstVcwwVTdMbttf2GzS6WCIzybiO3YCcp1JUr es4Q== X-Gm-Message-State: AOJu0Yw+/yxWofrg0RT2i0Jkx5StTFNE3soq4cbOEjtcqiVf68Tr4ntU KVxTSc3+/hn4uknNgCyCU8IyAuDU2piDn1rsZcNARtju9nRbJ9y6TGlxZWYM X-Received: by 2002:a17:90a:e657:b0:290:caa8:34b with SMTP id ep23-20020a17090ae65700b00290caa8034bmr739141pjb.55.1706368257064; Sat, 27 Jan 2024 07:10:57 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id oe1-20020a17090b394100b002953d87ecebsm845759pjb.34.2024.01.27.07.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 07:10:56 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 2C5BA740067; Sat, 27 Jan 2024 07:10:55 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH] Handle function symbol reference in readonly data section Date: Sat, 27 Jan 2024 07:10:55 -0800 Message-ID: <20240127151055.358066-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3023.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789256844185690600 X-GMAIL-MSGID: 1789256844185690600 For function symbol reference in readonly data section, instead of putting it in .data.rel.ro or .rodata.cst section, call function_rodata_section to get the read-only or relocated read-only data section associated with the function DECL so that the COMDAT section will be used for a COMDAT function symbol. gcc/ PR rtl-optimization/113617 * varasm.cc (default_elf_select_rtx_section): Call function_rodata_section to get the read-only or relocated read-only data section for function symbol reference. gcc/testsuite/ PR rtl-optimization/113617 * g++.dg/pr113617-1a.C: New test. * g++.dg/pr113617-1b.C: Likewise. --- gcc/testsuite/g++.dg/pr113617-1a.C | 170 +++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/pr113617-1b.C | 8 ++ gcc/varasm.cc | 18 +++ 3 files changed, 196 insertions(+) create mode 100644 gcc/testsuite/g++.dg/pr113617-1a.C create mode 100644 gcc/testsuite/g++.dg/pr113617-1b.C diff --git a/gcc/testsuite/g++.dg/pr113617-1a.C b/gcc/testsuite/g++.dg/pr113617-1a.C new file mode 100644 index 00000000000..effd50841c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr113617-1a.C @@ -0,0 +1,170 @@ +// { dg-do compile { target fpic } } +// { dg-require-visibility "" } +// { dg-options "-O2 -std=c++11 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden" } + +namespace { +template struct integral_constant { + static constexpr int value = __v; +}; +template using __bool_constant = integral_constant<__v>; +using true_type = __bool_constant; +template struct __conditional { + template using type = _Tp; +}; +template +using __conditional_t = typename __conditional<_Cond>::type<_If, _Else>; +true_type __trans_tmp_1; +template struct remove_cv { using type = _Tp; }; +template +struct __decay_selector + : __conditional_t, _Up> {}; +template struct decay { + using type = typename __decay_selector<_Tp>::type; +}; +} +struct vtkCellArray {}; +namespace blah { +struct _Any_data; +enum _Manager_operation {}; +template class function; +struct _Function_base { + using _Manager_type = bool (*)(_Any_data &, const _Any_data &, + _Manager_operation); + _Manager_type _M_manager; +}; +template class _Function_handler; +template +struct _Function_handler<_Res(_ArgTypes...), _Functor> { + static bool _M_manager(_Any_data &, const _Any_data &, _Manager_operation) { + return false; + } + __attribute__((noipa)) static _Res _M_invoke(const _Any_data &) {} +}; +template +struct function<_Res(_ArgTypes...)> : _Function_base { + template + using _Handler = _Function_handler<_Res(), _Functor>; + template function(_Functor) { + using _My_handler = _Handler<_Functor>; + _M_invoker = _My_handler::_M_invoke; + _M_manager = _My_handler::_M_manager; + } + using _Invoker_type = _Res (*)(const _Any_data &); + _Invoker_type _M_invoker; +}; +template class _Bind; +template +struct _Bind<_Functor(_Bound_args...)> {}; +template using __is_socketlike = decltype(__trans_tmp_1); +template struct _Bind_helper { + typedef _Bind::type( + typename decay<_BoundArgs>::type...)> + type; +}; +template +__attribute__((noipa)) typename _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type +bind(_Func, _BoundArgs...) { return typename _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type (); } +template struct __uniq_ptr_impl { + template struct _Ptr { using type = _Up *; }; + using pointer = typename _Ptr<_Tp>::type; +}; +template struct unique_ptr { + using pointer = typename __uniq_ptr_impl<_Tp>::pointer; + pointer operator->(); +}; +} +extern int For_threadNumber; +namespace vtk { +namespace detail { +namespace smp { +enum BackendType { Sequential, STDThread }; +template struct vtkSMPToolsImpl { + template + __attribute__((noipa)) void For(long long, long long, long long, FunctorInternal &) {} +}; +struct vtkSMPThreadPool { + vtkSMPThreadPool(int); + void DoJob(blah::function); +}; +template +__attribute__((noipa)) void ExecuteFunctorSTDThread(void *, long long, long long, long long) {} +template <> +template +void vtkSMPToolsImpl::For(long long, long long last, long long grain, + FunctorInternal &fi) { + vtkSMPThreadPool pool(For_threadNumber); + for (;;) { + auto job = blah::bind(ExecuteFunctorSTDThread, &fi, grain, + grain, last); + pool.DoJob(job); + } +} +struct vtkSMPToolsAPI { + static vtkSMPToolsAPI &GetInstance(); + template + void For(long first, long last, long grain, FunctorInternal fi) { + switch (ActivatedBackend) { + case Sequential: + SequentialBackend->For(first, last, grain, fi); + case STDThread: + STDThreadBackend->For(first, last, grain, fi); + } + } + BackendType ActivatedBackend; + blah::unique_ptr> SequentialBackend; + blah::unique_ptr> STDThreadBackend; +}; +template struct vtkSMPTools_FunctorInternal; +template struct vtkSMPTools_FunctorInternal { + __attribute__((noipa)) vtkSMPTools_FunctorInternal(Functor) {} + void For(long first, long last, long grain) { + auto SMPToolsAPI = vtkSMPToolsAPI::GetInstance(); + SMPToolsAPI.For(first, last, grain, *this); + } +}; +template struct vtkSMPTools_Lookup_For { + typedef vtkSMPTools_FunctorInternal type; +}; +} +} +} +struct vtkSMPTools { + template + static void For(long first, long last, long grain, Functor f) { + typename vtk::detail::smp::vtkSMPTools_Lookup_For::type fi(f); + fi.For(first, last, grain); + } + template + static void For(long first, long last, Functor f) { + For(first, last, 0, f); + } +}; +template struct vtkStaticCellLinksTemplate { + void ThreadedBuildLinks(long long, long long, vtkCellArray *); + int *Offsets; +}; +namespace { +template struct CountUses { __attribute__((noipa)) CountUses(vtkCellArray *, int *) {} }; +} +template +void vtkStaticCellLinksTemplate::ThreadedBuildLinks( + long long numPts, long long numCells, vtkCellArray *cellArray) { + int counts; + CountUses count(cellArray, &counts); + vtkSMPTools::For(0, numCells, count); + long ptId, npts; + for (ptId = 0; ptId < numPts; ptId++) + Offsets[ptId] = Offsets[ptId - 1] + npts; +} + +int For_threadNumber; +long vtkConstrainedSmoothingFilterRequestData_numPts; +void vtkConstrainedSmoothingFilterRequestData() { + vtkCellArray lines; + vtkStaticCellLinksTemplate links; + links.ThreadedBuildLinks(vtkConstrainedSmoothingFilterRequestData_numPts, 0, + &lines); +} + +// { dg-final { scan-assembler-not ".section\t\.data\.rel\.ro\.local,\"aw\"" { target { { i?86-*-linux* x86_64-*-linux* } && { ! ia32 } } } } } +// { dg-final { scan-assembler ".section\t.data\.rel\.ro\.local\..*,\"awG\"" { target { { i?86-*-linux* x86_64-*-linux* } && { ! ia32 } } } } } diff --git a/gcc/testsuite/g++.dg/pr113617-1b.C b/gcc/testsuite/g++.dg/pr113617-1b.C new file mode 100644 index 00000000000..4a02bf44e72 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr113617-1b.C @@ -0,0 +1,8 @@ +// { dg-do compile { target fpic } } +// { dg-require-visibility "" } +// { dg-options "-O2 -std=c++11 -fno-pic -fvisibility=hidden -fvisibility-inlines-hidden" } + +#include "pr113617-1a.C" + +// { dg-final { scan-assembler-not ".section\t\.rodata\.cst(4|8),\"aM\"" { target { { i?86-*-linux* x86_64-*-linux* } && { ! ia32 } } } } } +// { dg-final { scan-assembler ".section\t\.rodata\..*,\"aG\"" { target { { i?86-*-linux* x86_64-*-linux* } && { ! ia32 } } } } } diff --git a/gcc/varasm.cc b/gcc/varasm.cc index fa17eff551e..31d57edbe8a 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -7459,16 +7459,34 @@ default_elf_select_rtx_section (machine_mode mode, rtx x, { int reloc = compute_reloc_for_rtx (x); + /* If it is a function symbol reference, call function_rodata_section + for the read-only or relocated read-only data section associated + with function DECL so that the COMDAT section will be used for a + COMDAT function symbol. */ + tree decl = nullptr; + if (GET_CODE (x) == SYMBOL_REF) + { + decl = SYMBOL_REF_DECL (x); + if (TREE_CODE (decl) != FUNCTION_DECL) + decl = nullptr; + } + /* ??? Handle small data here somehow. */ if (reloc & targetm.asm_out.reloc_rw_mask ()) { + if (decl) + return targetm.asm_out.function_rodata_section (decl, true); + if (reloc == 1) return get_named_section (NULL, ".data.rel.ro.local", 1); else return get_named_section (NULL, ".data.rel.ro", 3); } + if (decl) + return targetm.asm_out.function_rodata_section (decl, false); + return mergeable_constant_section (mode, align, 0); }