On Mon, 18 May 2020, Florian Weimer wrote:

> >> In glibc, we already have this:
> >> 
> >> /* Used to disable stack protection in sensitive places, like ifunc
> >>    resolvers and early static TLS init.  */
> >> # define inhibit_stack_protector \
> >>     __attribute__ ((__optimize__ ("-fno-stack-protector")))
> >> #else
> >> # define inhibit_stack_protector
> >> #endif
> >> 
> >> Is it broken?
> >
> > Depends on what your expectations are.  It completely overrides all 
> > options given on the command line (including things like 
> > fno-omit-frame-pointer and -O2!).  At least I was very surprised by that 
> > even though the current docu can be read that way; if you're similarly 
> > surprised, then yes, the above is broken, it does not only disable stack 
> > protection (but also e.g. all optimizations, despite the attributes name 
> > :-) ).
> Yes, that would qualify as broken.
> This is not what I observe with gcc-9.3.1-2.fc31.x86_64 from Fedora.
> -O2 still has an effect.

Indeed, I definitely remember an interaction with the attribute and -O{,2} 
(or something that I interpreted as such) but it obviously isn't as simple 
as plain disabling it, and right now I can't recreate the situation :-/
(It might be disabling of some further cmdline flags that I conflated in 
my brain with "effect of -O2")

> So does -fcf-protection. -fno-omit-frame-pointer does not work for me at 
> all for some reason, the frame pointer is always missing?

Not for me:

% cat simple.c
extern int bla(int *);
#ifdef ATTR
__attribute__((__optimize__ ("-fno-stack-protector")))
foo(int a, int b)
  int c = b;
  return a * 42 + bla(&c);
% gcc-9 -fno-omit-frame-pointer -O -S -o - tryme.c | grep bp
        pushq   %rbp
        movq    %rsp, %rbp
        movl    %esi, -20(%rbp)
        leaq    -20(%rbp), %rdi
        popq    %rbp
% gcc-9 -fstack-protector-all -fno-omit-frame-pointer -O -S -o - tryme.c | grep 
        pushq   %rbp
        movq    %rsp, %rbp
        movq    %rax, -24(%rbp)
        movl    %esi, -28(%rbp)
        leaq    -28(%rbp), %rdi
        movq    -24(%rbp), %rdx
        popq    %rbp

But using the attr:

% gcc-9 -DATTR -fstack-protector-all -fno-omit-frame-pointer -O -S -o - tryme.c 
| grep bp

(gcc9 is gcc9-9.2.1+r275327-1.1.x86_64 on opensuse)


Reply via email to