From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by sourceware.org (Postfix) with ESMTPS id 3ECF0385356D for ; Wed, 24 Aug 2022 13:07:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3ECF0385356D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-vs1-xe2f.google.com with SMTP id d126so17453015vsd.13 for ; Wed, 24 Aug 2022 06:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=l16i/T321BPa96PODgfYG9DqbqafkxjIshNuUO3rAmw=; b=KyYVHHpHK3J4cZkcOsRgYpHrQizpkVr19cM4r+z2Y3eSweSI6xjpJSQMLY4UjozoFN VMm6Y4Z68SjdOh0YZhJcHvAQ+mbv4u+G3hyClGQjWngn4rUCcxkY4LZWv4+Mv1n/GEuL oZUoLsUMqwGW7AKaGJLfmzdQJod/ksK5QfMraxrF9+V0X4Wj6pLZIJhkaG7Jm3wH6Ak+ FQMzuhXCFJyCCJZyKPjC8hopt3p6Nsbpc0SmAjNJAnHKmsrV5GRPqJbhS3gAgba1ZktQ Aqq4Dhc/d4/fsJuK1IPsrCNkrN7F2ZQezDYLkw2aZoRsIRWKXmI0BA4zvkaQ0+1NzOwy XcEg== 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:cc:to:from:x-gm-message-state:from:to:cc; bh=l16i/T321BPa96PODgfYG9DqbqafkxjIshNuUO3rAmw=; b=YQONK+PwSjAO5z4xjc1B6yRcKcOC3joerKzpl7R92vBB22kb4jXUe51cMTwiYdVilR bRumfpa3hx/IFK+3EcYV3vFnBTS0qH2DSwvTu0CAAfJgq6nc7soBMvoAwBt4YXRdiBOj VsyFDgBs4qG3ue7MSrxhutHlHj+dFfCsUr48zJufEalf/X4//1/BdRBNfLJgDyBTEisd 3kp5UYv44nEqNABNdfA0F+R41UY+tkH5J99jj/qthDKmiLEG+MoUpSGjriLsPc4aV+24 GG6cbSAPF+kIj8Yqv0ytE/MUjv2IIV/75uvmQjC8SkD8xiLYoAjyDfOfJ7XzgV0O+KL+ LMfw== X-Gm-Message-State: ACgBeo3/EXvvKnc8RzZT/7iPB/xK8Du+8SIgk1xAdsa77WkwHuHqPN62 NlByjpTQov36j5I0WYA3t4+9F8LyF2HKOw== X-Google-Smtp-Source: AA6agR7U/eLplHtTIPAPiFvNBZr6K/OzbPBUaF2ZYJxMrhU0bzy+tZCPtZNcaXHGp6e/Qt3hudMU1A== X-Received: by 2002:a67:d70b:0:b0:390:1e0d:b6ba with SMTP id p11-20020a67d70b000000b003901e0db6bamr10635033vsj.9.1661346455222; Wed, 24 Aug 2022 06:07:35 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:745e:1e2b:867:85d9:4667]) by smtp.gmail.com with ESMTPSA id k6-20020a9f3f86000000b0038275916987sm13709836uaj.14.2022.08.24.06.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 06:07:34 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [COMMITTED 2.36 4/5] linux: Fix sys/mount.h usage with kernel headers Date: Wed, 24 Aug 2022 10:07:19 -0300 Message-Id: <20220824130720.2236114-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220824130720.2236114-1-adhemerval.zanella@linaro.org> References: <20220824130720.2236114-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 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 List-Id: 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. Reviewed-by: Florian Weimer (cherry picked from commit 774058d72942249f71d74e7f2b639f77184160a6) --- 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 a139a16532..3ceda9fdbf 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