This patch synchronizes <sys/cdefs.h> with the latest FreeBSD main branch. Alex Richardson (1): Expose clang's alignment builtins and use them for roundup2/rounddown2 Mark Johnston (2): cdefs: Make __nosanitizeaddress work for KASAN as well cdefs: Add a default definition for __nosanitizememory Warner Losh (3): cdefs.h: remove intel_compiler support cdefs.h: Remove __GNUCLIKE___OFFSETOF, it's unused cdefs.h: Remove redundant #ifdefs newlib/libc/include/sys/cdefs.h | 67 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 28 deletions(-) -- 2.35.3
From: Warner Losh <imp@FreeBSD.org> The age of the intel compiler support is so old as to be uninteresting. No recent recports of intel compiler support have been received. Remove all the special case workarounds for the Intel compiler. Should there be interest in supporting the compiler, contact me and I'll work with people to make it happen, though I suspect these instances are more likely to be in the way than to be helpful. Reviewed by: cem, emaste, vangyzen, dim Differential Revision: https://reviews.freebsd.org/D26817 --- newlib/libc/include/sys/cdefs.h | 34 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index da7290921..e6a31bd51 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -101,9 +101,9 @@ * having a compiler-agnostic source tree. */ -#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#if defined(__GNUC__) -#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) +#if __GNUC__ >= 3 #define __GNUCLIKE_ASM 3 #define __GNUCLIKE_MATH_BUILTIN_CONSTANTS #else @@ -113,15 +113,9 @@ #define __GNUCLIKE___OFFSETOF 1 #define __GNUCLIKE___SECTION 1 -#ifndef __INTEL_COMPILER #define __GNUCLIKE_CTOR_SECTION_HANDLING 1 -#endif #define __GNUCLIKE_BUILTIN_CONSTANT_P 1 -#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ - __INTEL_COMPILER < 800 -#undef __GNUCLIKE_BUILTIN_CONSTANT_P -#endif #if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) #define __GNUCLIKE_BUILTIN_VARARGS 1 @@ -140,10 +134,8 @@ #define __compiler_membar() __asm __volatile(" " : : : "memory") #endif -#ifndef __INTEL_COMPILER #define __GNUCLIKE_BUILTIN_NEXT_ARG 1 #define __GNUCLIKE_MATH_BUILTIN_RELOPS -#endif #define __GNUCLIKE_BUILTIN_MEMCPY 1 @@ -159,7 +151,7 @@ #define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 -#endif /* __GNUC__ || __INTEL_COMPILER */ +#endif /* __GNUC__ */ /* * The __CONCAT macro is used to concatenate parts of symbol names, e.g. @@ -228,18 +220,18 @@ * a feature that we cannot live without. */ #define __weak_symbol __attribute__((__weak__)) -#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) +#if !__GNUC_PREREQ__(2, 5) #define __dead2 #define __pure2 #define __unused #endif -#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) #define __unused /* XXX Find out what to do for __packed, __aligned and __section */ #endif -#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) +#if __GNUC_PREREQ__(2, 7) #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) #define __unused __attribute__((__unused__)) @@ -376,7 +368,7 @@ #define __pure #endif -#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#if __GNUC_PREREQ__(3, 1) #define __always_inline __inline__ __attribute__((__always_inline__)) #else #define __always_inline @@ -417,7 +409,7 @@ #endif /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ -#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#if !__GNUC_PREREQ__(2, 7) #define __func__ NULL #endif @@ -512,7 +504,7 @@ * that are known to support the features properly (old versions of gcc-2 * didn't permit keeping the keywords out of the application namespace). */ -#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#if !__GNUC_PREREQ__(2, 7) #define __printflike(fmtarg, firstvararg) #define __scanflike(fmtarg, firstvararg) #define __format_arg(fmtarg) @@ -532,18 +524,16 @@ /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ - defined(__GNUC__) && !defined(__INTEL_COMPILER) + defined(__GNUC__) #define __printf0like(fmtarg, firstvararg) \ __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) #else #define __printf0like(fmtarg, firstvararg) #endif -#if defined(__GNUC__) || defined(__INTEL_COMPILER) -#ifndef __INTEL_COMPILER +#if defined(__GNUC__) #define __strong_reference(sym,aliassym) \ extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) -#endif #ifdef __ELF__ #ifdef __STDC__ #define __weak_reference(sym,alias) \ @@ -587,7 +577,7 @@ __asm__(".stabs \"_/**/sym\",1,0,0,0") #endif /* __STDC__ */ #endif /* __ELF__ */ -#endif /* __GNUC__ || __INTEL_COMPILER */ +#endif /* __GNUC__ */ #ifndef __FBSDID #define __FBSDID(s) struct __hack -- 2.35.3
From: Alex Richardson <arichardson@FreeBSD.org> This makes roundup2/rounddown2 type- and const-preserving and allows using it on pointer types without casting to uintptr_t first. Not performing pointer-to-integer conversions also helps the compiler's optimization passes and can therefore result in better code generation. When using it with integer values there should be no change other than the compiler checking that the alignment value is a valid power-of-two. I originally implemented these builtins for CHERI a few years ago and they have been very useful for CheriBSD. However, they are also useful for non-CHERI code so I was able to upstream them for Clang 10.0. Rationale from the clang documentation: Clang provides builtins to support checking and adjusting alignment of pointers and integers. These builtins can be used to avoid relying on implementation-defined behavior of arithmetic on integers derived from pointers. Additionally, these builtins retain type information and, unlike bitwise arithmetic, they can perform semantic checking on the alignment value. There is also a feature request for GCC, so GCC may also support it in the future: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98641 Reviewed By: brooks, jhb, imp Differential Revision: https://reviews.freebsd.org/D28332 --- newlib/libc/include/sys/cdefs.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index e6a31bd51..7dff2c8d8 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -716,4 +716,23 @@ #define __guarded_by(x) __lock_annotate(guarded_by(x)) #define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) +/* Alignment builtins for better type checking and improved code generation. */ +/* Provide fallback versions for other compilers (GCC/Clang < 10): */ +#if !__has_builtin(__builtin_is_aligned) +#define __builtin_is_aligned(x, align) \ + (((__uintptr_t)x & ((align) - 1)) == 0) +#endif +#if !__has_builtin(__builtin_align_up) +#define __builtin_align_up(x, align) \ + ((__typeof__(x))(((__uintptr_t)(x)+((align)-1))&(~((align)-1)))) +#endif +#if !__has_builtin(__builtin_align_down) +#define __builtin_align_down(x, align) \ + ((__typeof__(x))((x)&(~((align)-1)))) +#endif + +#define __align_up(x, y) __builtin_align_up(x, y) +#define __align_down(x, y) __builtin_align_down(x, y) +#define __is_aligned(x, y) __builtin_is_aligned(x, y) + #endif /* !_SYS_CDEFS_H_ */ -- 2.35.3
From: Warner Losh <imp@FreeBSD.org> __GNUCLIKE___OFFSETOF is unreferenced in the tree, remove it as long obsolete. Sponsored by: Netflix --- newlib/libc/include/sys/cdefs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index 7dff2c8d8..6d179c2b4 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -110,7 +110,6 @@ #define __GNUCLIKE_ASM 2 #endif #define __GNUCLIKE___TYPEOF 1 -#define __GNUCLIKE___OFFSETOF 1 #define __GNUCLIKE___SECTION 1 #define __GNUCLIKE_CTOR_SECTION_HANDLING 1 -- 2.35.3
From: Mark Johnston <markj@FreeBSD.org> Add __nosanitizememory while I'm here. Reviewed by: andrew, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30126 --- newlib/libc/include/sys/cdefs.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index 6d179c2b4..7eb6c0430 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -699,12 +699,18 @@ #define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) /* - * Function or variable should not be sanitized, i.e. by AddressSanitizer. + * Function or variable should not be sanitized, e.g., by AddressSanitizer. * GCC has the nosanitize attribute, but as a function attribute only, and * warns on use as a variable attribute. */ #if __has_attribute(no_sanitize) && defined(__clang__) +#ifdef _KERNEL +#define __nosanitizeaddress __attribute__((no_sanitize("kernel-address"))) +#define __nosanitizememory __attribute__((no_sanitize("kernel-memory"))) +#else #define __nosanitizeaddress __attribute__((no_sanitize("address"))) +#define __nosanitizememory __attribute__((no_sanitize("memory"))) +#endif #define __nosanitizethread __attribute__((no_sanitize("thread"))) #else #define __nosanitizeaddress -- 2.35.3
From: Mark Johnston <markj@FreeBSD.org> MFC after: 1 week Sponsored by: The FreeBSD Foundation --- newlib/libc/include/sys/cdefs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index 7eb6c0430..b3508f3a9 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -714,6 +714,7 @@ #define __nosanitizethread __attribute__((no_sanitize("thread"))) #else #define __nosanitizeaddress +#define __nosanitizememory #define __nosanitizethread #endif -- 2.35.3
From: Warner Losh <imp@FreeBSD.org> Remove redunant #ifdef __GNUC__ inside an #if defined(__GNUC__) block. They are nops. Sponsored by: Netflix --- newlib/libc/include/sys/cdefs.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index b3508f3a9..720e70092 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -122,16 +122,12 @@ #define __GNUCLIKE_BUILTIN_VAALIST 1 #endif -#if defined(__GNUC__) #define __GNUC_VA_LIST_COMPATIBILITY 1 -#endif /* * Compiler memory barriers, specific to gcc and clang. */ -#if defined(__GNUC__) #define __compiler_membar() __asm __volatile(" " : : : "memory") -#endif #define __GNUCLIKE_BUILTIN_NEXT_ARG 1 #define __GNUCLIKE_MATH_BUILTIN_RELOPS -- 2.35.3
On Jul 11 09:15, Sebastian Huber wrote:
> From: Warner Losh <imp@FreeBSD.org>
>
> The age of the intel compiler support is so old as to be
> uninteresting. No recent recports of intel compiler support have been
> received. Remove all the special case workarounds for the Intel
> compiler. Should there be interest in supporting the compiler, contact
> me and I'll work with people to make it happen, though I suspect these
> instances are more likely to be in the way than to be helpful.
What about the Intel compiler support in newlib? Not that I have seen any
evidence that somebody is actually using one...
Other than that, the patchset looks good to me.
Thanks,
Corinna
On 11/07/2022 10:32, Corinna Vinschen wrote: > On Jul 11 09:15, Sebastian Huber wrote: >> From: Warner Losh<imp@FreeBSD.org> >> >> The age of the intel compiler support is so old as to be >> uninteresting. No recent recports of intel compiler support have been >> received. Remove all the special case workarounds for the Intel >> compiler. Should there be interest in supporting the compiler, contact >> me and I'll work with people to make it happen, though I suspect these >> instances are more likely to be in the way than to be helpful. > What about the Intel compiler support in newlib? Not that I have seen any > evidence that somebody is actually using one... The Intel compiler support was added through a <sys/cdefs.h> synchronization with FreeBSD in 2013 and 2015. The Intel compiler was probably never used together with Newlib. -- embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht München Registernummer: HRB 157899 Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/
On Jul 11 11:10, Sebastian Huber wrote:
> On 11/07/2022 10:32, Corinna Vinschen wrote:
> > On Jul 11 09:15, Sebastian Huber wrote:
> > > From: Warner Losh<imp@FreeBSD.org>
> > >
> > > The age of the intel compiler support is so old as to be
> > > uninteresting. No recent recports of intel compiler support have been
> > > received. Remove all the special case workarounds for the Intel
> > > compiler. Should there be interest in supporting the compiler, contact
> > > me and I'll work with people to make it happen, though I suspect these
> > > instances are more likely to be in the way than to be helpful.
> > What about the Intel compiler support in newlib? Not that I have seen any
> > evidence that somebody is actually using one...
>
> The Intel compiler support was added through a <sys/cdefs.h> synchronization
> with FreeBSD in 2013 and 2015. The Intel compiler was probably never used
> together with Newlib.
Ok, then please push.
Thx,
Corinna