Proper way of replacing crt0.o/GCC search path for startup files

Schwarz, Konrad
Mon May 11 10:46:00 GMT 2015


I have written an alternative crt0.o (the startup file placed at the
beginning of the executable) for a bare-metal system.

For GCC to use this, it requires a new specs file.

I would like to keep both the new specs file and the alternative crt0.o
in a central location, but not in GCC installation directories.

I was unable to find precise documentation on how GCC searches for specs
files and for startup files.  It seems like directories added by -L are
not searched for spec or startup files, for example.  (I.e., my_crt0%o%s was not
found by GCC, despite an appropriate -L argument).

My current solution uses an environment variable to point to the
directory containing the spec file and the my_crt0.o file.
This environment variable is expanded in the makefile to find the spec file
and is expanded in the spec file, via the %:getenv() spec-file function,
to find my_crt0.o.

This has the drawback of hard coding the name of this environment variable 
in the spec file.  Hence, the environment variable needs to be documented;
and impinges on the user's namespace of environment variables.

Is there a better way of doing this?  E.g., an option specifying additional
directories to look for spec and startup files?

(Although this is strictly a GCC question, libgloss contains numerous
spec files, so I am hoping to find some expertise here.)


Konrad Schwarz

More information about the Newlib mailing list