From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 7D9CD385780A for ; Fri, 29 Oct 2021 07:08:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7D9CD385780A Received: by mail-ed1-x532.google.com with SMTP id j21so12395237edt.11 for ; Fri, 29 Oct 2021 00:08:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DWP60vhfCLdr2z2QHMCp2ev8RdN94u6hu5MKB5Xaghc=; b=v1b1dEmGudMbWARzE3dh1IaI/nta3e9LtXHLrLFpA41PVhITXcdY6rEYJD+l3t4VC4 N3PuK9vtL3fBaljrDfD0MapKRyyNtKm7a4aSIicuMOQXNEA2qjYYEk+8TBMZ3j4IxGbp rMOx6E7IevsXxCRLqsOO655sd0Pz6xBrUcUO/wYdJ6eZKTkKiLddcaRxAwEUu6CCt3AX Y8v9XLm36T69Gt+Dt9hBdT1Y4FPibslK5Rznk+VmfSzcWbCgdARz3WBlboBECVuXwvUS P603a6alPt912TNSJL/aHawjH6u4SIHXzOkXntzi69aLus3n5cREQwaiqxhf+1yYyMUN f13Q== X-Gm-Message-State: AOAM532Oz8u+gz9kwzFwhsBUN/6a0NYEmFu5CqsWalGO/QRDdhJcK86M 88hdcs6l3HQ6RbYqkZSjGYqCinho70BBnioChfc= X-Google-Smtp-Source: ABdhPJwyHC5PhRSaHiMljNCJj+ju29zwzp4OXOFNvM2FbJHQXo6kaZbZQ0D9/smm+cTITX2pJWlm8h+psPos2QdQ4fs= X-Received: by 2002:a17:906:c301:: with SMTP id s1mr11207158ejz.56.1635491321535; Fri, 29 Oct 2021 00:08:41 -0700 (PDT) MIME-Version: 1.0 References: <96e842e0-4dcb-5ec2-5714-ab38565f063f@rasmusvillemoes.dk> In-Reply-To: <96e842e0-4dcb-5ec2-5714-ab38565f063f@rasmusvillemoes.dk> From: Richard Biener Date: Fri, 29 Oct 2021 09:08:30 +0200 Message-ID: Subject: Re: ctor/dtor priorities ignored when function is pre-declared To: Rasmus Villemoes Cc: "gcc@gcc.gnu.org" , Olivier Hainque Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Oct 2021 07:08:50 -0000 On Thu, Oct 28, 2021 at 1:26 PM Rasmus Villemoes wrote: > > Hi > > I was wondering why the vx_crtbegin.o file had a .init_array section and > not a .init_array.00101, when the function is defined with > __attribute__((constructor (101))) (see libgcc/config/vxcrtstuff.c). > > After a lot of digging, including making sure that EH_CTOR_ATTRIBUTE > actually gets defined as I expect and adding -frecord-gcc-switches to > the build to see if any of those made ctor priorities ignored, it turns > out that the problem is the declarations preceding the definitions. This > can easily be reproduced by > > #define ac(prio) __attribute__((constructor(prio))) > > unsigned x = 987; > > static void f101(void); > void f102(void); > > static void ac(101) f101(void) { x += 101; } > void ac(102) f102(void) { x *= 102; } > > static void ac(103) f103(void) { x -= 103; } > void ac(104) f104(void) { x /= 104; } > > This results in a .init_array section with two pointers, plus the > expected .init_array.00103 and .init_array.00104 with one each. > > This is rather unexpected, especially since the attribute is not > entirely ignored, just the priority part. Probably a bug in decl merging, failing to copy DECL_HAS_INIT_PRIORITY_P and altering the on-the-side init priority mapping (decl_{init,fini}_priority_insert). I suggest to file a bugreport or try to fix it yourself (gcc/c/c-decl.c:merge_decls) Richard. > > Rasmus