Replies: 4 comments 8 replies
-
|
@os-d, Thanks for centralizing this and making an excellent write-up! Interesting findings! One thing to note is that the LLVM PE/COFF emitter does not support section alignment values smaller than 4KB. That is the reason the size of the non-4K aligned CLANGPDB image is byte-for-byte identical to the 4K aligned image. They both have 4K alignment even though /ALIGN:4096 wasn't explicitly supplied to the linker. The thing that I find surprising is the |
Beta Was this translation helpful? Give feedback.
-
|
@nate-desimone moved this to a separate comment thread because it isn't really relevant to the main point of this: I'm seeing that lld-link does support < 4K section alignment. My ARM64 test I had missed that ArmVirt.dsc.inc was overriding what I set in tools_def.txt to be 4KB.
Looks like they added support for it awhile back: https://reviews.llvm.org/D65736. |
Beta Was this translation helpful? Give feedback.
-
|
Per the findings in the thread, marking this discussion resolved. |
Beta Was this translation helpful? Give feedback.
-
|
Should this discussion spawn a GitHub issue to align CLANGPDB and CLANGDWARF sizes? |
Beta Was this translation helpful? Give feedback.






Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@mdkinney pointed out that CLANGDWARF produces binaries that are smaller than CLANGPDB. There have been various discussions on this offline and online so I am centralizing the conversation here.
An example for OVMF X64 CLANGPDB DXE Core:
vs OVMF X64 CLANGDWARF DXE Core
@nate-desimone had suggested there may be an LLVM bug here. For the actual file size, I realized that neither CLANGPDB/CLANGDWARF for X64 is setting 0x1000 common-page-size/ALIGN (which also means memory protections can't be applied), setting that to match VS/GCC gives:
CLANGPDB:
CLANGDWARF:
So that makes sense where CLANGDWARF now has a larger file size, because the ELF conversion logic uses common-page-size for file alignment and section alignment whereas the PE image can have a lower file alignment. The virtual (in memory) size delta is also reduced from ~10% greater for CLANGPDB to ~0.6% greater for CLANGPDB, or in other words noise.
So, I think we are actually okay here when we go to 4K section alignment, which is what we already want. There may be other tuning opportunities, to be sure. There is a PR that is attempting to update CLANGPDB IA32/X64 to 4K section alignment here: #11454.
I'll note that CLANGPDB AARCH64 already has /ALIGN:4096.
Beta Was this translation helpful? Give feedback.
All reactions