Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2759085pxb; Sun, 28 Feb 2021 12:16:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkFVuZNOQsDsMGgz7HaHCv7PTpWfHtf72ZLzwjaUrWYgFgLYkSBDYXk7EAxu2raH7xqe+7 X-Received: by 2002:a17:906:cf90:: with SMTP id um16mr13090102ejb.389.1614543405300; Sun, 28 Feb 2021 12:16:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614543405; cv=none; d=google.com; s=arc-20160816; b=Y/D7GpMH7AmRWIlxAxpNPTbv+/3FybqQwbQZcfOTcJykSwpATmNpFkiHJXfIYqLqd8 Le3dU45L/4bq20JDUM2qz+pzeTVI63daKgzwg/6PkCb3td4+xzg0zDuGbKX+BJIwxs2I ABOWQeU8a0BsK21fUTZGJ5CB7sG5aWw7elGGrRON7nwQrFDkCE1b1sje9p8BSNBQEfFv IqpbGaMi+pFCcMj/5rudSag8MkMDqlHSyVdRzCYIX3qLZ64uhTVeIYCpDEq1djAdFZAp ELzgXixWjwK67glwVbbyWVftRbanGNtTEIK8XvuIKCGq7mPMctAVbf9+ypdHGGK+qOq5 w9hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=S5KfXXaQvt6j7WDZcPct+Ak/9/AyhidEr7ALQ5SkfaQ=; b=PN+jUN2dYYuwiHQy8NxJhPXZ6h+/jc1NkFX2+OBmHv0uyEKIzTS62tiBtscGZpnVUR BoGjQLnAB8XCygG5sP9J0gISzYJhb3w/ZcDmP8jmc+l1fVmJIsYhUf60Eg/j1NDXclb/ qZ/Y3O3dnbio0SD7VYZl6cwebDwTk1vATvI8jr/ekbixZDscD/NYOgII3ldB0Mc0ndzx z3fbGHWqcS9kyYflRw19v+5oF8rIuShABgSzBv+iluIOweTdt1+MnFkncNnGG09z7Z1Z mqWKLpdccuOKwt7PYeqEHtd13RlHh7LRPkrf2xF7kAAXcYV1YoGbd3Qqc84T7+YKb6f0 DG7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hDdtIyyX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si10568746ejs.165.2021.02.28.12.16.23; Sun, 28 Feb 2021 12:16:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hDdtIyyX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbhB1Tfb (ORCPT + 99 others); Sun, 28 Feb 2021 14:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbhB1Tfa (ORCPT ); Sun, 28 Feb 2021 14:35:30 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 476BDC06174A; Sun, 28 Feb 2021 11:34:50 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id mm21so23962917ejb.12; Sun, 28 Feb 2021 11:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=S5KfXXaQvt6j7WDZcPct+Ak/9/AyhidEr7ALQ5SkfaQ=; b=hDdtIyyX/3NqIWoSpmfpnm0A3ibi9UTwnDydNYf0r+wE8f5cESO5SdHdVIZ3gWAYQq bIAk2d4CUkqPsHAtb9c6mi22POyick7yfTMLyLd9mYAh1wko9B2F2i814+NGYchqxp3X wedSrWIA2bt2Emvpeu0kfsDSWBaQLuM/7DFCorLKqa2ymm9tVepMtTIAibWkL9ZmdcZQ t3hVboqF+q7y4b9K3FtS/gMwD53abboSbrplKY6TmnK8fU0stFLDqC6a5uExZSesm7Wj wzyixWT0kXZ+hArzyvQQ2u0zxGbwwOQw57u3HQYWPjXHWTXAdTJyj3Dmg4QSIb/03bHp EnuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=S5KfXXaQvt6j7WDZcPct+Ak/9/AyhidEr7ALQ5SkfaQ=; b=Cvo95Qfb4k2s2ZWqJJhZKvzZLNm18bG5dArZjqhAq6L4u8aIjnZEQnY7gGWR7Xcho6 BnQPJAqSqJUKWEHFXMTYt822fPWOUqX08yM6+6mKxg6cWVIoPj1HvWdy6DDJ1DLajZ+/ A7x0kXhmUpm2rsfN+xs47UuHRo8E4NpDAiuo8ppHMtgUD3Ge8EkM0TYVJNDvcIEAZRGx yU6TpAgMNsTE/PdDC8m/SRE5ZTE0breYfvZnSUvFY5tu53jR4tZthKMfUkd1nJ+LBtq8 SK5cKLQE04Jbswi/r8MkbjYzBLl/NmGcEfPlZBrs6PAXiV2ITbZCiYaBdUPeZBcWSul5 dyVA== X-Gm-Message-State: AOAM531RsmHSTGIxC3Hlz8PsNgH7MqqKxWjgmUJa07CitrKWsIgMyFYa qzI4q1M3Wdood+bp3lFZwA/4mxXSiliK X-Received: by 2002:a17:906:7d7:: with SMTP id m23mr12849912ejc.205.1614540888946; Sun, 28 Feb 2021 11:34:48 -0800 (PST) Received: from localhost.localdomain ([46.53.249.223]) by smtp.gmail.com with ESMTPSA id c17sm10445730edw.32.2021.02.28.11.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 11:34:48 -0800 (PST) Date: Sun, 28 Feb 2021 22:34:46 +0300 From: Alexey Dobriyan To: Linus Torvalds Cc: Luc Van Oostenryck , Linux Kernel Mailing List , Andrew Morton , Sparse Mailing-list Subject: Re: [PATCH 00/11] pragma once: treewide conversion Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 28, 2021 at 09:46:17AM -0800, Linus Torvalds wrote: > On Sun, Feb 28, 2021 at 8:57 AM Alexey Dobriyan wrote: > > > > This is bulk deletion of preprocessor include guards and conversion > > to #pragma once directive. > > So as mentioned earlier, I'm not 100% convinced about the advantage of > #pragma once. > > But I decided to actually test it, and it turns out that it causes > problems for at least sparse. Oh no. > Sparse *does* support pragma once, but it does it purely based on > pathname equality. Doing what gcc or clang does seems like a smart thing to do. > So a simple test-program like this: > > File 'pragma.h': > > #pragma once > #include "header.h" > > works fine. But this doesn't work at all: > > #pragma once > #include "./header.h" > > because it causes the filename to be different every time, and you > eventually end up with trying to open "././....../pragma.h" and it > causes ENAMETOOLONG. > > So at least sparse isn't ready for this. > > I guess sparse could always simplify the name, but that's non-trivial. > > And honestly, using st_dev/st_ino is problematic too, since > > (a) they can easily be re-used for generated files > > (b) you'd have to actually open/fstat the filename to use it, which > obviates one of the optimizations fstat is more or less necessary anyway to allocate just enough memory for 1 read. fstat is not a problem, read is (and subsequent parsing). > Trying the same on gcc, you don't get that endless "add "./" behavior" > that sparse did, but a quick test shows that it actually opens the > file and reads it three times: once for "pramga.h", once for > "./pragma.h" and a third time for "pragma.h". It only seems to > _expand_ it once, though. > > I have no idea what gcc does. Maybe it does some "different name, so > let's open and read it, and then does st_dev/st_ino again". But if so, > why the _third_ time? Is it some guard against "st_ino might have been > re-used, so I'll open the original name and re-verify"? > > End result: #pragma is fundamentally less reliable than the > traditional #ifdef guard. The #ifdef guard works fine even if you > re-read the file for whatever reason, while #pragma relies on some > kind of magical behavior. > > I'm adding Luc in case he has any ideas of what the magical behavior might be. gcc does open "/" + "whatever between quotes" fstat so that "1.h" and "./1.h" differ https://github.com/gcc-mirror/gcc/blob/master/libcpp/files.c#L377 clang does better: "./" + "whatever between quotes" open fstat normalise pathname via readlink /proc/*/fd I think it is quite hard to break something with double inclusion without trying to actually break stuff. Macros has to be token for token identical or compiler warn. Types definition too. Function prototypes and so on. This is how I found half of the exception list. The "no leading ./ in includes is trivially enforced with checkpatch.pl or even grep! And it will optimise the build now that gcc behaviour has been uncovered. Include guards aren't without problems. We have at least 1 identical include guard in the tree for two completely unrelated headers (allmodconfig of some fringe arch found it) Nobody complains because only defconfigs are run apparently. Developer can typo it disabling double inclusion. #ifndef FOO_H #define FOO_h #endif I've seen a reference to a static checker checking for such stuff so this problem exists. Invisibly broken inlcude guards (see qla2xxx patch in the series).