My custom compiler for a toy language uses Cranelift to generate object code, that I can write into a file main.o
. To make this object file into an executable file, I invoke GCC with gcc -o main main.o
.
However, I would like to pipe the code directly into GCC in order not to have a temporary object file written to disk, so I make my compiler write object code to the standard output. Using -
as a filename does not work because the -x
option does not appear to have any values for object files.
Using some kind of shell redirect also does not work: gcc -o main <(compiler)
errors out with /usr/bin/ld: /proc/self/fd/11: file not recognized: Illegal seek
. (Note that this does work when GCC itself works on the file, for example with gcc -xc <(echo "int main(){}") -o main
, but not when the file is passed to LD. The -pipe
option also doesn't seem to make a difference.)
Is there any way to use GCC to link object code piped into it?