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
5 # RUN: yaml2obj %s -o %t.o
7 ## First, check that the section header table appears immediately after the program
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
29 # CHECK: Offset: 0x1000
30 # CHECK: Name: .second
31 # CHECK: Offset: 0x1001
33 # CONTENTS: Hex dump of section '.first':
34 # CONTENTS-NEXT: 0x00000000 01234567
36 # CONTENTS-NEXT: Hex dump of section '.second':
37 # CONTENTS-NEXT: 0x00000000 23456789