xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/set-section-alignment.test (revision b28412d5397dc5a23f172d6ebeac760c82a82248)
1# RUN: yaml2obj %s -o %t
2
3# RUN: llvm-objcopy --set-section-alignment .foo=4 --set-section-alignment .bar=0x5 \
4# RUN:   --set-section-alignment .baz=0 %t %t.2
5# RUN: llvm-readobj --sections %t.2 | FileCheck --check-prefix=CHECK %s
6
7# CHECK:      Name: .foo
8# CHECK:      AddressAlignment:
9# CHECK-SAME:                   4{{$}}
10# CHECK:      Name: .bar
11# CHECK:      AddressAlignment:
12# CHECK-SAME:                   5{{$}}
13# CHECK:      Name: .baz
14# CHECK:      AddressAlignment:
15# CHECK-SAME:                   0{{$}}
16
17## If a section is specified multiple times, the last wins.
18## Also incidentally show that unmentioned sections are not impacted.
19# RUN: llvm-objcopy --set-section-alignment .foo=4 --set-section-alignment=.foo=7 %t %t.3
20# RUN: llvm-readobj --sections %t.3 | FileCheck --check-prefix=MULTI %s
21
22# MULTI:      Name: .foo
23# MULTI:      AddressAlignment:
24# MULTI-SAME:                   7{{$}}
25# MULTI:      Name: .bar
26# MULTI:      AddressAlignment:
27# MULTI-SAME:                   0{{$}}
28# MULTI:      Name: .baz
29# MULTI:      AddressAlignment:
30# MULTI-SAME:                   4{{$}}
31
32## Ignore the option if the section does not exist.
33# RUN: llvm-objcopy --set-section-alignment .not_exist=4 %t.3 %t.4
34# RUN: cmp %t.3 %t.4
35
36# RUN: not llvm-objcopy --set-section-alignment=.foo %t /dev/null 2>&1 | \
37# RUN:   FileCheck --check-prefix=MISSING-EQUAL %s
38# MISSING-EQUAL:   error: bad format for --set-section-alignment: missing '='
39
40# RUN: not llvm-objcopy --set-section-alignment==4 %t /dev/null 2>&1 | \
41# RUN:   FileCheck --check-prefix=MISSING-SECTION %s
42# MISSING-SECTION: error: bad format for --set-section-alignment: missing section name
43
44# RUN: not llvm-objcopy --set-section-alignment=.foo=bar %t /dev/null 2>&1 | \
45# RUN:   FileCheck --check-prefix=INVALID-ALIGN %s
46# INVALID-ALIGN:   error: invalid value for --set-section-alignment: 'bar'
47
48!ELF
49FileHeader:
50  Class:   ELFCLASS64
51  Data:    ELFDATA2LSB
52  Type:    ET_REL
53  Machine: EM_X86_64
54Sections:
55  - Name:         .foo
56    Type:         SHT_PROGBITS
57  - Name:         .bar
58    Type:         SHT_NOBITS
59  - Name:         .baz
60    Type:         SHT_NOTE
61    AddressAlign: 4
62    Notes:        []
63