From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by sourceware.org (Postfix) with ESMTPS id 15225385AE6C for ; Wed, 10 Aug 2022 17:24:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15225385AE6C Received: by mail-vk1-xa35.google.com with SMTP id w129so7753530vkg.10 for ; Wed, 10 Aug 2022 10:24:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=hQ+ZQzi9ippM3rz5BMu5lZbLFWKugYDK8/UTKoF4pto=; b=z2MDeiee9WxGymwoScrr5mZ2hfm8o3CTSADjRdSVF1ZD8Le98sm4qIcR6H+7yixWw5 KMhnRwZaMwdOWttZo18LJCSwwnjK0/qBrYB7eXrTuXWeY9vsWHbCMzPpGhzt+/UQojbt uCMUOuffwe8vGMNMaQOzyz00AzV6ht0JCJN3xVCb0YjNJbakzxWsxHxuAg//8/g5GCDp GXsFTHYDCI6BtrFk5F6feNM9WHemGkMTkYNwRJP2nDO3IlYu4R5B5tTDTtszGuO4B4Ps dcBAt27v4pS8/+MPiVFk2C8LI934WyYp43uNsQnfAQ7VIA8Ropg7LsFTAX1TK4lCrplU Lk+Q== X-Gm-Message-State: ACgBeo0rr6tRfPQkiJ2GprESy4GTVt2+NY9JtnH5hY/ki2tgeC46QOQT MBqvqqcm/bgsCpqKkS+ukO4Mc2DBEeezoQ== X-Google-Smtp-Source: AA6agR7O29tKiDsxf8KFVtNSv1k21qUP8MM1vQfvYARJS+t0vpFWxo6CNmN/umGUTC0aA/2mmUgTsA== X-Received: by 2002:a1f:1c49:0:b0:37c:fe5b:5edb with SMTP id c70-20020a1f1c49000000b0037cfe5b5edbmr960604vkc.17.1660152297219; Wed, 10 Aug 2022 10:24:57 -0700 (PDT) Received: from mandiga.. ([2804:431:c7ca:930b:405a:6d95:e89e:4020]) by smtp.gmail.com with ESMTPSA id i31-20020a0561023d1f00b00388859a325asm155722vsv.30.2022.08.10.10.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 10:24:56 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v2 5/5] linux: Fix sys/mount.h usage with kernel headers Date: Wed, 10 Aug 2022 14:24:47 -0300 Message-Id: <20220810172447.1502169-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220810172447.1502169-1-adhemerval.zanella@linaro.org> References: <20220810172447.1502169-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2022 17:25:00 -0000 Now that kernel exports linux/mount.h and includes it on linux/fs.h, its definitions might clash with glibc exports sys/mount.h. To avoid the need to rearrange the Linux header to be always after glibc one, the glibc sys/mount.h is changed to: 1. Undefine the macros also used as enum constants. This covers prior inclusion of (for instance MS_RDONLY). 2. Include based on the usual __has_include check (needs to use __has_include ("linux/mount.h") to paper over GCC bugs. 3. Define enum fsconfig_command only if FSOPEN_CLOEXEC is not defined. (FSOPEN_CLOEXEC should be a very close proxy.) 4. Define struct mount_attr if MOUNT_ATTR_SIZE_VER0 is not defined. (Added in the same commit on the Linux side.) This patch also adds some tests to check if including linux/fs.h and linux/mount.h after and before sys/mount.h does work. Checked on x86_64-linux-gnu. --- sysdeps/unix/sysv/linux/Makefile | 8 +++ sysdeps/unix/sysv/linux/sys/mount.h | 71 +++++++++++++++++--- sysdeps/unix/sysv/linux/tst-mount-compile.py | 66 ++++++++++++++++++ 3 files changed, 137 insertions(+), 8 deletions(-) create mode 100755 sysdeps/unix/sysv/linux/tst-mount-compile.py diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 3f31c19e4a..60e4cb1521 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -265,6 +265,14 @@ $(objpfx)tst-mount-consts.out: ../sysdeps/unix/sysv/linux/tst-mount-consts.py < /dev/null > $@ 2>&1; $(evaluate-test) $(objpfx)tst-mount-consts.out: $(sysdeps-linux-python-deps) +tests-special += $(objpfx)tst-mount-compile.out +$(objpfx)tst-mount-compile.out: ../sysdeps/unix/sysv/linux/tst-mount-compile.py + $(sysdeps-linux-python) \ + ../sysdeps/unix/sysv/linux/tst-mount-compile.py \ + $(sysdeps-linux-python-cc) \ + < /dev/null > $@ 2>&1; $(evaluate-test) +$(objpfx)tst-mount-compile.out: $(sysdeps-linux-python-deps) + tst-rseq-disable-ENV = GLIBC_TUNABLES=glibc.pthread.rseq=0 endif # $(subdir) == misc diff --git a/sysdeps/unix/sysv/linux/sys/mount.h b/sysdeps/unix/sysv/linux/sys/mount.h index df6b0dbb42..2e3fd6a7fe 100644 --- a/sysdeps/unix/sysv/linux/sys/mount.h +++ b/sysdeps/unix/sysv/linux/sys/mount.h @@ -27,6 +27,13 @@ #include #include +#ifdef __has_include +# if __has_include ("linux/mount.h") +# include "linux/mount.h" +# endif +#endif + + #define BLOCK_SIZE_BITS 10 #define BLOCK_SIZE (1<. + +import argparse +import sys + +import glibcextract + + +def main(): + """The main entry point.""" + parser = argparse.ArgumentParser( + description='Check if glibc provided sys/mount.h can be ' + ' used along related kernel headers.') + parser.add_argument('--cc', metavar='CC', + help='C compiler (including options) to use') + args = parser.parse_args() + + if glibcextract.compile_c_snippet( + '#include ', + args.cc).returncode != 0: + sys.exit (77) + + def check(testname, snippet): + # Add -Werror to catch macro redefinitions and _ISOMAC to avoid + # internal glibc definitions. + r = glibcextract.compile_c_snippet(snippet, args.cc, + '-Werror -D_ISOMAC') + if r.returncode != 0: + print('error: test {}:\n{}'.format(testname, r.output.decode())) + return r.returncode + + status = max( + check("sys/mount.h + linux/mount.h", + "#include \n" + "#include "), + check("sys/mount.h + linux/fs.h", + "#include \n" + "#include "), + check("linux/mount.h + sys/mount.h", + "#include \n" + "#include "), + check("linux/fs.h + sys/mount.h", + "#include \n" + "#include ")) + sys.exit(status) + +if __name__ == '__main__': + main() -- 2.34.1