Follow up on D139181.
Here we assume that alignExpr contains a valid value (i.e. non zero power of 2).
It was already somewhat assumed but not checked. This will now crash if it's not the case.
Details
- Reviewers
MaskRay
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
lld/ELF/InputSection.h | ||
---|---|---|
74 | Moving it after partition should allow it to fit into padding bytes |
lld/ELF/InputSection.h | ||
---|---|---|
74 | I moved the field around but it didn't improve the situation |
If you look at the -Xclang -fdump-record-layouts output you can see that it does improve the requirerd size, but due to the 8 byte alignment requirement it is still rounded up to 48 (for 64-bit architectures). However, for 32-bit arch reordering does help: 36 vs 40 bytes.
*** Dumping AST Record Layout 0 | struct OutputSegment 0:0-2 | uint8_t sectionKind 0:3-3 | uint8_t bss 0:4-4 | uint8_t keepUnique 1 | uint8_t partition 2 | struct llvm::Align addralign 2 | uint8_t ShiftValue 4 | uint32_t type 8 | class llvm::StringRef name 8 | const char * Data 16 | size_t Length 24 | uint64_t flags 32 | uint32_t entsize 36 | uint32_t link 40 | uint32_t info | [sizeof=48, dsize=44, align=8, | nvsize=44, nvalign=8]
Whereas the current patch has sizeof==dsize:
*** Dumping AST Record Layout 0 | struct OutputSegment 0:0-2 | uint8_t sectionKind 0:3-3 | uint8_t bss 0:4-4 | uint8_t keepUnique 1 | uint8_t partition 4 | uint32_t type 8 | class llvm::StringRef name 8 | const char * Data 16 | size_t Length 24 | uint64_t flags 32 | struct llvm::Align addralign 32 | uint8_t ShiftValue 36 | uint32_t entsize 40 | uint32_t link 44 | uint32_t info | [sizeof=48, dsize=48, align=8, | nvsize=48, nvalign=8]
With this patch, the final lld executable is larger and some call sites are more complex.
llvm::Align probably won't improve lld/ELF (and the extra dependency llvm/Support/Alignment.h and MathExtras.h is somewhat unnecessary).
I've checked using p2align for lld::elf::Symbol, but I think it won't decrease the struct size and will likely lead to no less code size in most call sites.
Note: I think struct size for 32-bit systems isn't really necessary. The 64-bit system behavior is much more interesting.
Moving it after partition should allow it to fit into padding bytes