This is an archive of the discontinued LLVM Phabricator instance.

Make stdarg.h compatible with FreeBSD
AbandonedPublic

Authored by arichardson on Mar 17 2018, 4:57 PM.

Details

Summary

On FreeBSD it is currently not possible to use the clang builtin
headers to build the base system. The build will fail with the
following error if I don't delete the std* headers from the clang
install directory:

/sources/freebsd-mips/include/stdio.h:72:19: error:
redefinition of typedef 'va_list' is a C11 feature
[-Werror,-Wtypedef-redefinition]
typedef __va_list       va_list;
                        ^
/home/alr48/cheri/output/sdk/lib/clang/7.0.0/include/stdarg.h:30:27:
note: previous definition is here
typedef __builtin_va_list va_list;

/sources/freebsd-mips/sys/sys/_stdarg.h:46:11: error: 'va_start' macro redefined
[-Werror,-Wmacro-redefined]
  #define       va_start(ap, last)      __builtin_va_start((ap), (last))
                ^
/home/alr48/cheri/output/sdk/lib/clang/7.0.0/include/stdarg.h:35:9:
note: previous definition is here
  #define va_start(ap, param) __builtin_va_start(ap, param)

FreeBSD includes definitions of va_list, va_copy, etc in the
<machine/stdarg.h> header and some files end up including both that
header and <stdarg.h>.

Only defining the va_* macros if they are not yet defined fixes the
macro redefiniton issue and probably also makes sense for other
operating systems. However, for the va_list typedef I can't think
of a better solution than to also check for _VA_LIST_DECLARED and
define it.

Diff Detail

Event Timeline

arichardson created this revision.Mar 17 2018, 4:57 PM
dim added a reviewer: emaste.Mar 17 2018, 5:15 PM
dim added a comment.Mar 17 2018, 5:17 PM

I'm fine with either this approach, or with the approach in stdint.h, e.g. using __has_include_next(), and in that case first including the system-provided header before this one.

This does not fix the potential problem on NetBSD. We define __VA_LIST_DECLARED (with extra _ on the beginning).

The proper solution looks to go for:

#if __STDC_HOSTED__ && __has_include_next(<stdarg.h>)
bsdjhb added a subscriber: bsdjhb.Apr 18 2018, 10:39 AM

FWIW, I ended up fixing FreeBSD to only use <machine/stdarg.h> in freestanding environments and always use <stdarg.h> in userland which makes this patch no longer necessary. (Only one place needed to be fixed.)

arichardson abandoned this revision.Oct 3 2022, 7:02 AM

Hopefully no longer required.

Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 7:02 AM
Herald added a subscriber: jrtc27. · View Herald Transcript