Auxiliary output files

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
2
3
4
gcc -c -g -gsplit-dwarf d/a.c d/b.c      # a.o b.o a.dwo b.dwo
gcc -c -g -gsplit-dwarf d/a.c -o e/a.o # e/a.o e/a.dwo
gcc -g -gsplit-dwarf d/a.c d/b.c -o e/x # e/x (temporary .o files) e/x-a.dwo e/x-b.dwo
gcc -g -gsplit-dwarf d/a.c d/b.c # (temporary .o files) a-a.dwo a-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
2
3
4
5
gcc -g -gsplit-dwarf -dumpdir f d/a.c -c # fa.dwo
gcc -g -gsplit-dwarf -dumpdir f d/a.c # fa.dwo
gcc -g -gsplit-dwarf -dumpdir f/ d/a.c # f/a.dwo
gcc -g -gsplit-dwarf -dumpbase f d/a.c # f-a.dwo
gcc -g -gsplit-dwarf -dumpbase f/ d/a.c # f/-a.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
2
3
4
5
6
# The last of -dumpdir and -save-temps wins.
gcc -g -gsplit-dwarf d/a.c -o e/x -dumpdir f/ -save-temps=obj # e/a.{i,s,o,dwo}
gcc -g -gsplit-dwarf d/a.c -o e/x -save-temps=obj -dumpdir f/ # f/a.{i,s,o,dwo}

# -save-temps=obj and -dumpdir are orthogonal.
clang -g -gsplit-dwarf d/a.c -o e/x -save-temps=obj -dumpdir f/ # e/a.{i,s,o} f/a.dwo

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.