As Bill Westfield wrote: > However, if I link > with "-nostartfiles" I seem to get the desired behavior.
That's what you are supposed to do, yes. > How is the crtxxx file linked into the final target? In order for the > weak symbol to be overridden by my own definition, it would have to be > treated as a library, and should come "after" my code, right? No, the crt*.o file is explicitly linked as the very first object file on the linker commandline. You can watch this by adding -v to the compiler commandline. When thinking about it, it probably doesn't make sense to declare it weak in the library, as there's no way around using -nostartfiles, but then, the (non-weak) vector table from crt*.o isn't in the way anyway. I don't know whether it would be possible to move the crt*.o file into a library at all (*), at least historically, it's never been the case. For example, on my host system, it looks like: $ echo 'int main(void) { return 42; }' > foo.c $ cc -v -o foo foo.c Using built-in specs. Target: i386-undermydesk-freebsd Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 4.2.1 20070719 [FreeBSD] /usr/libexec/cc1 -quiet -v -D_LONGLONG foo.c -quiet -dumpbase foo.c -auxbase foo -version -o /var/tmp//ccOUXd5v.s ignoring duplicate directory "/usr/include" #include "..." search starts here: #include <...> search starts here: /usr/include End of search list. GNU C version 4.2.1 20070719 [FreeBSD] (i386-undermydesk-freebsd) compiled by GNU C version 4.2.1 20070719 [FreeBSD]. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 6b6f6bc30816b118527ed697984d7f28 /usr/bin/as -o /var/tmp//cchKS1Jl.o /var/tmp//ccOUXd5v.s /usr/bin/ld --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 -o foo /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib -L/usr/lib /var/tmp//cchKS1Jl.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o GNU ld version 2.15 [FreeBSD] 2004-05-23 Supported emulations: elf_i386_fbsd As you can see, /usr/lib/crt1.o is the very first file on the linker commandline, too. (*) If at all, it would require per-device libraries, and GCC has to know about that. In order for crt*.o to be pulled from a library, there has to be a "pre-undefined" symbol that would cause the linker to consider that file at all. Adding such a symbol would be another compiler driver change. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-) _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-libc-dev