From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 2215D3858C2C for ; Tue, 31 Jan 2023 09:10:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2215D3858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x234.google.com with SMTP id bf19so807861ljb.6 for ; Tue, 31 Jan 2023 01:10:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fTcYj+3llvgq646SAG6yP3MwfF2Zvn9uliXuI78QynI=; b=g2lxBvh5R/0dr5qa+FS3AFLSrlfVmzshkmZsGeApK4zoVBjtq+BE6y8pSHZEvxBIzE 7Zw5oSIu0eNJyYwmfBqUU5VZwzz9f9wr+4/JE3MkMk+ANRE3fGPshEA6vPkYqS2assCt ArTpsMbGvxBM+cmN38L3APZrWR9he1bthYJjyILXHgl8tZsoQ6gvRmLbDqqhBno5Nrwo Qdg2mpKNSJ4pG2nl6thTMXhGLyQv+6PrYkA1Brmz5DIMAfxt4HBtGhNGcw6X3dNMcfqa ijOJqOzcHJxNNSYcnwYMwGZUKxfPEo3SCl6FCgzFP29RtrDqlPWxNUIxJLyx4xoEwTOx MaHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fTcYj+3llvgq646SAG6yP3MwfF2Zvn9uliXuI78QynI=; b=22Gskdk98CMhLEbYoTfuzxzanXUPiW4MKvas5qeu43Ig1KmyOeG5eFBVXcDKlIgfAc kbG2oh58qrq6JNYvJD1wPkQ60VCFCvlxE9N/efy1rgSZq6NHRRiNUv/vVNsEHiS/50Rt /wkbPiYshGLYQiooLUHUmmJ7MpxZECbw9wZ+Dqzn7itPYkPaZGehxq7nCxcxi1tXNpdb vQKUd/OIiMWiLb4y7VItWCtVnDiPdLTCA3Olwjp+Hrh7oXeP/mOpHbqMf1QOrlabcKay Il+9NZ3Fg/XthRUJZR/ZoNmu/zHc/h7O28Z3azuqP62TABJ2rfLYzFj0Txaeu/IHntpV Bd8w== X-Gm-Message-State: AO0yUKVjrQ7BSovedAmPfh+goFTg0wLdUtj/pk5moaVZEl3tTCqvnhzp ODpjKxH1x4+lZBcM0NwIww5ZuL1d+ySGhnnrKtY= X-Google-Smtp-Source: AK7set8Aj7MT2MfOXBZk46qBwsbzgbWr6ssqtUSqllZrAthcuC5J6er2XDRIEKaotCgs+nE0TwMh/uGAtu+abdWAAnE= X-Received: by 2002:a2e:3a0f:0:b0:28e:1ca4:b62 with SMTP id h15-20020a2e3a0f000000b0028e1ca40b62mr1789468lja.97.1675156203235; Tue, 31 Jan 2023 01:10:03 -0800 (PST) MIME-Version: 1.0 References: <20230131033707.2597685-1-ppalka@redhat.com> In-Reply-To: From: Richard Biener Date: Tue, 31 Jan 2023 10:09:51 +0100 Message-ID: Subject: Re: [PATCH] don't declare header-defined functions both static and inline To: Jakub Jelinek Cc: Patrick Palka , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Jan 31, 2023 at 9:43 AM Jakub Jelinek wrote: > > On Tue, Jan 31, 2023 at 08:05:15AM +0100, Richard Biener via Gcc-patches wrote: > > On Tue, Jan 31, 2023 at 4:39 AM Patrick Palka via Gcc-patches > > wrote: > > > > > > Many functions defined in our headers are declared 'static inline' which > > > is a vestige from when GCC's implementation language was C. But in C++ > > > the inline keyword is more than just a compiler hint, and is sufficient > > > to give the function the intended semantics. In fact declaring a > > > (namespace-scope) function both static and inline is a pessimization > > > since static effectively disables the intended definition merging > > > behavior that inline provides, and is also a source of (harmless) ODR > > > violations when a static inline function gets called from a non-static > > > inline one (such as tree_operand_length being called from > > > tree_operand_check). > > > > > > This patch mechanically fixes the vast majority of occurrences of this > > > anti-pattern throughout the compiler's headers via the command line > > > > > > echo gcc/*.h gcc/*/*.h | xargs sed -i 's/^static inline/inline/g' > > > > > > Besides fixing the ODR violations, this speeds up stage1 cc1plus by > > > about 2% and reduces the size of its text segment by 1.5MB. > > > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, would this be OK to > > > push now or wait for stage1? > > > > Speeding up and reducing the size of cc1plus improves on continued > > regression in this area. So I'd vote +1 to do this now, let's see what others > > think. > > I lean towards +1 too, but > 1) we should make sure we don't do that for installed headers with the > exception of headers meant for GCC plugins; in quick skimming I don't > see ginclude/ headers among the changed ones, but perhaps doing all > languages make install, then applying the patch, make and make install > again into another tree and compare all the headers in those tree > with the exception of paths with /plugin/include/ in it? > 2) we should make sure we don't introduce ODR violations through this, if > say 2 headers would define different static inline functions with the > same name (or even one static inline and another without that). > Don't know what would be best to catch that, get from the patch > list of changed functions and then search for it in readelf -wi output > using some script, or would LTO bootstrap detect that, or libabigail? > What I'm worried about is 2 different headers defining the same > function perhaps with different arguments/return values or content and > that we happen to never include the two headers in the same TU Ah, didn't think of that - yes, I suppose it might be that LTO bootstrap would warn about those? > 3) we have also gcc/ada/gcc-interface/*.h with > ada.h:#define INLINE static inline > gigi.h:static inline unsigned HOST_WIDE_INT > gigi.h:static inline bool > gigi.h:static inline bool > gigi.h:static inline bool > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > gigi.h:static inline tree > I think we can defer that to Ada maintaners but we should tell them > about it > 4) there are some static inline also in > gcc/config/*/*.h (and some in gcc/common/*/*.h - though in that case > it is solely in installed header that shouldn't be changed) > avr/avr-protos.h:static inline unsigned > pru/pru-protos.h:static inline bool > rs6000/rs6000-internal.h:static inline bool > rs6000/rs6000-protos.h:static inline bool > s390/s390-builtins.h:static inline unsigned int > s390/s390-builtins.h:static inline unsigned int > s390/vecintrin.h:static inline int > The last one is an installed header, so I think we shouldn't touch > it, the rest should be considered. The above probably asks to split the patch up and separate gcc/*/*.h into individual patches? Richard. > > Jakub >