linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Error after setting -Og] ‘__bad_copy_from’ declared with attribute error: copy source size is too small
@ 2017-11-09 21:02 Wei Wei
  2017-11-18  3:03 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Wei @ 2017-11-09 21:02 UTC (permalink / raw)
  To: LKML

Hi all,

I get a compile time error after setting -Og when compiling for the latest GitHub version.
I am using `make defconfig’ to get the default x86_64 config. But previously I did this in v4.4, 
it's fine.

Modification to Makefile:
KBUILD_CFLAGS  += -O2 $(call cc-disable-warning,maybe-uninitialized,)            
       else                                                                  
       -KBUILD_CFLAGS   += -O2                                                    
       +KBUILD_CFLAGS   += -Og                                                    
       endif                                                                    
       endif   

And error info:
In file included from ./arch/x86/include/asm/preempt.h:6:0,                        
  from ./include/linux/preempt.h:80,                                              
  from ./include/linux/rcupdate.h:40,                                             
  from ./include/linux/rculist.h:10,                                              
  from ./include/linux/pid.h:4,                                                   
  from ./include/linux/sched.h:13,                                                
  from kernel/ptrace.c:12:                                                        
  In function ‘check_copy_size’,                                                  
  inlined from ‘copy_to_user’ at ./include/linux/uaccess.h:153:6,                 
  inlined from ‘ptrace_request’ at kernel/ptrace.c:934:7:                         
  ./include/linux/thread_info.h:138:4: error: call to ‘__bad_copy_from’ declared 
with attribute error: copy source size is too small
  __bad_copy_from();                                                              
  ^                                                                               
  scripts/Makefile.build:313: recipe for target 'kernel/ptrace.o' failed          
  make[1]: *** [kernel/ptrace.o] Error 1                                          
  Makefile:1023: recipe for target ‘kernel' failed  

Any help is appreciated!

Thank you,
Wei

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Error after setting -Og] ‘__bad_copy_from’ declared with attribute error: copy source size is too small
  2017-11-09 21:02 [Error after setting -Og] ‘__bad_copy_from’ declared with attribute error: copy source size is too small Wei Wei
@ 2017-11-18  3:03 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2017-11-18  3:03 UTC (permalink / raw)
  To: Wei Wei; +Cc: LKML

On Thu, Nov 09, 2017 at 04:02:53PM -0500, Wei Wei wrote:
> Hi all,
> 
> I get a compile time error after setting -Og when compiling for the latest GitHub version.
> I am using `make defconfig’ to get the default x86_64 config. But previously I did this in v4.4, 
> it's fine.

; cat >a.c <<'EOF'
extern void __attribute((error("1"))) f1(void);
extern void __attribute((error("2"))) f2(void);

static inline __attribute__((always_inline)) void bar(const void *addr)
{
        int sz = __builtin_object_size(addr, 0);
        if (__builtin_expect(sz >= 0, 0))
                f1();
        if (sz >= 0)
                f2();
}

void foo(int *in)
{
        bar(in);
}
EOF
; gcc -O2 -c a.c
; gcc -Og -c a.c
In function ‘bar’,
    inlined from ‘foo’ at a.c:15:2:
a.c:8:3: error: call to ‘f1’ declared with attribute error: 1
   f1();
   ^
;

Note that the call of f2() _was_ eliminated.  Wrap the condition into
__builtin_expect() and with -Og it doesn't get eliminated until too
late.  It's really brittle and dependent not just upon the _result_
of optimizations (get rid of __attribute((error())) in those and
you'll see that with -Og it compiles into
        .file   "a.c"
        .text
        .globl  foo
        .type   foo, @function
foo:
.LFB1:
        .cfi_startproc
        rep ret
        .cfi_endproc
.LFE1:
        .size   foo, .-foo
getting rid of both calls, as it ought to); it depends upon the moment
when dead code elimination happens.  -Og leaves the sucker around for
too long.  If you replace that __builtin_object_size() with -1 (which
is what it evaluates to), you'll get elimination happening early enough
even with -Og; ditto for getting rid of inlining...

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-18  3:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-09 21:02 [Error after setting -Og] ‘__bad_copy_from’ declared with attribute error: copy source size is too small Wei Wei
2017-11-18  3:03 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).