While studying the kernel build system, I noticed that before v4.19 the kernel was using incremental linking (ld -r
) and then it moved to thin archives (ar T
) as shown at: What is the difference between the following kernel Makefile terms: vmLinux, vmlinuz, vmlinux.bin, zimage & bzimage? I noticed
Then, I tried to make a synthetic incremental linking benchmark to see if the link speedup was considerable at: https://stackoverflow.com/questions/29391965/what-is-partial-linking-in-gnu-linker/53959624#53959624 but it wasn't for my benchmark.
Therefore, my question is: why does the kernel use incremental linking or thin archives?
Is it to speed up the build or for some other reason?
Which commit introduced incremental linking? With that I would be able to figure out the rationale from git log
. I found the one that moved to thin archives with git log --grep 'thin archive'
(a5967db9af51a84f5e181600954714a9e4c69f1f), but could not easily grep the incremental linking one.
If it exists to speed up the build, is there a way to quickly test out link with vs without incremental linking to see the speedup?
Best Answer
Reason for thin archives
I've pinged Nicholas Piggin by email, who is one of the authors of the patches, and he explained that the thin archives are not just to reduce disk usage, but they can also prevent a link failure.
The problem is that the incremental linked object files could get so large, that the linker cannot insert even trampoline relocations, which must point to generated code that goes between the objects.
I didn't get a reply for the rationale for the incremental builds yet.
This is his awesome reply: