From patchwork Thu Jun 28 08:43:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 936007 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-480652-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rasmusvillemoes.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hJetgmKd"; dkim=pass (1024-bit key; unprotected) header.d=rasmusvillemoes.dk header.i=@rasmusvillemoes.dk header.b="Fp0ErvvQ"; dkim-atps=neutral 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 41GYHD6Z7bz9s1B for ; Thu, 28 Jun 2018 18:44:24 +1000 (AEST) 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:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=efIYb1P80QgzXc/O+12Tt2eTMt3ECSSWCnbC5FG8+9uKcA49Hib+O vQ785z5fFrJu+f7/BBDKpPRMHFBOgrrBZg2Coc5a0gUjZrzEmQhRyTWYW+uomtWz FpxwIOyN9wIs26y8bWTWO4JMcyLF3YQWkzj/TgQuNHyjbGyZGpw2KI= 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:cc:subject:date:message-id:in-reply-to:references; s= default; bh=ibBHoQvI9R+Oii1Og1I3Ubi/4D4=; b=hJetgmKdkPIb7foWKHpp 1cbryx937POi3b5mDC+4DnaZbnLYYrDVB1/PgzvYQsQSJOPb8YwiY8fbw/L3XucS d9J9Vjvvi3dVLq95I38lj2EkQXHWbwUSD18jaBjUjFLtoQy34QWxXLF6NlPuOOWT ZgvZ/UQj/+Zx1ls/NwJ580I= Received: (qmail 42773 invoked by alias); 28 Jun 2018 08:43:44 -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 42694 invoked by uid 89); 28 Jun 2018 08:43:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=_ctors X-HELO: mail-wr0-f170.google.com Received: from mail-wr0-f170.google.com (HELO mail-wr0-f170.google.com) (209.85.128.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Jun 2018 08:43:42 +0000 Received: by mail-wr0-f170.google.com with SMTP id u7-v6so4599722wrn.12 for ; Thu, 28 Jun 2018 01:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j2Pq9Rqd4svZXGog7UhaYmO/95/9r1ZdNhCWvvE+k2c=; b=Fp0ErvvQaWFRrUyDggCBPW9JQ2TqmvOhpjJY6yeZz7qZJdAaqs8WON1E9BrEyASosa K3g/LrlzqLQFkQu6+LbBuzpG9T77NaEnQIXewR8lOSiMxm7OCwQXd/CDvqQkHdHKxQJ5 hJbq9Nlosuc//QG8cPm2uX4BKnnXyYQ9x5Xzk= Received: from prevas-ravi.vestasvisitor.net ([193.47.71.171]) by smtp.gmail.com with ESMTPSA id 63-v6sm9095323wmv.48.2018.06.28.01.43.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 01:43:39 -0700 (PDT) From: Rasmus Villemoes To: gcc-patches@gcc.gnu.org Cc: Olivier Hainque , Rasmus Villemoes Subject: [PATCH v2 3/4] vxworks: enable use of .init_array/.fini_array for cdtors Date: Thu, 28 Jun 2018 10:43:28 +0200 Message-Id: <20180628084329.22754-4-rv@rasmusvillemoes.dk> In-Reply-To: <20180628084329.22754-1-rv@rasmusvillemoes.dk> References: <11927417-16E9-4FE8-9A14-F27D29EB1212@adacore.com> <20180628084329.22754-1-rv@rasmusvillemoes.dk> The target OS actually runs all function pointers found in the _ctors array when the module is loaded. So it is not that hard to make use of the "modern" .init_array/.fini_array mechanism - it mostly just requires a linker script adding the _ctors and _dtors symbols and terminating LONG(0) entries. Assume that if the user passed --enable-initfini-array when building gcc, the rest of the toolchain (including the link spec and linker script) is set up appropriately. Note that configuring with --enable-initfini-array may prevent the -mrtp mode from working, due to the (unconditional) use of .init_array.* sections instead of .ctors.* - however, that is the case regardless of this patch. 2018-06-04 Rasmus Villemoes gcc/ config/vxworks.c: Set targetm.have_ctors_dtors if HAVE_INITFINI_ARRAY_SUPPORT. config/vxworks.h: Set SUPPORTS_INIT_PRIORITY if HAVE_INITFINI_ARRAY_SUPPORT. --- gcc/config/vxworks.c | 7 +++++-- gcc/config/vxworks.h | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/config/vxworks.c b/gcc/config/vxworks.c index 061f02057c2..953f74f71af 100644 --- a/gcc/config/vxworks.c +++ b/gcc/config/vxworks.c @@ -143,8 +143,11 @@ vxworks_override_options (void) targetm.emutls.debug_form_tls_address = true; } - /* We can use .ctors/.dtors sections only in RTP mode. */ - targetm.have_ctors_dtors = TARGET_VXWORKS_RTP; + /* We can use .ctors/.dtors sections only in RTP mode. But, if the + compiler was built with --enable-initfini-array, assume the + toolchain implements the proper glue to make .init_array and + .fini_array work. */ + targetm.have_ctors_dtors = TARGET_VXWORKS_RTP || HAVE_INITFINI_ARRAY_SUPPORT; /* PIC is only supported for RTPs. */ if (flag_pic && !TARGET_VXWORKS_RTP) diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h index 08d2c9d76d6..4c2d98381f6 100644 --- a/gcc/config/vxworks.h +++ b/gcc/config/vxworks.h @@ -142,9 +142,13 @@ along with GCC; see the file COPYING3. If not see #define VXWORKS_OVERRIDE_OPTIONS vxworks_override_options () extern void vxworks_override_options (void); -/* Only RTPs support prioritized constructors and destructors: - the implementation relies on numbered .ctors* sections. */ -#define SUPPORTS_INIT_PRIORITY TARGET_VXWORKS_RTP +/* RTPs support prioritized constructors and destructors: the + implementation relies on numbered .ctors* sections. If the compiler + was built with --enable-initfini-array, we assume the user uses a + linker script that sorts and merges the .init_array.* sections + appropriately. */ +#define SUPPORTS_INIT_PRIORITY \ + (TARGET_VXWORKS_RTP || HAVE_INITFINI_ARRAY_SUPPORT) /* VxWorks requires special handling of constructors and destructors. All VxWorks configurations must use these functions. */