Some options cause the compiler to generate auxiliary output files. How are the files named?
For compilation without linking (-c
, -S
,
etc), the auxiliary output file names are derived from the primary
output file name.
For compilation and linking in one command, the relocatable object
files are temporary files. (We can control the directory with the
environment variables TMPDIR
, TMP
, and
TEMP
.) The final output file name (-o
) affects
the auxiliary output file names.
-gsplit-dwarf
creates auxiliary .dwo
files. Let's see some examples.
1 | gcc -c -g -gsplit-dwarf d/a.c d/b.c # a.o b.o a.dwo b.dwo |
GCC provides -dumpdir
and -dumpbase
to
control the auxiliary output file names. The official documentation is
at https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html,
which may be difficult to follow. Let's see some examples.
1 | gcc -g -gsplit-dwarf -dumpdir f d/a.c -c # fa.dwo |
-dumpbase
appends a dash, which makes it inconvenient. I
suggest that you only use -dumpdir
.
I have a patch to support -dumpdir
in Clang: https://reviews.llvm.org/D149193.
-save-temps
-save-temps
and -save-temps={cwd,obj}
generate intermediate
files.
In the absence of -dumpdir
/-dumpbase
,
-save-temps
is like an alias for
-save-temps=cwd
and stores intermediate files in the
current directory. -save-temps=obj
stores intermediate
files in the directory of the output file specified by
-o
.
When -dumpdir
is specified, there is complex interaction
between -dumpdir
and
-save-temps
/-save-temps={cwd,obj}
. For Clang,
I think we should make -dumpdir
and
-save-temps
/-save-temps={cwd,obj}
orthogonal.
1 | # The last of -dumpdir and -save-temps wins. |
Other auxiliary files
Clang supports a few options (e.g. -ftime-trace
) to
generate other auxiliary output files. I plan to change their file names
to be controlled by -dumpdir
.