[llvm-objcopy] Add additional testing for various cases
[llvm-core.git] / test / tools / llvm-objcopy / ELF / overlapping-sections-in-segments.test
blob94363a457d327d7dff37f49bbd045ad8d2ba1dd1
1 ## This test shows that llvm-objcopy does not baulk at overlapping sections
2 ## where such sections are within segments.
3 ## These don't really make sense, but the tool should still handle invalid
4 ## inputs somehow.
5 # RUN: yaml2obj %s -o %t.o
7 ## First, check that the section header table appears immediately after the program
8 ## header table.
9 # RUN: llvm-readobj --file-headers %t.o | FileCheck %s --check-prefix=SHDRS-OFFSET
10 # SHDRS-OFFSET: SectionHeaderOffset: 0x78{{$}}
12 ## Binary edit the section header sh_offset field of the second section to
13 ## overlap the first one.
14 # RUN: %python -c "with open('%/t.o', 'r+b') as input: import struct; bytes = struct.pack('<Q', 0x1001); input.seek(272); input.write(bytes)"
16 ## Sanity check that the binary editing modified the correct field.
17 # RUN: llvm-readobj --section-headers %t.o | FileCheck %s
19 ## Check that the contents are as expected before the copy.
20 # RUN: llvm-readobj -x .first -x .second %t.o | FileCheck %s --check-prefix=CONTENTS
22 ## Now check that the section contents are still correct after the copy and show that
23 ## llvm-objcopy hasn't "unoverlapped" these sections because they are in segments.
24 # RUN: llvm-objcopy %t.o %t2.o
25 # RUN: llvm-readobj --section-headers %t2.o | FileCheck %s
26 # RUN: llvm-readobj -x .first -x .second %t2.o | FileCheck %s --check-prefix=CONTENTS
28 # CHECK: Name: .first
29 # CHECK: Offset: 0x1000
30 # CHECK: Name: .second
31 # CHECK: Offset: 0x1001
33 # CONTENTS:      Hex dump of section '.first':
34 # CONTENTS-NEXT: 0x00000000 01234567
35 # CONTENTS-NEXT: Hex dump of section '.second':
36 # CONTENTS-NEXT: 0x00000000 23456789
38 --- !ELF
39 FileHeader:
40   Class:   ELFCLASS64
41   Data:    ELFDATA2LSB
42   Type:    ET_EXEC
43   Machine: EM_X86_64
44 Sections:
45   - Name: .first
46     Type: SHT_PROGBITS
47     Content: '01234567'
48     AddressAlign: 0x1000
49   - Name: .second
50     Type: SHT_PROGBITS
51     Content: '89abcdef'
52 ProgramHeaders:
53   - Type:     PT_LOAD
54     FileSize: 5
55     Offset:   0x1000
56     Align:    0x1000