--compress-sections <section-glib>=[none|zlib|zstd] is similar to --compress-debug-sections but applies to broader sections without the SHF_ALLOC flag. lld will report an error if a SHF_ALLOC section is matched. An interesting use case is to compress `.strtab`/`.symtab`, which consume a significant portion of the file size (15.1% for a release build of Clang). An older revision is available at https://reviews.llvm.org/D154641 . This patch focuses on non-allocated sections for safety. Moving `maybeCompress` as D154641 does not handle STT_SECTION symbols for `-r --compress-debug-sections=zlib` (see `relocatable-section-symbol.s` from #66804). Since different output sections may use different compression algorithms, we need CompressedData::type to generalize config->compressDebugSections. GNU ld feature request: https://sourceware.org/bugzilla/show_bug.cgi?id=27452 Link: https://discourse.llvm.org/t/rfc-compress-arbitrary-sections-with-ld-lld-compress-sections/71674 Pull Request: https://github.com/llvm/llvm-project/pull/84855
63 lines
1.6 KiB
ArmAsm
63 lines
1.6 KiB
ArmAsm
# REQUIRES: x86, zlib
|
|
|
|
# RUN: rm -rf %t && split-file %s %t && cd %t
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
|
|
# RUN: ld.lld -T a.lds a.o --compress-sections nonalloc=zlib --compress-sections str=zlib -o out
|
|
# RUN: llvm-readelf -SsXz -p str out | FileCheck %s
|
|
|
|
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
|
|
# CHECK: nonalloc PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 1
|
|
# CHECK-NEXT: str PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC 0 0 1
|
|
|
|
# CHECK: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_start
|
|
# CHECK: 0000000000000023 0 NOTYPE GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_end
|
|
# CHECK: String dump of section 'str':
|
|
# CHECK-NEXT: [ 0] AAA
|
|
# CHECK-NEXT: [ 4] BBB
|
|
|
|
## TODO The uncompressed size of 'nonalloc' is dependent on linker script
|
|
## commands, which is not handled. We should report an error.
|
|
# RUN: ld.lld -T b.lds a.o --compress-sections nonalloc=zlib
|
|
|
|
#--- a.s
|
|
.globl _start
|
|
_start:
|
|
ret
|
|
|
|
.section nonalloc0,""
|
|
.balign 8
|
|
.quad .text
|
|
.quad .text
|
|
.section nonalloc1,""
|
|
.balign 8
|
|
.quad 42
|
|
|
|
.section str,"MS",@progbits,1
|
|
.asciz "AAA"
|
|
.asciz "BBB"
|
|
|
|
#--- a.lds
|
|
SECTIONS {
|
|
.text : { *(.text) }
|
|
c = SIZEOF(.text);
|
|
b = c+1;
|
|
a = b+1;
|
|
nonalloc : {
|
|
nonalloc_start = .;
|
|
## In general, using data commands is error-prone. This case is correct, though.
|
|
*(nonalloc*) QUAD(SIZEOF(.text))
|
|
. += a;
|
|
nonalloc_end = .;
|
|
}
|
|
str : { *(str) }
|
|
}
|
|
|
|
#--- b.lds
|
|
SECTIONS {
|
|
nonalloc : { *(nonalloc*) . += a; }
|
|
.text : { *(.text) }
|
|
a = b+1;
|
|
b = c+1;
|
|
c = SIZEOF(.text);
|
|
}
|