xref: /llvm-project/lld/test/ELF/linkerscript/compress-sections.s (revision e53c53559bb6ca6d69b9c0f45988e33fd0cefb6e)
1# REQUIRES: x86, zlib
2
3# RUN: rm -rf %t && split-file %s %t && cd %t
4# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
5# RUN: ld.lld -T a.lds a.o --compress-sections nonalloc=zlib --compress-sections str=zlib -o out
6# RUN: llvm-readelf -SsXz -p str out | FileCheck %s
7
8# CHECK:      Name     Type            Address   Off      Size     ES Flg  Lk Inf Al
9# CHECK:      nonalloc PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00   C   0   0  1
10# CHECK-NEXT: str      PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 01 MSC   0   0  1
11
12# CHECK:      0000000000000000  0 NOTYPE  GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_start
13# CHECK:      0000000000000063  0 NOTYPE  GLOBAL DEFAULT [[#]] (nonalloc) nonalloc_end
14# CHECK:      String dump of section 'str':
15# CHECK-NEXT: [     0] AAA
16# CHECK-NEXT: [     4] {{a+}}
17# CHECK-NEXT: [    45] BBB
18
19## TODO The uncompressed size of 'nonalloc' is dependent on linker script
20## commands, which is not handled. We should report an error.
21# RUN: ld.lld -T b.lds a.o --compress-sections nonalloc=zlib
22
23#--- a.s
24.globl _start
25_start:
26  ret
27
28.section nonalloc0,""
29.balign 8
30.quad .text
31.quad .text
32.space 64
33.section nonalloc1,""
34.balign 8
35.quad 42
36
37.section str,"MS",@progbits,1
38  .asciz "AAA"
39  .asciz "BBB"
40  .fill 64,1,0x61
41  .byte 0
42
43#--- a.lds
44SECTIONS {
45  .text : { *(.text) }
46  c = SIZEOF(.text);
47  b = c+1;
48  a = b+1;
49  nonalloc : {
50    nonalloc_start = .;
51## In general, using data commands is error-prone. This case is correct, though.
52    *(nonalloc*) QUAD(SIZEOF(.text))
53    . += a;
54    nonalloc_end = .;
55  }
56  str : { *(str) }
57}
58
59#--- b.lds
60SECTIONS {
61  nonalloc : { *(nonalloc*) . += a; }
62  .text : { *(.text) }
63  a = b+1;
64  b = c+1;
65  c = SIZEOF(.text);
66}
67