public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59219] New: ____builtin___memcpy_chk and -fno-builtin-memcpy
@ 2013-11-20 23:19 msebor at gmail dot com
  2013-11-21 12:10 ` [Bug c/59219] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: msebor at gmail dot com @ 2013-11-20 23:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59219

            Bug ID: 59219
           Summary: ____builtin___memcpy_chk and -fno-builtin-memcpy
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gmail dot com

The __builtin___xxx_chk intrinsics are useful in detecting buffer overflows via
the Object Size Checking feature. But in a freestanding/embeeded environment
with its own implementation of function xxx (such as memcpy), the
__builtin___xxx_chk intrinsics cannot be used even with the -ffreestanding or
-fno-builtin option because they result in the inline expansion of the related
xxx function irrespective of the option (see the test program below). To get
the benefit of Object Size Checking in these environments, it's necessary to
hand-code __builtin___xxx_chk instead. It would simplify the adoption of Object
Size Checking in these environments if instead of expanding xxx inline when
-fno-builtin is specified, GCC emitted a call to xxx. (As a side note, this
happens to be the behavior of the Intel compiler.)

$ cat v.c && gcc -O2 -c -fno-builtin -std=c11 v.c && objdump -d v.o | sed -n
"/<foo>:/,/^$/p"
typedef __typeof__ (sizeof 0) size_t;

extern inline __attribute__ ((always_inline, artificial)) void*
memcpy (void* restrict d, const void* restrict s, size_t n) {
    return __builtin___memcpy_chk (d, s, n, __builtin_object_size (d, 1));
}

char b [4];

void foo (const void *p) {
    memcpy (b, p, sizeof b);
}
0000000000000010 <foo>:
  10:    8b 07                    mov    (%rdi),%eax
  12:    89 05 00 00 00 00        mov    %eax,0(%rip)        # 18 <foo+0x8>
  18:    c3                       retq


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

end of thread, other threads:[~2013-11-25  9:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-20 23:19 [Bug c/59219] New: ____builtin___memcpy_chk and -fno-builtin-memcpy msebor at gmail dot com
2013-11-21 12:10 ` [Bug c/59219] " rguenth at gcc dot gnu.org
2013-11-21 16:21 ` msebor at gmail dot com
2013-11-22 10:29 ` rguenth at gcc dot gnu.org
2013-11-22 17:25 ` msebor at gmail dot com
2013-11-25  9:29 ` rguenth at gcc dot gnu.org

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 read-only IMAP folder(s) and NNTP newsgroup(s).