* why ld return with error? @ 2011-01-31 5:02 ali hagigat 2011-01-31 7:17 ` Ian Lance Taylor 0 siblings, 1 reply; 4+ messages in thread From: ali hagigat @ 2011-01-31 5:02 UTC (permalink / raw) To: Ian Lance Taylor, binutils I have the following files: prog3.c #include <stdio.h> main(){ printf("uuuuuu\n"); } prog3.ld ASSERT(1,"there is not an error"); Then : gcc -c prog3.c -o prog3.o ld prog3.o prog3.ld -o prog3 ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074 prog3.o: In function `main': prog3.c:(.text+0x11): undefined reference to `puts' ------------------------------------------------------------------------ I want to force gcc (or ld) to use its built-in functions as printf and puts(not to use the standard library functions like libc.a or libc.so). how can i do it? ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: why ld return with error? 2011-01-31 5:02 why ld return with error? ali hagigat @ 2011-01-31 7:17 ` Ian Lance Taylor 2011-01-31 8:28 ` ali hagigat 0 siblings, 1 reply; 4+ messages in thread From: Ian Lance Taylor @ 2011-01-31 7:17 UTC (permalink / raw) To: ali hagigat; +Cc: binutils ali hagigat <hagigatali@gmail.com> writes: > I have the following files: > prog3.c > #include <stdio.h> > main(){ > printf("uuuuuu\n"); > } > prog3.ld > ASSERT(1,"there is not an error"); > Then : > gcc -c prog3.c -o prog3.o > ld prog3.o prog3.ld -o prog3 > > ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074 > prog3.o: In function `main': > prog3.c:(.text+0x11): undefined reference to `puts' > ------------------------------------------------------------------------ > I want to force gcc (or ld) to use its built-in functions as printf > and puts(not to use the standard library functions like libc.a or > libc.so). how can i do it? gcc by default optimizes printf of a string constant ending in a newline to call puts instead. To disable that, use -fno-builtin-printf when compiling. I don't understand what you mean when you say that you want gcc to use its built-in functions as printf rather than the standard library functions. gcc has no built-in printf function. Ian ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: why ld return with error? 2011-01-31 7:17 ` Ian Lance Taylor @ 2011-01-31 8:28 ` ali hagigat 2011-01-31 9:00 ` Dave Korn 0 siblings, 1 reply; 4+ messages in thread From: ali hagigat @ 2011-01-31 8:28 UTC (permalink / raw) To: Ian Lance Taylor, binutils Thank you for the reply. I think that GCC compiler collection has the definitions and C code of some standard libraries. It means that the code of printf exists inside the code of gcc and gcc does not need to go to /usr/bin on hard disk to find libc.a and then find the defintion and the body of printf. Is that right? or I am mistaken? If I am mistaken what will be the meaning of -fno-builtin then? I think the code of built-in functions exist inside the code segment of gcc when it is invoked. Regards On Mon, Jan 31, 2011 at 10:47 AM, Ian Lance Taylor <iant@google.com> wrote: > ali hagigat <hagigatali@gmail.com> writes: > >> I have the following files: >> prog3.c >> #include <stdio.h> >> main(){ >> printf("uuuuuu\n"); >> } >> prog3.ld >> ASSERT(1,"there is not an error"); >> Then : >> gcc -c prog3.c -o prog3.o >> ld prog3.o prog3.ld -o prog3 >> >> ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074 >> prog3.o: In function `main': >> prog3.c:(.text+0x11): undefined reference to `puts' >> ------------------------------------------------------------------------ >> I want to force gcc (or ld) to use its built-in functions as printf >> and puts(not to use the standard library functions like libc.a or >> libc.so). how can i do it? > > gcc by default optimizes printf of a string constant ending in a newline > to call puts instead. To disable that, use -fno-builtin-printf when > compiling. > > I don't understand what you mean when you say that you want gcc to use > its built-in functions as printf rather than the standard library > functions. gcc has no built-in printf function. > > Ian > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: why ld return with error? 2011-01-31 8:28 ` ali hagigat @ 2011-01-31 9:00 ` Dave Korn 0 siblings, 0 replies; 4+ messages in thread From: Dave Korn @ 2011-01-31 9:00 UTC (permalink / raw) To: ali hagigat; +Cc: Ian Lance Taylor, binutils On 31/01/2011 08:28, ali hagigat wrote: > Thank you for the reply. I think that GCC compiler collection has the > definitions and C code of some standard libraries. It means that the > code of printf exists inside the code of gcc and gcc does not need to > go to /usr/bin on hard disk to find libc.a and then find the defintion > and the body of printf. > Is that right? or I am mistaken? > If I am mistaken what will be the meaning of -fno-builtin then? I > think the code of built-in functions exist inside the code segment of > gcc when it is invoked. GCC's built-ins are an internal mechanism by which the compiler can "know" enough about what goes on inside a function such as printf to be able to optimise it - in some but not all cases - but ultimately they rely on the underlying functionality of the system's C library. They're kind of synthetic inline wrappers around the real functions, that in some cases can be simplified during expansion. They don't actually have the functionality that the C library supplies; you could picture the builtin printf as being something roughly like this: int builtin_printf (const char *fmt, ...) __attribute__ ((__always_inline__)) { if (__builtin_constant_p (fmt) && (strcmp (fmt, "%s") == 0 || strchr (fmt, "%") == NULL)) { if (strcmp (fmt, "%s") == 0) { str = GET_FIRST_VARARG(); } else { str = fmt; } /* If the string was "", printf does nothing. */ if (str[0] == '\0') return 0; /* If the string has length of 1, call putchar. */ if (str[1] == '\0) { builtin_putchar (fmt[0]); return 1; } /* If the string was "string\n", call puts("string"). */ . . . /* Other optimisations etc. */ . . . } /* Can't optimise it if we don't know the format string at compile time, so pass it through to the . */ return __builtin_apply (printf, __builtin_apply_args(), GET_VARARGS_SIZE()); } When the compiler comes to inline this into a function that is calling printf, it will end up either optimising the whole thing away into a call to the C lib's underlying printf function, or translate it into a call with modified args to builtin_putchar or builtin_puts, which each may also make further transformations or just optimise away into a libcall likewise. So in the end all the actual functionality still has to come from the C library anyway. cheers, DaveK ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-01-31 9:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-01-31 5:02 why ld return with error? ali hagigat 2011-01-31 7:17 ` Ian Lance Taylor 2011-01-31 8:28 ` ali hagigat 2011-01-31 9:00 ` Dave Korn
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).