1 ## This test shows that llvm-objcopy does not baulk at overlapping sections.
2 ## These don't really make sense, but the tool should still handle invalid
4 # RUN: yaml2obj %s -o %t.o
6 ## First, check that the section header table appears immediately after the ELF
8 # RUN: llvm-readobj --file-headers %t.o | FileCheck %s --check-prefix=SHDRS-OFFSET
9 # SHDRS-OFFSET: SectionHeaderOffset: 0x40{{$}}
11 ## Binary edit the section header sh_offset field of the second section to
12 ## overlap the first one.
13 # RUN: %python -c "with open('%/t.o', 'r+b') as input: import struct; bytes = struct.pack('<Q', 0x1001); input.seek(216); input.write(bytes)"
15 ## Sanity check that the binary editing modified the correct field.
16 # RUN: llvm-readobj --section-headers %t.o | FileCheck %s --check-prefix=VALIDATE
18 # VALIDATE: Name: .first
19 # VALIDATE: Offset: 0x1000
20 # VALIDATE: Name: .second
21 # VALIDATE: Offset: 0x1001
23 ## Check that the contents are as expected before the copy.
24 # RUN: llvm-readobj -x .first -x .second %t.o | FileCheck %s --check-prefix=CONTENTS
26 ## Now check that the section contents are still correct after the copy.
27 ## Also characterize the behavior of llvm-objcopy in that it "unoverlaps" the
29 # RUN: llvm-objcopy %t.o %t2.o
30 # RUN: llvm-readobj --section-headers %t2.o | FileCheck %s
31 # RUN: llvm-readobj -x .first -x .second %t2.o | FileCheck %s --check-prefix=CONTENTS
34 # CHECK: Offset: 0x1000
35 # CHECK: Name: .second
36 # CHECK: Offset: 0x1004
38 # CONTENTS: Hex dump of section '.first':
39 # CONTENTS-NEXT: 0x00000000 01234567
41 # CONTENTS-NEXT: Hex dump of section '.second':
42 # CONTENTS-NEXT: 0x00000000 23456789