ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.24k stars 2.57k forks source link

-femit-asm=foo and related options will not restore a file in the output directory which has been tampered with by a third party #7219

Open DanB91 opened 4 years ago

DanB91 commented 4 years ago

I am trying to generate asm using the following command zig build-obj -femit-asm=build/asm.s -target x86_64-uefi-gnu program.zig. Unfortunately asm.s is only generated when zig-cache is not present. Once it generates the asm, it will not generate another copy unless zig-cache is deleted. I am running the release version of zig 0.7.0. `

andrewrk commented 4 years ago

Thanks for the report. I believe this was fixed by 5b5097a22a380a93a0f205ba218e8290a42ad051

FireFox317 commented 4 years ago

This has not been solved yet:

➜  7266 ls
main.zig
➜  7266 zig build-exe main.zig -femit-asm=asm.s
➜  7266 ls
asm.s  main  main.zig  zig-cache
➜  7266 rm asm.s 
➜  7266 ls
main  main.zig  zig-cache
➜  7266 zig build-exe main.zig -femit-asm=asm.s
➜  7266 ls
main  main.zig  zig-cache

As you can see, when the asm.s file is removed, it is not recreated.

andrewrk commented 4 years ago

The nature of this issue is changed after 5b5097a22a380a93a0f205ba218e8290a42ad051. Before, adding -femit-asm=foo.s to a previous compilation would not produce the foo.s file. Now it will, but there are still other cases to consider. Here is the current situation:

When you build a compilation, there is a zig-cache directory that gets the build artifacts. The way -femit-foo=bar options currently work is that they override the output path, so instead of the build artifacts going to the zig-cache directory, they in fact go to the explicitly specified path instead. For -femit-bin=foo this works fine because we have disable_lld_caching which always writes the output to the specified path. For the other options such as -femit-asm=foo when the input file is unchanged, the cache system tells us there is nothing to be done. However, if any of the source files are modified, the cache system will identify that the output file needs to be updated and everything works properly.

In short summary, this issue is open to represent the use case of the following options, under specific circumstances:

    \\  -femit-asm[=path]         Output .s (assembly code)
    \\  -fno-emit-asm             (default) Do not output .s (assembly code)
    \\  -femit-zir[=path]         Produce a .zir file with Zig IR
    \\  -fno-emit-zir             (default) Do not produce a .zir file with Zig IR
    \\  -femit-llvm-ir[=path]     Produce a .ll file with LLVM IR (requires LLVM extensions)
    \\  -fno-emit-llvm-ir         (default) Do not produce a .ll file with LLVM IR
    \\  -femit-h[=path]           Generate a C header file (.h)
    \\  -fno-emit-h               (default) Do not generate a C header file (.h)
    \\  -femit-docs[=path]        Create a docs/ dir with html documentation
    \\  -fno-emit-docs            (default) Do not produce docs/ dir with html documentation
    \\  -femit-analysis[=path]    Write analysis JSON file with type information
    \\  -fno-emit-analysis        (default) Do not write analysis JSON file with type information

The circumstances are: