public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/29171]  New: forgotten memcpy with -ffreestanding -fwhole-program --combine
@ 2006-09-21 17:53 acahalan at gmail dot com
  2006-09-21 17:57 ` [Bug middle-end/29171] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: acahalan at gmail dot com @ 2006-09-21 17:53 UTC (permalink / raw)
  To: gcc-bugs

Unlike Bug #29159 and Bug #17402, this one involves -ffreestanding. The results
are not really different. Basically, gcc is unable to correctly compile
anything significant with -fwhole-program. With or without the -ffreestanding
option, gcc will leave undefined references to various string.h things. It does
not matter if the program provides these functions in *.c files.

Note that -ffreestanding is illogical. I do have a C library, even including
the various libgcc things. I added -ffreestanding just now because a comment in
Bug #17402 incorrectly suggests this as a fix for the problem. Note that
-ffreestanding is probably undesirable even if would work, because I provide a
runtime and I expect gcc to take advantage of that runtime.

So anyway...

I have a number of *.c files, including a bit of inline assembly, which form
the entire program. ("program" being a shared object which gets executed via
the _init function) There are no other source libraries. I have a memset.c
containing the obvious function. This is based on klibc (bare-bones Linux C
library) with the assembly files replaced with *.c files.

No matter what attributes I place on the functions, either in the *.c or *.h
files, the compiler produces an undefined reference to memset. Though gcc
certainly compiles the function, it seems to forget this. I don't think an
undefined reference should even be possible with the -fwhole-program option;
this supposedly tells the compiler that I'm giving the WHOLE program.

The gcc version:

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.1 20060828 (Red Hat 4.1.1-20)

The compile command line, with numerous unrelated *.c files
chopped out of the middle:

gcc -m32 -std=gnu99 -nostdinc -isystem
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/include -D__KLIBC__ -Iinclude
-Iinclude/bits32 -Iinclude/arch/i386 -mregparm=3 -D_REGPARM=3
-Wstrict-prototypes -Wmissing-prototypes -msoft-float -fPIC
-fomit-frame-pointer -march=pentium2 -Os -fno-defer-pop -fno-common
-mtune=nocona -Wstrict-aliasing=2 -fvisibility=hidden -W -Wall -Wshadow -g3
-ffreestanding -fwhole-program --combine -c buffer.c testlib.c klibc/strcmp.c
klibc/strcpy.c klibc/strncpy.c klibc/memcpy.c klibc/memset.c klibc/strlen.c
klibc/strspn.c klibc/strxspn.c klibc/malloc.c klibc/mmap.c klibc/pause.c
klibc/raise.c klibc/sleep.c klibc/sigaction.c klibc/libgcc/__udivdi3.c
klibc/libgcc/__umoddi3.c klibc/libgcc/__udivmoddi4.c -o bigblob.pic


The link command line:

gcc -m32 -shared -Wl,-O9 -Wl,-warn-common -Wl,-soname,libfoo.so.1
-Wl,-z,initfirst -nostartfiles -nodefaultlibs -nostdlib -o tmp.so
bigblob.pic

Examining the result:

nm tmp.so | grep -i ' u ' 
        U memcpy

I have tried the memcpy function with and without various attributes including:
externally_visible, unused, noinline, regparm(0)

Last of all, here is the memcpy function itself.

/////////////////////////////////////////////////////////
#include <string.h>
#include <stdint.h>

void *memcpy(void *restrict dst, const void *restrict src, size_t n)
{
       const char *p = src;
       char *q = dst;
#if defined(__i386__)
       size_t nl = n >> 2;
       asm volatile ("cld ; rep ; movsl ; movl %3,%0 ; rep ; movsb":"+c" (nl),
                     "+S"(p), "+D"(q)
                     :"r"(n & 3));
#elif defined(__x86_64__)
       size_t nq = n >> 3;
       asm volatile ("cld ; rep ; movsq ; movl %3,%%ecx ; rep ; movsb":"+c"
                     (nq), "+S"(p), "+D"(q)
                     :"r"((uint32_t) (n & 7)));
#else
       while (n--) {
               *q++ = *p++;
       }
#endif

       return dst;
}


-- 
           Summary: forgotten memcpy with -ffreestanding -fwhole-program --
                    combine
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: acahalan at gmail dot com


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
@ 2006-09-21 17:57 ` pinskia at gcc dot gnu dot org
  2006-09-21 18:16 ` acahalan at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-09-21 17:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-09-21 17:57 -------
externally_visible should have fixed the undefined symbol.
Do you really have a simple testcase instead of just describing what your code
does?


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
          Component|c                           |middle-end


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
  2006-09-21 17:57 ` [Bug middle-end/29171] " pinskia at gcc dot gnu dot org
@ 2006-09-21 18:16 ` acahalan at gmail dot com
  2006-09-21 18:49 ` acahalan at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: acahalan at gmail dot com @ 2006-09-21 18:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from acahalan at gmail dot com  2006-09-21 18:15 -------
A simple test case would involve the code I gave plus whatever it takes to make
gcc decide to call memcpy. What is the most simple thing which triggers that?


-- 


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
  2006-09-21 17:57 ` [Bug middle-end/29171] " pinskia at gcc dot gnu dot org
  2006-09-21 18:16 ` acahalan at gmail dot com
@ 2006-09-21 18:49 ` acahalan at gmail dot com
  2006-09-21 20:36 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: acahalan at gmail dot com @ 2006-09-21 18:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from acahalan at gmail dot com  2006-09-21 18:49 -------
foo 0 $ cat foo.c
void *memcpy(void *restrict, const void *restrict, unsigned long);
void *memcpy(void *restrict dst, const void *restrict src, unsigned long n)
{
        const char *p = src;
        char *q = dst;
        while (n--) {
                *q++ = *p++;
        }
        return dst;
}
typedef struct S {
        int a[42];
}S;
void __attribute__((used,unused)) _fini(void)
{
        S *s1;
        S *s2;
        __asm__ __volatile__("":"=r"(s1)::"memory");
        __asm__ __volatile__("":"=r"(s2)::"memory");
        *s1 = *s2;
        __asm__ __volatile__(""::"r"(s1):"memory");
        __asm__ __volatile__(""::"r"(s2):"memory");
}
foo 0 $ make
gcc -m32 -std=gnu99 -nostdinc -fPIC -Os -fvisibility=hidden -W -Wall -g3
-ffreestanding -fwhole-program --combine -c foo.c -o bigblob.pic
rm -f tmp.so testcase.so.1.0.1
gcc -m32 -shared -nostartfiles -nodefaultlibs -nostdlib -o tmp.so bigblob.pic 
if nm tmp.so | grep -i --color=auto '.* u .*' ; then false ; else true ; fi
         U memcpy
make: *** [testcase.so.1.0.1] Error 1
foo 2 $ 


-- 


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
                   ` (2 preceding siblings ...)
  2006-09-21 18:49 ` acahalan at gmail dot com
@ 2006-09-21 20:36 ` pinskia at gcc dot gnu dot org
  2007-06-25 16:45 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-09-21 20:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-09-21 20:36 -------
Confirmed, note waiting means waiting for the reporter to get back to us about
a question, it should have been obvious anyways.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-09-21 20:36:50
               date|                            |


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
                   ` (3 preceding siblings ...)
  2006-09-21 20:36 ` pinskia at gcc dot gnu dot org
@ 2007-06-25 16:45 ` pinskia at gcc dot gnu dot org
  2007-06-26  3:37 ` acahalan at gmail dot com
  2010-09-17  9:09 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-25 16:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2007-06-25 16:44 -------
This is related to or really a dup of bug 4417.


-- 


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
                   ` (4 preceding siblings ...)
  2007-06-25 16:45 ` pinskia at gcc dot gnu dot org
@ 2007-06-26  3:37 ` acahalan at gmail dot com
  2010-09-17  9:09 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: acahalan at gmail dot com @ 2007-06-26  3:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from acahalan at gmail dot com  2007-06-26 03:37 -------
(In reply to comment #5)
> This is related to or really a dup of bug 4417.

It's only related, not a dup, though bug 4417 is sort of a subset.

There appears to be no possible set of gcc options that will allow compiling
non-trivial programs with -fwhole-program --combine. With or without the
-ffreestanding option, gcc will leave undefined references to various string.h
things. It does not matter if the program provides these functions in *.c
files.

With -ffreestanding, gcc ought to avoid using memcpy. Without, gcc ought to
call the one I'm providing. (both should work; neither one does)

Right now neither works, making -fwhole-program --combine 100% useless.

Alternately, the documentation is not correct, and the user can indeed link
with other things. (if I supply memcpy via some other binary file, then I am
NOT supplying the "whole program" to the compiler and am thus violating the
rules -- perhaps "whole program" needs a very detailed definition regarding *.S
files, system headers, libgcc.a, libgcc.so, libc.so, and so on) According to
the documentation, a command line with "--combine foo.c bar.c baz.S" would
invoke the C front end on foo.c and bar.c only; they thus become the
compilation unit. Adding -fwhole-program adds the requirement that the current
compilation unit (foo.c and bar.c) be the whole program, thereby excluding
baz.h from being part of the program.


-- 


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


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

* [Bug middle-end/29171] forgotten memcpy with -ffreestanding -fwhole-program --combine
  2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
                   ` (5 preceding siblings ...)
  2007-06-26  3:37 ` acahalan at gmail dot com
@ 2010-09-17  9:09 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-09-17  9:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2010-09-17 09:06 -------
-combine has been removed from GCC 4.6 in favor of LTO, closing as WONTFIX.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


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


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

end of thread, other threads:[~2010-09-17  9:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-21 17:53 [Bug c/29171] New: forgotten memcpy with -ffreestanding -fwhole-program --combine acahalan at gmail dot com
2006-09-21 17:57 ` [Bug middle-end/29171] " pinskia at gcc dot gnu dot org
2006-09-21 18:16 ` acahalan at gmail dot com
2006-09-21 18:49 ` acahalan at gmail dot com
2006-09-21 20:36 ` pinskia at gcc dot gnu dot org
2007-06-25 16:45 ` pinskia at gcc dot gnu dot org
2007-06-26  3:37 ` acahalan at gmail dot com
2010-09-17  9:09 ` rguenth at gcc dot gnu dot 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).