Messages in this thread Patch in this message | | | From | Nick Desaulniers <> | Date | Thu, 24 May 2018 14:27:08 -0700 | Subject | Re: [clang] stack protector and f1f029c7bf |
| |
On Thu, May 24, 2018 at 2:12 PM Nick Desaulniers <ndesaulniers@google.com> wrote: > On Thu, May 24, 2018 at 1:52 PM Nick Desaulniers <ndesaulniers@google.com> > wrote: > > On Thu, May 24, 2018 at 1:26 PM Nick Desaulniers < ndesaulniers@google.com> > > wrote: > > > On Thu, May 24, 2018 at 11:59 AM <hpa@zytor.com> wrote: > > > > Issue 3: Let's face it, reading and writing the flags should be > > builtins, > > > exactly because it has to do stack operations, which really means the > > > compiler should be involved.
> > > I'm happy to propose that as a feature request to llvm+gcc.
> > Oh, looks like both clang and gcc have: > > __builtin_ia32_readeflags_u64()
> > https://godbolt.org/g/SwPjhq
> > Maybe native_save_fl() and native_restore_fl() should be replaced in the > > kernel with > > __builtin_ia32_readeflags_u64() and __builtin_ia32_writeeflags_u64()? > > -- > > Thanks, > > ~Nick Desaulniers
> Looks like those builtins got added to GCC around the 4.9 timeframe: > https://godbolt.org/g/9VS2E9
> Problematically, it seems that GCC does not have __has_builtin to do > feature detection:
https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros > https://godbolt.org/g/oku8ux
Is there a more canonical way the kernel does feature detection that looks better than:
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h index 89f08955fff7..90974b5d023c 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -13,6 +13,8 @@ * Interrupt control: */
+#ifdef GCC_VERSION +#if GCC_VERSION < 40900 static inline unsigned long native_save_fl(void) { unsigned long flags; @@ -38,6 +40,17 @@ static inline void native_restore_fl(unsigned long flags) :"g" (flags) :"memory", "cc"); } +#else +static inline unsigned long native_save_fl(void) +{ + return __builtin_ia32_readeflags_u64(); +} +static inline void native_restore_fl(unsigned long flags) +{ + __builtin_ia32_writeeflags_u64(flags); +} +#endif +
static inline void native_irq_disable(void) { -- Thanks, ~Nick Desaulniers
| |