Auxiliary output files
2023-4-25 15:0:0 Author: maskray.me(查看原文) 阅读量:12 收藏

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. 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      
gcc -c -g -gsplit-dwarf d/a.c -o e/a.o
gcc -g -gsplit-dwarf d/a.c d/b.c -o e/x
gcc -g -gsplit-dwarf d/a.c d/b.c

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 
gcc -g -gsplit-dwarf -dumpdir f d/a.c
gcc -g -gsplit-dwarf -dumpdir f/ d/a.c
gcc -g -gsplit-dwarf -dumpbase f d/a.c
gcc -g -gsplit-dwarf -dumpbase f/ d/a.c

-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

gcc -g -gsplit-dwarf d/a.c -o e/x -dumpdir f/ -save-temps=obj
gcc -g -gsplit-dwarf d/a.c -o e/x -save-temps=obj -dumpdir f/


clang -g -gsplit-dwarf d/a.c -o e/x -save-temps=obj -dumpdir f/

Other auxiliary files

Clang supports a few options to generate other auxiliary output files. I plan to change their file names to be controlled by -dumpdir.


文章来源: https://maskray.me/blog/2023-04-25-auxiliary-output-files
如有侵权请联系:admin#unsafe.sh