[PATCH 0/9] Add check-cxx-linkage test for installed headers (BZ 34752)
Carlos O'Donell
carlos@redhat.com
Mon Nov 2 16:54:45 GMT 2026
On 10/21/26 9:54 AM, Adhemerval Zanella wrote:
> <sys/pidfd.h> declares pidfd_open and the other pidfd functions outside
> __BEGIN_DECLS/__END_DECLS, so C++ programs refer to them with C++
> language linkage and fail to link (BZ 34752). It also tests _PIDFD_H
> without ever defining it, so its multiple inclusion guard does not work.
>
> The existing header tests catch neither problem.
> check-installed-headers-cxx only checks that each header compiles as
> C++, and it includes each header only once.
>
> Patch 1 fixes <sys/pidfd.h>. Patch 2 makes check-installed-headers.sh
> include each header twice. The last patch adds check-cxx-linkage, which
> compiles each installed header as C++ with the GCC -fdump-lang-raw
> option and reports every global function that would require a symbol
> with C++ language linkage. The test is UNSUPPORTED if the compiler
> does not provide the option.
The -fdump-lang-raw is a clever trick.
I was wondering how you were going to try use all of the functions :-)
> Patches 3 to 8 fix the other issues the new test found.
>
> The test has two exceptions. The first is seqbuf_dump, from the Linux
> UAPI <linux/soundcard.h>. The second is all headers installed by the
> hurd and mach subdirectories, where the MIG generated RPC stubs and the
> GNU Mach headers declare more than a thousand functions without C language
> linkage on i686-gnu. Fixing those would need changes to MIG or to
> mach/Machrules.
>
> Checked on aarch64-linux-gnu and x86_64-linux-gnu. Also checked with
> the compile-only tests on 28 configurations (every Linux architecture,
> plus i686-gnu and x86_64-gnu).
>
> Adhemerval Zanella (9):
> linux: Add C++ and multiple inclusion guards to sys/pidfd.h (BZ 34752)
> scripts: Check multiple inclusion in check-installed-headers.sh
> nptl_db: Add __BEGIN_DECLS/__END_DECLS to thread_db.h
> Move internal err, error, and argp prototypes under !_ISOMAC
> alpha: Add __BEGIN_DECLS/__END_DECLS to bits/fenv.h
> loongarch: Add __BEGIN_DECLS/__END_DECLS to fpu_control.h
> mips: Add __BEGIN_DECLS/__END_DECLS to fpu_control.h
> misc: Add __BEGIN_DECLS/__END_DECLS to generic sys/swap.h
> Add check-cxx-linkage test for installed headers
>
> Makefile | 10 ++
> Rules | 13 ++
> include/argp.h | 2 +-
> include/err.h | 4 +-
> include/error.h | 3 +
> scripts/check-cxx-linkage.py | 225 ++++++++++++++++++++++++++++
> scripts/check-installed-headers.sh | 2 +
> sysdeps/alpha/fpu/bits/fenv.h | 4 +
> sysdeps/generic/sys/swap.h | 3 +
> sysdeps/loongarch/fpu_control.h | 4 +
> sysdeps/mips/fpu_control.h | 4 +
> sysdeps/nptl/thread_db.h | 4 +
> sysdeps/unix/sysv/linux/sys/pidfd.h | 5 +
> 13 files changed, 280 insertions(+), 3 deletions(-)
> create mode 100755 scripts/check-cxx-linkage.py
>
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list