A month or so ago when I was creating a cross-compiler for my OS (glidix) it didn't automatically add crt0.o and such to the executable, so to force it to include them, I modified gcc/config/glidix.h and added a STARTFILE_SPEC and ENDFILE_SPEC at the end, here's what it looks like now:
Code:
/* Useful if you wish to make target-specific gcc changes. */
#undef TARGET_GLIDIX
#define TARGET_GLIDIX 1
/* Don't automatically add extern "C" { } around header files. */
#undef NO_IMPLICIT_EXTERN_C
#define NO_IMPLICIT_EXTERN_C 1
/* Additional predefined macros. */
#undef TARGET_OS_CPP_BUILTINS
#define TARGET_OS_CPP_BUILTINS() \
do { \
builtin_define ("__glidix__"); \
builtin_define ("__unix__"); \
builtin_assert ("system=glidix"); \
builtin_assert ("system=unix"); \
builtin_assert ("system=posix"); \
} while(0);
#undef ENDFILE_SPEC
#define ENDFILE_SPEC "crtend.o%s crtn.o%s"
#undef STARTFILE_SPEC
#define STARTFILE_SPEC "crt0.o%s crti.o%s crtbegin.o%s"
It now successfully builds static executable, but refuses to build a shared library, because when I run:
Code:
x86_64-glidix-gcc -shared -o out/lib/libc.so out/lib/libc.a
("libc.a" does NOT contain the crt0.o files; they are seperate files installed under /glidix/lib), it tries to link crt0.o into libc.so, and fails due to undefined reference to 'main'. Is there something I am doing horribly wrong? And if so, what is it?