From owner-svn-src-head@freebsd.org Wed Nov 13 18:35:16 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 25A501B7EBA; Wed, 13 Nov 2019 18:35:16 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47CtZr0BDPz4Mjj; Wed, 13 Nov 2019 18:35:16 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id CFB211596F; Wed, 13 Nov 2019 18:35:15 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-qt1-f179.google.com with SMTP id t8so3679153qtc.6; Wed, 13 Nov 2019 10:35:15 -0800 (PST) X-Gm-Message-State: APjAAAVgkByIewFUy5lhvnNA8YXnN6Z9U5Uf42rlXHmcSyW5XTygMcf5 KlB59BXMcIR9lWXoWrhUQW+MeQOe9OVUXkh7eSA= X-Google-Smtp-Source: APXvYqy4U/UuiWLb2msaDZCWtJrPtDtyDrXd1i/u70ttB9U8dUThfsD17rTSmiEL6SecajWo40MlnTzu6ue13NGvHlg= X-Received: by 2002:ac8:41cc:: with SMTP id o12mr4117232qtm.310.1573670115099; Wed, 13 Nov 2019 10:35:15 -0800 (PST) MIME-Version: 1.0 References: <201911130300.xAD30WUE099996@repo.freebsd.org> <80479651-f60d-e352-1f40-f01939aff9fd@FreeBSD.org> In-Reply-To: From: Kyle Evans Date: Wed, 13 Nov 2019 12:35:03 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r354672 - head/lib/libc/secure To: Warner Losh Cc: Pedro Giffuni , src-committers , svn-src-all , svn-src-head Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Nov 2019 18:35:16 -0000 On Wed, Nov 13, 2019 at 12:23 PM Warner Losh wrote: > > > > On Wed, Nov 13, 2019 at 8:52 AM Pedro Giffuni wrote: >> >> Hi; >> >> On 12/11/2019 23:44, Warner Losh wrote: >> >> >> >> On Tue, Nov 12, 2019 at 9:20 PM Kyle Evans wrote: >>> >>> >>> >>> On Tue, Nov 12, 2019, 22:04 Pedro Giffuni wrote: >>>> >>>> >>>> On 12/11/2019 22:00, Kyle Evans wrote: >>>> >>>> Author: kevans >>>> Date: Wed Nov 13 03:00:32 2019 >>>> New Revision: 354672 >>>> URL: https://svnweb.freebsd.org/changeset/base/354672 >>>> >>>> Log: >>>> ssp: rework the logic to use priority=3D200 on clang builds >>>> >>>> The preproc logic was added at the last minute to appease GCC 4.2, a= nd >>>> kevans@ did clearly not go back and double-check that the logic work= ed out >>>> for clang builds to use the new variant. >>>> >>>> It turns out that clang defines __GNUC__ =3D=3D 4. Flip it around an= d check >>>> __clang__ as well, leaving a note to remove it later. >>>> >>>> >>>> clang reports itself as GCC 4.2, the priority argument was introduced = in GCC 4.3. >>>> >>>> Reported by: cem >>>> >>>> Modified: >>>> head/lib/libc/secure/stack_protector.c >>>> >>>> Modified: head/lib/libc/secure/stack_protector.c >>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D >>>> --- head/lib/libc/secure/stack_protector.c Wed Nov 13 02:22:00 2019 (r= 354671) >>>> +++ head/lib/libc/secure/stack_protector.c Wed Nov 13 03:00:32 2019 (r= 354672) >>>> @@ -47,13 +47,15 @@ __FBSDID("$FreeBSD$"); >>>> * they're either not usually statically linked or they simply don't = do things >>>> * in constructors that would be adversely affected by their position= ing with >>>> * respect to this initialization. >>>> + * >>>> + * This conditional should be removed when GCC 4.2 is removed. >>>> */ >>>> -#if defined(__GNUC__) && __GNUC__ <=3D 4 >>>> -#define _GUARD_SETUP_CTOR_ATTR \ >>>> - __attribute__((__constructor__, __used__)); >>>> -#else >>>> +#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 4) >>>> #define _GUARD_SETUP_CTOR_ATTR \ >>>> __attribute__((__constructor__ (200), __used__)); >>>> +#else >>>> +#define _GUARD_SETUP_CTOR_ATTR \ >>>> + __attribute__((__constructor__, __used__)); >>>> #endif >>>> >>>> extern int __sysctl(const int *name, u_int namelen, void *oldp, >>>> >>>> Please fix properly. Assuming clang always supported it, something lik= e: >>>> >>>> #if __GNUC_PREREQ__(4, 3) || __has_attribute(__constructor__) >>>> >>>> should work >>>> >>>> Cheers, >>> >>> >>> I considered something of this sort, but searching for information on t= he priority argument in the first place was annoying enough that I had too = much search-fatigue to figure out when GCC actually corrected this, thus as= suming that GCC5 (which seemed to be an all-around good release if memory s= erves) and later (since I confirmed GCC6) was sufficient. >>> >>> I'll fix it in the morning (~8 hours) if I receive no further objection= s to address. >> >> >> Soon enough this can be removed entirely... Getting it pedantically righ= t in the mean time has little value. We don't really support gcc5 at the mo= ment. gcc6 and later have good support, but anything new between 4.3 and 6.= 0 likely is poorly tagged... >> >> >> Well, tracking attributes on GCC versions is not easy but I did spend a = good amount of time getting the attributes right on cdefs.h and while I los= t the battle to get support for older GCC versions deprecated, getting the = attributes properly defined in the GCC 4.2 vs clang vicinity is particularl= y important. > > Not really. We only support 4.2.1 + freebsd hacks and then 6..= Further refining stuff is useless. Refining 4.3 vs 6.0 buys us nothing and= distracts our limited resources getting correct something we are definitel= y removing from the tree in a couple of months. Going back and refining it = gives us no practical benefit. While I don't object to the change, per se, = I don't view it as required given our future plans. > > We should scrub cdefs.h. We've needed to for a while... >> >> I particularly dislike the idea of leaving notes of stuff that can be re= moved when an existing compiler is gone. In this case, we can fix this with= out adding more lines of code, and that also helps in case the code is MFCd= . >> >> Now ... if you want to be pedantic: this code doesn't handle the case fo= r non-GCC based compilers, and it probably could be done more generic and c= lean in cdefs.h where it can be reused. But I am not asking for that ;). > > I guess I disagree here. The current code is adequate and can be MFC'd. = It's not as perfect as it could be, but it's not wrong enough to fuss with.= ... If Kyle wants to, great, I'm not standing in the way, but I want to sen= d the clear message that we don't need to get gcc 4.2 era stuff perfect bec= ause such distinctions are currently muddy at best. We won't work with a st= ock 4.2 compiler, and we already use 4.2 as a proxy for our current gcc com= piler, not a perfect thing today anyway. Spending time on it doesn't give g= ood value for the time spent on it, especially if we spend that time on oth= er things that give better ROI. > I went ahead and fixed it because it was already agreed that __has_attribute is a better test for clang than defined(__clang__), so I might as well get the version correct since I'm already touching the line and writing a commit message for it. I do still think it should unifdef'd when GCC 4.2 goes away, so the note still reflects my wishes. Given that this is a libc/*.c file, we can handle any of the edge cases for non-clang/newer GCC compilers as they crop up, if they crop up. We don't seem to put much effort (that I've noticed) into making sure that libc can be compiled with other compilers than those noted, but we can always make exception if someone comes forward with a need for it.