First, lets consult the "internals"
manual of gcc:
Quote:
Here is the order of prefixes tried for startfiles:
Any prefixes specified by the user with -B.
The environment variable GCC_EXEC_PREFIX or its automatically determined value based on the installed toolchain location.
The directories specified by the environment variable LIBRARY_PATH (or port-specific name; native only, cross compilers do not use this).
The macro STANDARD_EXEC_PREFIX, but only if the toolchain is installed in the configured prefix or this is a native compiler.
The location /usr/lib/gcc/, but only if this is a native compiler.
The macro MD_EXEC_PREFIX, if defined, but only if this is a native compiler.
The macro MD_STARTFILE_PREFIX, if defined, but only if this is a native compiler, or we have a target system root.
The macro MD_STARTFILE_PREFIX_1, if defined, but only if this is a native compiler, or we have a target system root.
The macro STANDARD_STARTFILE_PREFIX, with any sysroot modifications. If this path is relative it will be prefixed by GCC_EXEC_PREFIX and the machine suffix or STANDARD_EXEC_PREFIX and the machine suffix.
The macro STANDARD_STARTFILE_PREFIX_1, but only if this is a native compiler, or we have a target system root. The default for this macro is /lib/.
The macro STANDARD_STARTFILE_PREFIX_2, but only if this is a native compiler, or we have a target system root. The default for this macro is /usr/lib/.
The "-B" approach works on my test machine. Note that "-B" takes precedence over the gcc install folder, where the crtbegin.o, etc, are located in your case. If your /usr/lib also contains crtbegin.o for some reason and you want to shadow it, you need to specify the gcc install path with the "-B" option as well, and make it first, before /usr/lib.
Anyway. My understanding is that you want to host gcc inside your platform and not just to cross-compile. At the bare minimum, you may want to check out the "--with-sysroot" option. Setting it to "/" might fix your specific problem now. But the more comprehensive solution is to port GCC. I am not familiar with the process, but thankfully there is an
osdev guide for this type of thing and it addresses the steps necessary to create a port. Also, there is the relevant documentation
here.
If you don't want to host the compiler execution, but to simply cross compile, you may use the ffreestanding flag to instruct the compiler that the standard library routines cannot be treated as built-ins (that is, may not entirely conform to the standard) and to either pass -nostartfiles, -nodefaultlibs, or -nostdlib to the compiler driver during the linking stage, or directly invoke ld. In any case, if you call ld directly, or invoke gcc with -nostartfiles, you can control the directory of crt0, crtbegin and crtend manually. None of this applies if you want to host the compiler on your OS and build software there (such as when you have POSIX compatibility.)