Commit 0b7fb27b698d (Fix and document -r option) broke building of VxWorks modules, at least for our version of VxWorks. A VxWorks module is a relocatable ELF file - the final link is done when the file is linked in to the running kernel. So building with -r is necessary. However, the module also needs to be wrapped in crtbegin.o/crtend.o in order to have the exception frame info registered with the run-time.
We used to achieve that with a custom spec file that specified crtbegin.o and crtend.o as start/endfile, but after the above commit, %S and %E no longer get substituted. In order to allow custom spec files to add arbitrary objects at the beginning/end, add a level of indirection that puts "%o" in a new outfiles spec - then the custom spec file can override that with the %rename outfiles old_outfiles *outfiles: ... idiom. Of course, the custom spec file could also override all of the link_command, but that's a lot of logic to copy-paste and keep in sync. gcc/ChangeLog: 2020-04-04 Rasmus Villemoes <r...@rasmusvillemoes.dk> * gcc.c (OUTFILES_SPEC): New spec, hook for wrapping or overriding %o. --- I'm not quite up to speed on how the gcc repo works after the switch to git. Please advise. gcc/gcc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/gcc.c b/gcc/gcc.c index 9f790db0daf..7ea7e2a3ae0 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -804,6 +804,10 @@ proper position among the other output files. */ #define ENDFILE_SPEC "" #endif +#ifndef OUTFILES_SPEC +#define OUTFILES_SPEC "%o" +#endif + #ifndef LINKER_NAME #define LINKER_NAME "collect2" #endif @@ -1042,7 +1046,7 @@ proper position among the other output files. */ "%X %{o*} %{e*} %{N} %{n} %{r}\ %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \ - VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ + VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %(outfiles) "" \ %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ %:include(libgomp.spec)%(link_gomp)}\ %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ @@ -1087,6 +1091,7 @@ static const char *link_gomp_spec = ""; static const char *libgcc_spec = LIBGCC_SPEC; static const char *endfile_spec = ENDFILE_SPEC; static const char *startfile_spec = STARTFILE_SPEC; +static const char *outfiles_spec = OUTFILES_SPEC; static const char *linker_name_spec = LINKER_NAME; static const char *linker_plugin_file_spec = ""; static const char *lto_wrapper_spec = ""; @@ -1596,6 +1601,7 @@ static struct spec_list static_specs[] = INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec), INIT_STATIC_SPEC ("lto_wrapper", <o_wrapper_spec), INIT_STATIC_SPEC ("lto_gcc", <o_gcc_spec), + INIT_STATIC_SPEC ("outfiles", &outfiles_spec), INIT_STATIC_SPEC ("post_link", &post_link_spec), INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec), INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix), -- 2.23.0