From patchwork Thu Jan 18 14:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 84349 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAE393858409 for ; Thu, 18 Jan 2024 14:59:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 36E563858C2A for ; Thu, 18 Jan 2024 14:59:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36E563858C2A 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 36E563858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705589970; cv=none; b=ULMFeDrJBLLOMiFGX7kTs/9/LeodnxcDVjD9A+s3HQeC859uw5c0oOUp3MRcvJ08fRjqxs3TmEyLWaZK9YHMFwpQGluf4+/0dxr9cOLwU42dtVFadxIknq4haEFNl0yKPqltx2aXgf8XAyXPEteEMmBWNN0DuXbYBSqKKig/8l0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705589970; c=relaxed/simple; bh=MlAjHxgEFckbABPNrtF9Nw3MCv0KdMtm+5KHE5YyoeE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jIn7Gsd6TroSoXi8k/0dT7dwQxg2k6YWA46rjJJcZC93OMaGx+pJIhgTrseSXZhNl2sjIjy0IZafgyHDso4pyOFr//mYJdQWGzeZr4znFub7+UJYS0x1brYYoCsSTeo2Nbg8Bt/6jDu3/fSPUcVqsBpx1u+K9d8QjrEE+CvzgdI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e90163be1so7945535e9.1 for ; Thu, 18 Jan 2024 06:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705589965; x=1706194765; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=CW0DtRHTgWHCHYc+rWcdaPEoRxLALaKuZgT00N9fG1w=; b=N2LAQK4kty10xSadbFRJvwIDMboP32cXRMvRTl9F4HHcfbz3nX4zD4Qc5c6mKeOuPv avUkyAw+DNzzZ3siaTItoeblvXZVa8DneUB84W6p8xtKsddf5y/xvCyu8y4KTStMquoM ZRHgBxL4Gzowj2uOpqHiNIeWyQSHDN6K6GNbJKiFezjyRkfrDJN7ZPOeqgX/E8E+df1o GByQ8JuyMMP5GaGRKVi5Zxihnq4gKYbdq4sPKxUI3tyu9jHt0R997e37BS+oauQWVam0 69iOG1KfJyiajUBBnE+LDKQsIT5g0fmLwrohoNCNpRjCK2IeafP3JrGIKg36DWIknbAJ 9ZdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705589965; x=1706194765; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CW0DtRHTgWHCHYc+rWcdaPEoRxLALaKuZgT00N9fG1w=; b=jWoCJQ+ZtmIU3Ny6jYHgSpEWmmV8CegMekCiv8DcScbQUX9Lroh3Q5U6eQCpA+PWdd 67j/w0oh30WLMDpdTdw3MCkqHufzL8m9xYJ2sZlW/bIct84TBfG7ALAiGu9l388WLn5m 5EYrc6tdRu2eBgRYnkBEiLCbbxfNXTtCYiHUyXUcHcRpP2qUwGShPyJs94/nkRX//65L HNqna1TJejvajCO8OMJbLwuyk+D51PykKltblxPWWMtJ+j203G0x8EdehbJOJY9Yctlf wc4oFD/67lz0LIWWg8U7ryqjCeNg4FR8GcGOg7yjR715iDXFSUCu0fjHEQfj6HWusTZF 6eFQ== X-Gm-Message-State: AOJu0Yz1N9FzC7nXernVv/jiCvqka94gl5KRvuKPtJf6QbkczEWXVtZ6 HUbDEX26mwYl3hZ3g1KWm6/ogQYsWAWQ2YejwxiGfUWIr0DpPPHabYs4y6Z3 X-Google-Smtp-Source: AGHT+IGHP8vZ5jlZGDixdz+ybXehO+8qa+h76MZI2LfAT4uKQfYJZ0Zm55bRuv4Q3s5RVY5lWGZ9JA== X-Received: by 2002:a05:600c:1d20:b0:40d:5a41:52e with SMTP id l32-20020a05600c1d2000b0040d5a41052emr275401wms.161.1705589964688; Thu, 18 Jan 2024 06:59:24 -0800 (PST) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id f18-20020a05600c155200b0040d87100733sm26208613wmg.39.2024.01.18.06.59.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 18 Jan 2024 06:59:24 -0800 (PST) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH v3] Fix __builtin_nested_func_ptr_{created, deleted} symbol versions [PR113402] Date: Thu, 18 Jan 2024 14:59:23 +0000 Message-Id: <20240118145923.25112-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org In order to regularise the two new builtins as extension library types the scope of this patch has grown w.r.t "just rename". Tested on x86_64-darwin21 (default heap trampolines) and x86_64 Linux and other Darwin platforms that are default executable stack. How does this look now? thanks Iain --- 8< --- The symbols for the functions supporting heap-based trampolines were exported at an incorrect symbol version, the following patch fixes that. As requested in the PR, this also renames __builtin_nested_func_ptr* to __gcc_nested_func_ptr*. In carrying our the rename, we move the builtins to use DEF_EXT_LIB_BUILTIN. PR libgcc/113402 gcc/ChangeLog: * builtins.cc (expand_builtin): Handle BUILT_IN_NESTED_PTR_CREATED and BUILT_IN_NESTED_PTR_DELETED. * builtins.def (BUILT_IN_NESTED_PTR_CREATED, BUILT_IN_NESTED_PTR_DELETED): Make these builtins LIB-EXT and rename the library fallbacks to __gcc_nested_func_ptr_created and __gcc_nested_func_ptr_deleted. * doc/invoke.texi: Rename these to __gcc_nested_func_ptr_created and __gcc_nested_func_ptr_deleted. * tree-nested.cc (finalize_nesting_tree_1): Use builtin_explicit for BUILT_IN_NESTED_PTR_CREATED and BUILT_IN_NESTED_PTR_DELETED. * tree.cc (build_common_builtin_nodes): Build the BUILT_IN_NESTED_PTR_CREATED and BUILT_IN_NESTED_PTR_DELETED local builtins only for non-explicit. libgcc/ChangeLog: * config/aarch64/heap-trampoline.c: Rename __builtin_nested_func_ptr_created to __gcc_nested_func_ptr_created and __builtin_nested_func_ptr_deleted to __gcc_nested_func_ptr_deleted. * config/i386/heap-trampoline.c: Likewise. * libgcc2.h: Likewise. * libgcc-std.ver.in (GCC_7.0.0): Likewise and then move __gcc_nested_func_ptr_created and __gcc_nested_func_ptr_deleted from this symbol version to ... (GCC_14.0.0): ... this one. Signed-off-by: Iain Sandoe Co-authored-by: Jakub Jelinek Signed-off-by: Iain Sandoe --- gcc/builtins.cc | 5 ++++ gcc/builtins.def | 4 ++-- gcc/doc/invoke.texi | 4 ++-- gcc/tree-nested.cc | 4 ++-- gcc/tree.cc | 31 ++++++++++++++----------- libgcc/config/aarch64/heap-trampoline.c | 8 +++---- libgcc/config/i386/heap-trampoline.c | 8 +++---- libgcc/libgcc-std.ver.in | 5 ++-- libgcc/libgcc2.h | 4 ++-- 9 files changed, 41 insertions(+), 32 deletions(-) diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 09f2354f114..cebd88142b0 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -8416,6 +8416,11 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, case BUILT_IN_ADJUST_DESCRIPTOR: return expand_builtin_adjust_descriptor (exp); + case BUILT_IN_NESTED_PTR_CREATED: + case BUILT_IN_NESTED_PTR_DELETED: + break; /* At present, no expansion, just call the function. */ + + case BUILT_IN_FORK: case BUILT_IN_EXECL: case BUILT_IN_EXECV: diff --git a/gcc/builtins.def b/gcc/builtins.def index 4d97ca0eec9..fd040eb8d80 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -1084,8 +1084,8 @@ DEF_BUILTIN_STUB (BUILT_IN_ADJUST_TRAMPOLINE, "__builtin_adjust_trampoline") DEF_BUILTIN_STUB (BUILT_IN_INIT_DESCRIPTOR, "__builtin_init_descriptor") DEF_BUILTIN_STUB (BUILT_IN_ADJUST_DESCRIPTOR, "__builtin_adjust_descriptor") DEF_BUILTIN_STUB (BUILT_IN_NONLOCAL_GOTO, "__builtin_nonlocal_goto") -DEF_BUILTIN_STUB (BUILT_IN_NESTED_PTR_CREATED, "__builtin_nested_func_ptr_created") -DEF_BUILTIN_STUB (BUILT_IN_NESTED_PTR_DELETED, "__builtin_nested_func_ptr_deleted") +DEF_EXT_LIB_BUILTIN (BUILT_IN_NESTED_PTR_CREATED, "__gcc_nested_func_ptr_created", BT_FN_VOID_PTR_PTR_PTR, ATTR_NOTHROW_LIST) +DEF_EXT_LIB_BUILTIN (BUILT_IN_NESTED_PTR_DELETED, "__gcc_nested_func_ptr_deleted", BT_FN_VOID, ATTR_NOTHROW_LIST) /* Implementing __builtin_setjmp. */ DEF_BUILTIN_STUB (BUILT_IN_SETJMP_SETUP, "__builtin_setjmp_setup") diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 4d43dda9839..7a5ba9e7fb5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -19457,8 +19457,8 @@ for nested functions. By default, trampolines are generated on stack. However, certain platforms (such as the Apple M1) do not permit an executable stack. Compiling with @option{-ftrampoline-impl=heap} generate calls to -@code{__builtin_nested_func_ptr_created} and -@code{__builtin_nested_func_ptr_deleted} in order to allocate and +@code{__gcc_nested_func_ptr_created} and +@code{__gcc_nested_func_ptr_deleted} in order to allocate and deallocate trampoline space on the executable heap. These functions are implemented in libgcc, and will only be provided on specific targets: x86_64 Darwin, x86_64 and aarch64 Linux. @emph{PLEASE NOTE}: Heap diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc index 96718a66d01..9f275879595 100644 --- a/gcc/tree-nested.cc +++ b/gcc/tree-nested.cc @@ -3557,13 +3557,13 @@ finalize_nesting_tree_1 (struct nesting_info *root) root->frame_decl, field, NULL_TREE); arg3 = build_addr (x); - x = builtin_decl_implicit (BUILT_IN_NESTED_PTR_CREATED); + x = builtin_decl_explicit (BUILT_IN_NESTED_PTR_CREATED); stmt = gimple_build_call (x, 3, arg1, arg2, arg3); gimple_seq_add_stmt (&stmt_list, stmt); /* This call to delete the nested function trampoline is added to the cleanup list, and called when we exit the current scope. */ - x = builtin_decl_implicit (BUILT_IN_NESTED_PTR_DELETED); + x = builtin_decl_explicit (BUILT_IN_NESTED_PTR_DELETED); stmt = gimple_build_call (x, 0); gimple_seq_add_stmt (&cleanup_list, stmt); } diff --git a/gcc/tree.cc b/gcc/tree.cc index 8aee3ef18d8..4e65dd26165 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -9929,20 +9929,25 @@ build_common_builtin_nodes (void) tree ptr_ptr_type_node = build_pointer_type (ptr_type_node); - ftype = build_function_type_list (void_type_node, - ptr_type_node, // void *chain - ptr_type_node, // void *func - ptr_ptr_type_node, // void **dst - NULL_TREE); - local_define_builtin ("__builtin_nested_func_ptr_created", ftype, - BUILT_IN_NESTED_PTR_CREATED, - "__builtin_nested_func_ptr_created", ECF_NOTHROW); + if (!builtin_decl_explicit_p (BUILT_IN_NESTED_PTR_CREATED)) + { + ftype = build_function_type_list (void_type_node, + ptr_type_node, // void *chain + ptr_type_node, // void *func + ptr_ptr_type_node, // void **dst + NULL_TREE); + local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype, + BUILT_IN_NESTED_PTR_CREATED, + "__gcc_nested_func_ptr_created", ECF_NOTHROW); + } - ftype = build_function_type_list (void_type_node, - NULL_TREE); - local_define_builtin ("__builtin_nested_func_ptr_deleted", ftype, - BUILT_IN_NESTED_PTR_DELETED, - "__builtin_nested_func_ptr_deleted", ECF_NOTHROW); + if (!builtin_decl_explicit_p (BUILT_IN_NESTED_PTR_DELETED)) + { + ftype = build_function_type_list (void_type_node, NULL_TREE); + local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype, + BUILT_IN_NESTED_PTR_DELETED, + "__gcc_nested_func_ptr_deleted", ECF_NOTHROW); + } ftype = build_function_type_list (void_type_node, ptr_type_node, ptr_type_node, NULL_TREE); diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c index f22233987ca..2041fe6aa39 100644 --- a/libgcc/config/aarch64/heap-trampoline.c +++ b/libgcc/config/aarch64/heap-trampoline.c @@ -20,8 +20,8 @@ int get_trampolines_per_page (void); struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); void *allocate_trampoline_page (void); -void __builtin_nested_func_ptr_created (void *chain, void *func, void **dst); -void __builtin_nested_func_ptr_deleted (void); +void __gcc_nested_func_ptr_created (void *chain, void *func, void **dst); +void __gcc_nested_func_ptr_deleted (void); #if defined(__gnu_linux__) static const uint32_t aarch64_trampoline_insns[] = { @@ -108,7 +108,7 @@ allocate_tramp_ctrl (struct tramp_ctrl_data *parent) } void -__builtin_nested_func_ptr_created (void *chain, void *func, void **dst) +__gcc_nested_func_ptr_created (void *chain, void *func, void **dst) { if (tramp_ctrl_curr == NULL) { @@ -155,7 +155,7 @@ __builtin_nested_func_ptr_created (void *chain, void *func, void **dst) } void -__builtin_nested_func_ptr_deleted (void) +__gcc_nested_func_ptr_deleted (void) { if (tramp_ctrl_curr == NULL) abort (); diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i386/heap-trampoline.c index 4b9f4365868..726cf55277a 100644 --- a/libgcc/config/i386/heap-trampoline.c +++ b/libgcc/config/i386/heap-trampoline.c @@ -20,8 +20,8 @@ int get_trampolines_per_page (void); struct tramp_ctrl_data *allocate_tramp_ctrl (struct tramp_ctrl_data *parent); void *allocate_trampoline_page (void); -void __builtin_nested_func_ptr_created (void *chain, void *func, void **dst); -void __builtin_nested_func_ptr_deleted (void); +void __gcc_nested_func_ptr_created (void *chain, void *func, void **dst); +void __gcc_nested_func_ptr_deleted (void); static const uint8_t trampoline_insns[] = { /* movabs $,%r11 */ @@ -108,7 +108,7 @@ allocate_tramp_ctrl (struct tramp_ctrl_data *parent) } void -__builtin_nested_func_ptr_created (void *chain, void *func, void **dst) +__gcc_nested_func_ptr_created (void *chain, void *func, void **dst) { if (tramp_ctrl_curr == NULL) { @@ -155,7 +155,7 @@ __builtin_nested_func_ptr_created (void *chain, void *func, void **dst) } void -__builtin_nested_func_ptr_deleted (void) +__gcc_nested_func_ptr_deleted (void) { if (tramp_ctrl_curr == NULL) abort (); diff --git a/libgcc/libgcc-std.ver.in b/libgcc/libgcc-std.ver.in index a81c5a1142c..ac8f661a08e 100644 --- a/libgcc/libgcc-std.ver.in +++ b/libgcc/libgcc-std.ver.in @@ -1943,9 +1943,6 @@ GCC_4.8.0 { GCC_7.0.0 { __PFX__divmoddi4 __PFX__divmodti4 - - __builtin_nested_func_ptr_created - __builtin_nested_func_ptr_deleted } %inherit GCC_14.0.0 GCC_7.0.0 @@ -1960,4 +1957,6 @@ GCC_14.0.0 { __PFX__strub_enter __PFX__strub_update __PFX__strub_leave + __gcc_nested_func_ptr_created + __gcc_nested_func_ptr_deleted } diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h index 5050456eada..0b67fab637e 100644 --- a/libgcc/libgcc2.h +++ b/libgcc/libgcc2.h @@ -29,8 +29,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #pragma GCC visibility push(default) #endif -extern void __builtin_nested_func_ptr_created (void *, void *, void **); -extern void __builtin_nested_func_ptr_deleted (void); +extern void __gcc_nested_func_ptr_created (void *, void *, void **); +extern void __gcc_nested_func_ptr_deleted (void); extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t); extern void __clear_cache (void *, void *);