IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Compiler output files

    MaskRay发表于 2023-04-26 07:05:29
    love 0

    For a GCC or Clang command, there is typically one primary outputfile, specified by -o or the default (a.out ora.exe). There can also be temporary files and auxiliaryfiles.

    Primary output file

    We can specify the primary output file with the -ooption. When unspecified, a default output file name is inferred fromthe input files and the final phase. When the final phase is linking,the default output file name is a.out ora.exe.

    1
    2
    3
    4
    gcc -S d/a.c      # a.s
    gcc -c d/a.c # a.o
    gcc d/a.c # a.out
    gcc d/a.c -o e/a # e/a

    Temporary files

    For compilation and linking in one command, the relocatable objectfiles are temporary files.

    For GCC, when generating a relocatable object file, it needs togenerate a temporary assembly file, then feeds it to GNU assembler.

    We can set the temporary directory with one of the environmentvariables TMPDIR, TMP, and TEMP.When none is specified, compilers have a fallback, /tmp on*NIX systems.

    Auxiliary files

    Beside primary output files and temporary output files, we have athird output file type called auxiliary output files. Some options suchas -ftest-coverage and -gsplit-dwarfcause the compiler to generate auxiliary output files.

    For compilation without linking (-c, -S,etc), the auxiliary output file names are derived from the primaryoutput file name.

    For compilation and linking in one command, the primary output filename affects the auxiliary output file names.

    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 some optionsthat are primarily of interest to GCC developers. These dump outputfiles are treated the same way as auxiliary output files.

    -dumpdir and -dumpbase are provided tocontrol the auxiliary output file names. The officialdocumentation may be difficult to follow. Let's see someexamples.

    1
    2
    3
    4
    5
    6
    7
    8
    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

    # Specify both to avoid the influence of the source filename.
    gcc -g -gsplit-dwarf -dumpdir f/ -dumpbase x d/a.c # f/x.dwo

    In the absence of -dumpdir, -dumpbaseappends 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-tempsand -save-temps={cwd,obj} generate intermediatefiles.

    In the absence of -dumpdir/-dumpbase,-save-temps is like an alias for-save-temps=cwd and stores intermediate files in thecurrent directory. -save-temps=obj stores intermediatefiles in the directory of the output file specified by-o.

    When -dumpdir is specified, there is complex interactionbetween -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) togenerate other auxiliary output files. I plan to change their file namesto be controlled by -dumpdir.



沪ICP备19023445号-2号
友情链接