Download raw body.
Guarding inline asm with __GNUC__
No, this is about `inline asm` (i.e `__asm`), not `inline`. :) `inline` is a C99 standard feature [1], but `__asm` (`__asm__`, `asm`) isn't [2][3]. And my goal is not building the whole OpenBSD project with another compiler; I just want my (and others') home brewed C compiler could be able to process at least the C standard headers. [1]: http://port70.net/%7Ensz/c/c99/n1256.html#6.7.4 [2]: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html [3]: https://stackoverflow.com/a/49830990 On Sun, Dec 31, 2023, at 9:18 PM, Jonathan Gray wrote: > On Sun, Dec 31, 2023 at 08:36:52PM -0800, Chenguang Wang wrote: >> Hi, >> >> It seems that /usr/include/machine/endian.h uses inline asm, which is a >> GNU C extension, without guarding it with __GNUC__. This header is a >> dependency of stdio.h, which means any C compiler that wants to #include >> stdio.h is required to implement the asm extension. This has been >> causing troubles in the cproc C11 compiler; they had to patch that >> header file [1] in their automated testing setup for OpenBSD. > > __inline is defined by cdefs.h which endian.h includes > > For a C compiler not defining __GNUC__ it gets defined to nothing. > Untested diff below to define it to inline for >= c99. > > I would not be surprised if other things are broken when __GNUC__ > is not defined. The pcc revival started out that way but soon changed. > > Index: sys/sys/cdefs.h > =================================================================== > RCS file: /cvs/src/sys/sys/cdefs.h,v > diff -u -p -r1.43 cdefs.h > --- sys/sys/cdefs.h 29 Oct 2018 17:10:40 -0000 1.43 > +++ sys/sys/cdefs.h 1 Jan 2024 05:10:36 -0000 > @@ -66,8 +66,9 @@ > #define __const const /* define reserved names to standard */ > #define __signed signed > #define __volatile volatile > -#if defined(__cplusplus) || defined(__PCC__) > -#define __inline inline /* convert to C++ keyword */ > +#if defined(__cplusplus) || \ > + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) > +#define __inline inline /* convert to C++/C99 keyword */ > #else > #if !defined(__GNUC__) > #define __inline /* delete GCC keyword */
Guarding inline asm with __GNUC__