News for hackers. Stuff that matters.
Re:Zig's New Relationship with LLVM by ikskuh on Monday September 28, 2020 @09:03AM (#24616184)
Yes, you understood that right. The existing executable file is not written completly anew.

And yes, it will be faster. The way Zig does this is by only recompiling and modifying the parts of the executable where the source has changed. Imagine a project like chromium, where your executable is 150 MB large. Now you change a single function. Classic linking would require the whole linking process and the write of 150 MB of code. Zig will only compile and patch a single function (when lucky: less than 1kB) and emit this. Less I/O, less overall work to do.

Re:Zig's New Relationship with LLVM by tom_mellior on Monday September 28, 2020 @10:45AM (#24617160)
> Now you change a single function. Classic linking would require the whole linking process and the write of 150 MB of code. Zig will only compile and patch a single function (when lucky: less than 1kB) and emit this.

I see, thanks. I think I was misled by the article's "the final executable depends on everything else and so any meaningful change to the code will invalidate it". My understanding now is that, since the Zig compiler knows exactly what has changed, unlike a traditional linker it will not invalidate the parts that haven't changed. Is that correct?

Re:Zig's New Relationship with LLVM by dnautics on Monday September 28, 2020 @11:10AM (#24617471)
> the final executable depends on everything else and so any meaningful change to the code will invalidate it

If I'm not mistaken that refers to in traditional compiled languages.

Re:Zig's New Relationship with LLVM by rictic on Monday September 28, 2020 @01:06PM (#24618843)
What if the machine code for the function is larger after than before?

I guess even worst case, writing 151MB to disk is fast if you have the data ready. Very fast with a modern SSD.

Re:Zig's New Relationship with LLVM by AndyKelley on Monday September 28, 2020 @03:36PM (#24620423)
This is a fascinating topic that I hope to follow up with a more technical blog post. The short summary is that there is room for functions to grow, and if they still exceed the padding, they get moved around to a new location in both virtual memory and in the file. Because of indirect function calls this means callsites remain the same; only the GOT entry has to get updated. The actual function body is moved with the copy_file_range syscall, where available.