diff --git a/llvm/test/tools/llvm-objcopy/ELF/basic-binary-copy.test b/llvm/test/tools/llvm-objcopy/ELF/basic-binary-copy.test --- a/llvm/test/tools/llvm-objcopy/ELF/basic-binary-copy.test +++ b/llvm/test/tools/llvm-objcopy/ELF/basic-binary-copy.test @@ -1,25 +1,25 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy -O binary %t %t2 -# RUN: od -t x2 -v %t2 | FileCheck %s -# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - AddressAlign: 0x0000000000001000 - Content: "c3c3c3c3" -ProgramHeaders: - - Type: PT_LOAD - Flags: [ PF_X, PF_R ] - Sections: - - Section: .text - -# CHECK: 0000000 c3c3 c3c3 -# SIZE: 4 +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy -O binary %t %t2 +# RUN: od -t x2 -v %t2 | FileCheck %s --ignore-case +# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000001000 + Content: "c3c3c3c3" +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + Sections: + - Section: .text + +# CHECK: 0000000 c3c3 c3c3 +# SIZE: 4 diff --git a/llvm/test/tools/llvm-objcopy/ELF/binary-no-paddr.test b/llvm/test/tools/llvm-objcopy/ELF/binary-no-paddr.test --- a/llvm/test/tools/llvm-objcopy/ELF/binary-no-paddr.test +++ b/llvm/test/tools/llvm-objcopy/ELF/binary-no-paddr.test @@ -1,42 +1,42 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy -O binary %t %t2 -# RUN: od -t x2 -v %t2 | FileCheck %s -# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Address: 0x1000 - AddressAlign: 0x0000000000001000 - Content: "c3c3c3c3" - - Name: .data - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC ] - Address: 0x1004 - AddressAlign: 0x0000000000000004 - Content: "3232" -ProgramHeaders: - - Type: PT_LOAD - Flags: [ PF_X, PF_R ] - VAddr: 0x1000 - PAddr: 0x0000 - Align: 0x1000 - Sections: - - Section: .text - - Type: PT_LOAD - Flags: [ PF_R, PF_W ] - VAddr: 0x1004 - PAddr: 0x0000 - Align: 0x1000 - Sections: - - Section: .data - -# CHECK: 0000000 c3c3 c3c3 3232 -# SIZE: 6 +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy -O binary %t %t2 +# RUN: od -t x2 -v %t2 | FileCheck %s --ignore-case +# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1000 + AddressAlign: 0x0000000000001000 + Content: "c3c3c3c3" + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x1004 + AddressAlign: 0x0000000000000004 + Content: "3232" +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + VAddr: 0x1000 + PAddr: 0x0000 + Align: 0x1000 + Sections: + - Section: .text + - Type: PT_LOAD + Flags: [ PF_R, PF_W ] + VAddr: 0x1004 + PAddr: 0x0000 + Align: 0x1000 + Sections: + - Section: .data + +# CHECK: 0000000 c3c3 c3c3 3232 +# SIZE: 6 diff --git a/llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test b/llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test --- a/llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test +++ b/llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test @@ -1,45 +1,45 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy -O binary %t %t2 -# RUN: od -t x2 %t2 | FileCheck %s -# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Address: 0x1000 - AddressAlign: 0x0000000000001000 - Content: "c3c3c3c3" - - Name: .data - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC ] - Address: 0x2000 - AddressAlign: 0x0000000000001000 - Content: "3232" -ProgramHeaders: - - Type: PT_LOAD - Flags: [ PF_X, PF_R ] - VAddr: 0x1000 - PAddr: 0x1000 - Align: 0x1000 - Sections: - - Section: .text - - Type: PT_LOAD - Flags: [ PF_R, PF_W ] - VAddr: 0x2000 - PAddr: 0x4000 - Align: 0x1000 - Sections: - - Section: .data - -# CHECK: 0000000 c3c3 c3c3 0000 0000 0000 0000 0000 0000 -# CHECK-NEXT: 0000020 0000 0000 0000 0000 0000 0000 0000 0000 -# CHECK-NEXT: * -# CHECK-NEXT: 0030000 3232 -# SIZE: 12290 +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy -O binary %t %t2 +# RUN: od -t x2 %t2 | FileCheck %s --ignore-case +# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1000 + AddressAlign: 0x0000000000001000 + Content: "c3c3c3c3" + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x2000 + AddressAlign: 0x0000000000001000 + Content: "3232" +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + VAddr: 0x1000 + PAddr: 0x1000 + Align: 0x1000 + Sections: + - Section: .text + - Type: PT_LOAD + Flags: [ PF_R, PF_W ] + VAddr: 0x2000 + PAddr: 0x4000 + Align: 0x1000 + Sections: + - Section: .data + +# CHECK: 0000000 c3c3 c3c3 0000 0000 0000 0000 0000 0000 +# CHECK-NEXT: 0000020 0000 0000 0000 0000 0000 0000 0000 0000 +# CHECK-NEXT: * +# CHECK-NEXT: 0030000 3232 +# SIZE: 12290 diff --git a/llvm/test/tools/llvm-objcopy/ELF/binary-segment-layout.test b/llvm/test/tools/llvm-objcopy/ELF/binary-segment-layout.test --- a/llvm/test/tools/llvm-objcopy/ELF/binary-segment-layout.test +++ b/llvm/test/tools/llvm-objcopy/ELF/binary-segment-layout.test @@ -1,38 +1,38 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy -O binary %t %t2 -# RUN: od -t x2 %t2 | FileCheck %s -# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - AddressAlign: 0x0000000000001000 - Address: 0x00 - Content: "c3c3c3c3" - - Name: .data - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - AddressAlign: 0x0000000000000008 - Address: 0x08 - Content: "3232" -ProgramHeaders: - - Type: PT_LOAD - Flags: [ PF_X, PF_R ] - VAddr: 0x00 - Sections: - - Section: .text - - Type: PT_LOAD - Flags: [ PF_R ] - VAddr: 0x08 - Sections: - - Section: .data - -# CHECK: 0000000 c3c3 c3c3 0000 0000 3232 -# SIZE: 10 +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy -O binary %t %t2 +# RUN: od -t x2 %t2 | FileCheck %s --ignore-case +# RUN: wc -c < %t2 | FileCheck %s --check-prefix=SIZE + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000001000 + Address: 0x00 + Content: "c3c3c3c3" + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000008 + Address: 0x08 + Content: "3232" +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + VAddr: 0x00 + Sections: + - Section: .text + - Type: PT_LOAD + Flags: [ PF_R ] + VAddr: 0x08 + Sections: + - Section: .data + +# CHECK: 0000000 c3c3 c3c3 0000 0000 3232 +# SIZE: 10 diff --git a/llvm/test/tools/llvm-objcopy/ELF/check-addr-offset-align-binary.test b/llvm/test/tools/llvm-objcopy/ELF/check-addr-offset-align-binary.test --- a/llvm/test/tools/llvm-objcopy/ELF/check-addr-offset-align-binary.test +++ b/llvm/test/tools/llvm-objcopy/ELF/check-addr-offset-align-binary.test @@ -1,40 +1,40 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy -O binary %t %t2 -# RUN: od -t x1 %t2 | FileCheck %s - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Address: 0x1000 - AddressAlign: 0x0000000000001000 - Content: "c3c3c3c3" - - Name: .data - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC ] - Address: 0x1008 - AddressAlign: 0x0000000000000008 - Content: "3232" -ProgramHeaders: - - Type: PT_LOAD - Flags: [ PF_X, PF_R ] - VAddr: 0x1000 - PAddr: 0x1000 - Align: 0x1000 - Sections: - - Section: .text - - Type: PT_LOAD - Flags: [ PF_R, PF_W ] - VAddr: 0x1008 - PAddr: 0x1008 - Align: 0x1000 - Sections: - - Section: .data - -# CHECK: 0000000 c3 c3 c3 c3 00 00 00 00 32 32 +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy -O binary %t %t2 +# RUN: od -t x1 %t2 | FileCheck %s --ignore-case + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1000 + AddressAlign: 0x0000000000001000 + Content: "c3c3c3c3" + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x1008 + AddressAlign: 0x0000000000000008 + Content: "3232" +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + VAddr: 0x1000 + PAddr: 0x1000 + Align: 0x1000 + Sections: + - Section: .text + - Type: PT_LOAD + Flags: [ PF_R, PF_W ] + VAddr: 0x1008 + PAddr: 0x1008 + Align: 0x1000 + Sections: + - Section: .data + +# CHECK: 0000000 c3 c3 c3 c3 00 00 00 00 32 32 diff --git a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test --- a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test +++ b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test @@ -1,44 +1,44 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy -O binary -j .text %t %t2 -# RUN: llvm-objcopy -O binary --only-section .text %t %t3 -# RUN: llvm-objcopy --dump-section .text=%t4 %t %t5 -# RUN: llvm-objcopy --dump-section .foo=%t6 %t %t7 -# RUN: not llvm-objcopy --dump-section .bar=%t8 %t %t9 2>&1 | FileCheck %s --check-prefix=NOBITS -DINPUT=%t -# RUN: od -t x1 %t2 | FileCheck %s -# RUN: od -t x1 %t6 | FileCheck %s --check-prefix=NON-ALLOC -# RUN: wc -c %t2 | FileCheck %s --check-prefix=SIZE -# RUN: diff %t2 %t3 -# RUN: diff %t4 %t3 - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - AddressAlign: 0x0000000000001000 - Content: "DEADBEEF" - - Name: .foo - Type: SHT_PROGBITS - Flags: [ SHF_WRITE ] - Content: "CAFE" - - Name: .bar - Type: SHT_NOBITS - Flags: [ SHF_WRITE ] -ProgramHeaders: -- Type: PT_LOAD - Flags: [ PF_X, PF_R ] - Sections: - - Section: .text - -#CHECK: 0000000 de ad be ef - -#NON-ALLOC: 0000000 ca fe - -#SIZE: 4 - -#NOBITS: error: '[[INPUT]]': cannot dump section '.bar': it has no contents +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy -O binary -j .text %t %t2 +# RUN: llvm-objcopy -O binary --only-section .text %t %t3 +# RUN: llvm-objcopy --dump-section .text=%t4 %t %t5 +# RUN: llvm-objcopy --dump-section .foo=%t6 %t %t7 +# RUN: not llvm-objcopy --dump-section .bar=%t8 %t %t9 2>&1 | FileCheck %s --check-prefix=NOBITS -DINPUT=%t +# RUN: od -t x1 %t2 | FileCheck %s --ignore-case +# RUN: od -t x1 %t6 | FileCheck %s --ignore-case --check-prefix=NON-ALLOC +# RUN: wc -c %t2 | FileCheck %s --check-prefix=SIZE +# RUN: diff %t2 %t3 +# RUN: diff %t4 %t3 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000001000 + Content: "DEADBEEF" + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_WRITE ] + Content: "CAFE" + - Name: .bar + Type: SHT_NOBITS + Flags: [ SHF_WRITE ] +ProgramHeaders: +- Type: PT_LOAD + Flags: [ PF_X, PF_R ] + Sections: + - Section: .text + +#CHECK: 0000000 de ad be ef + +#NON-ALLOC: 0000000 ca fe + +#SIZE: 4 + +#NOBITS: error: '[[INPUT]]': cannot dump section '.bar': it has no contents diff --git a/llvm/test/tools/llvm-objcopy/ELF/preserve-segment-contents.test b/llvm/test/tools/llvm-objcopy/ELF/preserve-segment-contents.test --- a/llvm/test/tools/llvm-objcopy/ELF/preserve-segment-contents.test +++ b/llvm/test/tools/llvm-objcopy/ELF/preserve-segment-contents.test @@ -1,639 +1,639 @@ -# We want to preserve areas in segments that are not covered by section headers. -# This test shows that we do this for areas at the start of a segment, between -# sections in a segment, and after all sections in a segment. -# To create inputs with arbitrary data in segments, not covered by sections, we -# use yaml2obj to create segments with sections covering all areas, then remove -# some sections in those segments, and finally write over the areas of the -# removed sections using python. - -# blob* sections are the sections that will be removed to create unlabelled -# areas and then overwritten with data to show we preserve the data. - -# RUN: yaml2obj %s -o %t.base -# RUN: llvm-objcopy %t.base %t.stripped --regex -R blob.* -# Show that the removal leaves the bytes as zeroes, as desired, for all our -# test cases. -# RUN: od -t x1 -j 0x2000 -N 24 %t.stripped | FileCheck %s --check-prefix=CHECK1 -DPATTERN="00 00 00 00" -# RUN: od -t x1 -j 0x2100 -N 12 %t.stripped | FileCheck %s --check-prefix=CHECK2 -DPATTERN="00 00 00 00" -# RUN: od -t x1 -j 0x2200 -N 4 %t.stripped | FileCheck %s --check-prefix=CHECK3 -DPATTERN="00 00 00 00" -# RUN: od -t x1 -j 0x2300 -N 12 %t.stripped | FileCheck %s --check-prefix=CHECK4 -DPATTERN="00 00 00 00" -# RUN: od -t x1 -j 0x3000 -N 68 %t.stripped | FileCheck %s --check-prefix=CHECK5 -DPATTERN="00 00 00 00" -# RUN: od -t x1 -j 0x4000 -N 60 %t.stripped | FileCheck %s --check-prefix=CHECK6 -DPATTERN="00 00 00 00" -# RUN: od -t x1 -j 0x5000 -N 60 %t.stripped | FileCheck %s --check-prefix=CHECK7 -DPATTERN="00 00 00 00" - -# RUN: cp %t.stripped %t.in -# RUN: echo "with open('%/t.in', 'rb+') as input:" > %t.py -# RUN: echo " for offset in [" >> %t.py -# RUN: echo " 0x2000, 0x2008, 0x200C, 0x2014, 0x2104, 0x2300," >> %t.py -# RUN: echo " 0x3008, 0x3010, 0x3018, 0x3020, 0x3028, 0x302C, 0x3034, 0x303C," >> %t.py -# RUN: echo " 0x4000, 0x4008, 0x4010, 0x4014, 0x401C, 0x4024, 0x4034," >> %t.py -# RUN: echo " 0x5000, 0x5008, 0x5010, 0x501C, 0x5024, 0x502C, 0x5030, 0x5038]:" >> %t.py -# RUN: echo " input.seek(offset)" >> %t.py -# RUN: echo " input.write(bytearray.fromhex('DEADBEEF'))" >> %t.py -# RUN: %python %t.py -# RUN: llvm-objcopy %t.in %t.out -# RUN: od -t x1 -j 0x2000 -N 24 %t.out | FileCheck %s --check-prefix=CHECK1 -DPATTERN="de ad be ef" -# RUN: od -t x1 -j 0x2100 -N 12 %t.out | FileCheck %s --check-prefix=CHECK2 -DPATTERN="de ad be ef" -# RUN: od -t x1 -j 0x2200 -N 4 %t.out | FileCheck %s --check-prefix=CHECK3 -DPATTERN="de ad be ef" -# RUN: od -t x1 -j 0x2300 -N 12 %t.out | FileCheck %s --check-prefix=CHECK4 -DPATTERN="de ad be ef" -# RUN: od -t x1 -j 0x3000 -N 68 %t.out | FileCheck %s --check-prefix=CHECK5 -DPATTERN="de ad be ef" -# RUN: od -t x1 -j 0x4000 -N 60 %t.out | FileCheck %s --check-prefix=CHECK6 -DPATTERN="de ad be ef" -# RUN: od -t x1 -j 0x5000 -N 60 %t.out | FileCheck %s --check-prefix=CHECK7 -DPATTERN="de ad be ef" - -# CHECK1: [[PATTERN]] 11 22 33 44 [[PATTERN]] [[PATTERN]] -# CHECK1-NEXT: 55 66 77 88 [[PATTERN]] -# CHECK2: 99 00 aa bb [[PATTERN]] cc dd ee ff -# CHECK3: fe fe fe fe -# CHECK4: [[PATTERN]] 00 00 00 00 00 00 00 00 -# CHECK5: ff ff ee ee dd dd cc cc [[PATTERN]] bb bb aa aa -# CHECK5-NEXT: [[PATTERN]] 00 00 99 99 [[PATTERN]] 88 88 77 77 -# CHECK5-NEXT: [[PATTERN]] 66 66 55 55 [[PATTERN]] [[PATTERN]] -# CHECK5-NEXT: 44 44 33 33 [[PATTERN]] 22 22 11 11 [[PATTERN]] -# CHECK5-NEXT: 00 11 22 33 -# CHECK6: [[PATTERN]] 44 55 66 77 [[PATTERN]] 88 99 aa bb -# CHECK6-NEXT: [[PATTERN]] [[PATTERN]] cc dd ee ff [[PATTERN]] -# CHECK6-NEXT: ff ee dd cc [[PATTERN]] bb aa 99 88 77 66 55 44 -# CHECK6-NEXT: 33 22 11 00 [[PATTERN]] 11 11 11 11 -# CHECK7: [[PATTERN]] 12 34 56 78 [[PATTERN]] 90 ab cd ef -# CHECK7-NEXT: [[PATTERN]] fe dc ba 09 87 65 43 21 [[PATTERN]] -# CHECK7-NEXT: 22 22 22 22 [[PATTERN]] 33 33 33 33 [[PATTERN]] -# CHECK7-NEXT: [[PATTERN]] 44 44 44 44 [[PATTERN]] - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: blob1 - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x2000 - AddressAlign: 0x2000 - - Name: section1 - Type: SHT_PROGBITS - Address: 0x2004 - Content: '11223344' - - Name: blob2 - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x2008 - - Name: section2 - Type: SHT_NOBITS - Size: 4 - Address: 0x200C - - Name: blob3 - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x2010 - - Name: section3 - Type: SHT_PROGBITS - Content: '55667788' - Address: 0x2014 - - Name: blob4 - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x2018 - - Name: section4 - Type: SHT_PROGBITS - Content: '9900aabb' - Address: 0x2100 - AddressAlign: 0x100 - - Name: blob5 - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x2104 - - Name: section5 - Type: SHT_PROGBITS - Address: 0x2108 - Content: 'ccddeeff' - - Name: section6 - Type: SHT_PROGBITS - Content: 'fefefefe' - Address: 0x2200 - AddressAlign: 0x100 - - Name: blob6 - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x2300 - AddressAlign: 0x100 - - Name: sectionA - Type: SHT_PROGBITS - Content: 'ffffeeee' - Address: 0x3000 - AddressAlign: 0x1000 - - Name: sectionB - Type: SHT_PROGBITS - Content: 'ddddcccc' - Address: 0x3004 - - Name: blobA - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x3008 - - Name: sectionC - Type: SHT_PROGBITS - Content: 'bbbbaaaa' - Address: 0x300C - - Name: blobB - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x3010 - - Name: sectionD - Type: SHT_PROGBITS - Content: '00009999' - Address: 0x3014 - - Name: blobC - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x3018 - - Name: sectionE - Type: SHT_PROGBITS - Content: '88887777' - Address: 0x301C - - Name: blobD - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x3020 - - Name: sectionF - Type: SHT_PROGBITS - Content: '66665555' - Address: 0x3024 - - Name: blobE - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x3028 - - Name: blobF - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x302C - - Name: sectionG - Type: SHT_PROGBITS - Content: '44443333' - Address: 0x3030 - - Name: blobG - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x3034 - - Name: sectionH - Type: SHT_PROGBITS - Content: '22221111' - Address: 0x3038 - - Name: blobH - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x303C - - Name: sectionI - Type: SHT_PROGBITS - Content: '00112233' - Address: 0x3040 - - Name: blobz - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x4000 - AddressAlign: 0x1000 - - Name: sectionz - Type: SHT_PROGBITS - Content: '44556677' - Address: 0x4004 - - Name: bloby - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x4008 - - Name: sectiony - Type: SHT_PROGBITS - Content: '8899aabb' - Address: 0x400C - - Name: blobx - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x4010 - - Name: blobw - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x4014 - - Name: sectionx - Type: SHT_PROGBITS - Content: 'ccddeeff' - Address: 0x4018 - - Name: blobv - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x401C - - Name: sectionw - Type: SHT_PROGBITS - Content: 'ffeeddcc' - Address: 0x4020 - - Name: blobu - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x4024 - - Name: sectionv - Type: SHT_PROGBITS - Content: 'bbaa9988' - Address: 0x4028 - - Name: sectionu - Type: SHT_PROGBITS - Content: '77665544' - Address: 0x402C - - Name: sectiont - Type: SHT_PROGBITS - Content: '33221100' - Address: 0x4030 - - Name: blobt - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x4034 - - Name: sections - Type: SHT_PROGBITS - Content: '11111111' - Address: 0x4038 - - Name: bloba - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x5000 - AddressAlign: 0x1000 - - Name: sectiona - Type: SHT_PROGBITS - Content: '12345678' - Address: 0x5004 - - Name: blobb - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x5008 - - Name: sectionb - Type: SHT_PROGBITS - Content: '90abcdef' - Address: 0x500C - - Name: blobc - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x5010 - - Name: sectionc - Type: SHT_PROGBITS - Content: 'fedcba09' - Address: 0x5014 - - Name: sectiond - Type: SHT_PROGBITS - Content: '87654321' - Address: 0x5018 - - Name: blobd - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x501C - - Name: sectione - Type: SHT_PROGBITS - Content: '22222222' - Address: 0x5020 - - Name: blobe - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x5024 - - Name: sectionf - Type: SHT_PROGBITS - Content: '33333333' - Address: 0x5028 - - Name: blobf - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x502C - - Name: blobg - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x5030 - - Name: sectiong - Type: SHT_PROGBITS - Content: '44444444' - Address: 0x5034 - - Name: blobh - Type: SHT_PROGBITS - Content: 'abbababa' - Address: 0x5038 -ProgramHeaders: - # First segment has unlabelled space at start and end. - - Type: 0x6ABCDEF0 # Non-specific segment type. - VAddr: 0x2000 - PAddr: 0x2000 - Align: 0x2000 - Sections: - - Section: blob1 - - Section: section1 - - Section: blob2 - - Section: section2 # nobits - - Section: blob3 - - Section: section3 - - Section: blob4 - # Second segment has sections at start and end. - - Type: 0x6ABCDEF0 - VAddr: 0x2100 - PAddr: 0x2100 - Align: 0x100 - Sections: - - Section: section4 - - Section: blob5 - - Section: section5 - # Third segment is all covered by a section. - - Type: 0x6ABCDEF0 - VAddr: 0x2200 - PAddr: 0x2200 - Align: 0x100 - Sections: - - Section: section6 - # Fourth segment has no sections (after removing blob headers). - - Type: 0x6ABCDEF0 - VAddr: 0x2300 - PAddr: 0x2300 - Align: 0x100 - Sections: - - Section: blob6 - # Fifth segment is empty. - - Type: 0x6ABCDEF0 - VAddr: 0x2308 - PAddr: 0x2308 - Offset: 0x2308 - - # The next few segments test behaviour of fully nested segments. - # Sixth segment is the "parent" segment. - - Type: 0x6ABCDEF0 - VAddr: 0x3000 - PAddr: 0x3000 - Align: 0x1000 - Sections: - - Section: sectionA - - Section: sectionB - - Section: blobA - - Section: sectionC - - Section: blobB - - Section: sectionD - - Section: blobC - - Section: sectionE - - Section: blobD - - Section: sectionF - - Section: blobE - - Section: blobF - - Section: sectionG - - Section: blobG - - Section: sectionH - - Section: blobH - - Section: sectionI - # Seventh segment is empty and nested. - - Type: 0x6ABCDEF0 - VAddr: 0x3002 - PAddr: 0x3002 - Offset: 0x3002 - # Eighth segment contains only a section and is nested. - - Type: 0x6ABCDEF0 - VAddr: 0x3004 - PAddr: 0x3004 - Sections: - - Section: sectionB - # Ninth segment contains only unlabelled space and is nested. - - Type: 0x6ABCDEF0 - VAddr: 0x3008 - PAddr: 0x3008 - Sections: - - Section: blobA - # Tenth segment contains two sections with space between and is nested. - - Type: 0x6ABCDEF0 - VAddr: 0x300C - PAddr: 0x300C - Sections: - - Section: sectionC - - Section: blobB - - Section: sectionD - # Eleventh segment contains two sections with space between and at ends and is nested. - - Type: 0x6ABCDEF0 - VAddr: 0x3018 - PAddr: 0x3018 - Sections: - - Section: blobC - - Section: sectionE - - Section: blobD - - Section: sectionF - - Section: blobE - # Twelfth segment contains one section with space at ends adjacent to space in parent segment. - - Type: 0x6ABCDEF0 - VAddr: 0x302E - PAddr: 0x302E - Offset: 0x302E - FileSize: 8 - Sections: - - Section: sectionG - # Thirteenth segment contains overlaps sections at either end in parent segment. - - Type: 0x6ABCDEF0 - VAddr: 0x303A - PAddr: 0x303A - Offset: 0x303A - FileSize: 0x8 - Sections: - - Section: blobH - - # The next batch of segments are segments that only partially overlap other segments. - - # Segment14: |-unlabelled-|-Sec-| - # Segment15: |--|-Sec-|-unlabelled-| - - Type: 0x6ABCDEF0 - VAddr: 0x4000 - PAddr: 0x4000 - Sections: - - Section: blobz - - Section: sectionz - - Type: 0x6ABCDEF0 - VAddr: 0x4002 - PAddr: 0x4002 - Offset: 0x4002 - Sections: - - Section: sectionz - - Section: bloby - - # Segment16: |-Sec-|--| - # Segment17: |--|----unlabelled---| - - Type: 0x6ABCDEF0 - VAddr: 0x400C - PAddr: 0x400C - FileSize: 6 - Sections: - - Section: sectiony - - Type: 0x6ABCDEF0 - VAddr: 0x400E - PAddr: 0x400E - Offset: 0x400E - Sections: - - Section: blobx - - # Segment18: |-unlabelled-|-Sec-| - # Segment19: |-Sec-|-unlabelled-| - - Type: 0x6ABCDEF0 - VAddr: 0x4014 - PAddr: 0x4014 - Sections: - - Section: blobw - - Section: sectionx - - Type: 0x6ABCDEF0 - VAddr: 0x4018 - PAddr: 0x4018 - Sections: - - Section: sectionx - - Section: blobv - - # Segment20: |-Sec-| - # Segment21: |--|-unlabelled-|-Sec-| - - Type: 0x6ABCDEF0 - VAddr: 0x4020 - PAddr: 0x4020 - Sections: - - Section: sectionw - - Type: 0x6ABCDEF0 - VAddr: 0x4022 - PAddr: 0x4022 - Offset: 0x4022 - Sections: - - Section: blobu - - Section: sectionv - - # Segment22: |-Sec-| - # Segment23: |--|-Sec-| - - Type: 0x6ABCDEF0 - VAddr: 0x402C - PAddr: 0x402C - Sections: - - Section: sectionu - - Type: 0x6ABCDEF0 - VAddr: 0x402E - PAddr: 0x402E - Offset: 0x402E - Sections: - - Section: sectiont - - # Segment24: |-unlabelled-|--| - # Segment25: |--Sec--| - - Type: 0x6ABCDEF0 - VAddr: 0x4034 - PAddr: 0x4034 - FileSize: 6 - Sections: - - Section: blobt - - Type: 0x6ABCDEF0 - VAddr: 0x4038 - PAddr: 0x4038 - Sections: - - Section: sections - - # The next batch of segments represent groups of three nested/overlapping segments, - # with one parent segment containing two overlapping segments. - - # Segment26: |-unlabelled-|-Sec-|-unlabelled-| - # Segment27: |------------|--| - # Segment28: |-Sec-|------------| - - Type: 0x6ABCDEF0 - VAddr: 0x5000 - PAddr: 0x5000 - Align: 0x1000 - Sections: - - Section: bloba - - Section: sectiona - - Section: blobb - - Type: 0x6ABCDEF0 - VAddr: 0x5000 - PAddr: 0x5000 - FileSize: 6 - Sections: - - Section: bloba - - Type: 0x6ABCDEF0 - VAddr: 0x5004 - PAddr: 0x5004 - Sections: - - Section: sectiona - - Section: blobb - - # Segment29: |-Sec-|-unlabelled-|-Sec-| - # Segment30: |-Sec-|--------| - # Segment31: |---------|-Sec-| - - Type: 0x6ABCDEF0 - VAddr: 0x500C - PAddr: 0x500C - Sections: - - Section: sectionb - - Section: blobc - - Section: sectionc - - Type: 0x6ABCDEF0 - VAddr: 0x500C - PAddr: 0x500C - FileSize: 7 - Sections: - - Section: sectionb - - Type: 0x6ABCDEF0 - VAddr: 0x5011 - PAddr: 0x5011 - Offset: 0x5011 - Sections: - - Section: sectionc - - # Segment32: |-Sec-|-unlabelled-|-Sec-| - # Segment33: |-Sec-|------------| - # Segment34: |------------|-Sec-| - - Type: 0x6ABCDEF0 - VAddr: 0x5018 - PAddr: 0x5018 - Sections: - - Section: sectiond - - Section: blobd - - Section: sectione - - Type: 0x6ABCDEF0 - VAddr: 0x5018 - PAddr: 0x5018 - Sections: - - Section: sectiond - - Section: blobd - - Type: 0x6ABCDEF0 - VAddr: 0x501C - PAddr: 0x501C - Sections: - - Section: blobd - - Section: sectione - - # Segment35: |-unlabelled-|-Sec-|-unlabelled-| - # Segment36: |------------|-Sec-| - # Segment37: |-Sec-|------------| - - Type: 0x6ABCDEF0 - VAddr: 0x5024 - PAddr: 0x5024 - Sections: - - Section: blobe - - Section: sectionf - - Section: blobf - - Type: 0x6ABCDEF0 - VAddr: 0x5024 - PAddr: 0x5024 - Sections: - - Section: blobe - - Section: sectionf - - Type: 0x6ABCDEF0 - VAddr: 0x5028 - PAddr: 0x5028 - Sections: - - Section: sectionf - - Section: blobf - - # Segment38: |-unlabelled-|-Sec-|-unlabelled-| - # Segment39: |------------|---| - # Segment40: |---|------------| - - Type: 0x6ABCDEF0 - VAddr: 0x5030 - PAddr: 0x5030 - Sections: - - Section: blobg - - Section: sectiong - - Section: blobh - - Type: 0x6ABCDEF0 - VAddr: 0x5030 - PAddr: 0x5030 - FileSize: 7 - Sections: - - Section: blobg - - Type: 0x6ABCDEF0 - VAddr: 0x5035 - PAddr: 0x5035 - Offset: 0x5035 - Sections: - - Section: blobh +# We want to preserve areas in segments that are not covered by section headers. +# This test shows that we do this for areas at the start of a segment, between +# sections in a segment, and after all sections in a segment. +# To create inputs with arbitrary data in segments, not covered by sections, we +# use yaml2obj to create segments with sections covering all areas, then remove +# some sections in those segments, and finally write over the areas of the +# removed sections using python. + +# blob* sections are the sections that will be removed to create unlabelled +# areas and then overwritten with data to show we preserve the data. + +# RUN: yaml2obj %s -o %t.base +# RUN: llvm-objcopy %t.base %t.stripped --regex -R blob.* +# Show that the removal leaves the bytes as zeroes, as desired, for all our +# test cases. +# RUN: od -t x1 -j 0x2000 -N 24 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK1 -DPATTERN="00 00 00 00" +# RUN: od -t x1 -j 0x2100 -N 12 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK2 -DPATTERN="00 00 00 00" +# RUN: od -t x1 -j 0x2200 -N 4 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK3 -DPATTERN="00 00 00 00" +# RUN: od -t x1 -j 0x2300 -N 12 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK4 -DPATTERN="00 00 00 00" +# RUN: od -t x1 -j 0x3000 -N 68 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK5 -DPATTERN="00 00 00 00" +# RUN: od -t x1 -j 0x4000 -N 60 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK6 -DPATTERN="00 00 00 00" +# RUN: od -t x1 -j 0x5000 -N 60 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK7 -DPATTERN="00 00 00 00" + +# RUN: cp %t.stripped %t.in +# RUN: echo "with open('%/t.in', 'rb+') as input:" > %t.py +# RUN: echo " for offset in [" >> %t.py +# RUN: echo " 0x2000, 0x2008, 0x200C, 0x2014, 0x2104, 0x2300," >> %t.py +# RUN: echo " 0x3008, 0x3010, 0x3018, 0x3020, 0x3028, 0x302C, 0x3034, 0x303C," >> %t.py +# RUN: echo " 0x4000, 0x4008, 0x4010, 0x4014, 0x401C, 0x4024, 0x4034," >> %t.py +# RUN: echo " 0x5000, 0x5008, 0x5010, 0x501C, 0x5024, 0x502C, 0x5030, 0x5038]:" >> %t.py +# RUN: echo " input.seek(offset)" >> %t.py +# RUN: echo " input.write(bytearray.fromhex('DEADBEEF'))" >> %t.py +# RUN: %python %t.py +# RUN: llvm-objcopy %t.in %t.out +# RUN: od -t x1 -j 0x2000 -N 24 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK1 -DPATTERN="de ad be ef" +# RUN: od -t x1 -j 0x2100 -N 12 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK2 -DPATTERN="de ad be ef" +# RUN: od -t x1 -j 0x2200 -N 4 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK3 -DPATTERN="de ad be ef" +# RUN: od -t x1 -j 0x2300 -N 12 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK4 -DPATTERN="de ad be ef" +# RUN: od -t x1 -j 0x3000 -N 68 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK5 -DPATTERN="de ad be ef" +# RUN: od -t x1 -j 0x4000 -N 60 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK6 -DPATTERN="de ad be ef" +# RUN: od -t x1 -j 0x5000 -N 60 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK7 -DPATTERN="de ad be ef" + +# CHECK1: [[PATTERN]] 11 22 33 44 [[PATTERN]] [[PATTERN]] +# CHECK1-NEXT: 55 66 77 88 [[PATTERN]] +# CHECK2: 99 00 aa bb [[PATTERN]] cc dd ee ff +# CHECK3: fe fe fe fe +# CHECK4: [[PATTERN]] 00 00 00 00 00 00 00 00 +# CHECK5: ff ff ee ee dd dd cc cc [[PATTERN]] bb bb aa aa +# CHECK5-NEXT: [[PATTERN]] 00 00 99 99 [[PATTERN]] 88 88 77 77 +# CHECK5-NEXT: [[PATTERN]] 66 66 55 55 [[PATTERN]] [[PATTERN]] +# CHECK5-NEXT: 44 44 33 33 [[PATTERN]] 22 22 11 11 [[PATTERN]] +# CHECK5-NEXT: 00 11 22 33 +# CHECK6: [[PATTERN]] 44 55 66 77 [[PATTERN]] 88 99 aa bb +# CHECK6-NEXT: [[PATTERN]] [[PATTERN]] cc dd ee ff [[PATTERN]] +# CHECK6-NEXT: ff ee dd cc [[PATTERN]] bb aa 99 88 77 66 55 44 +# CHECK6-NEXT: 33 22 11 00 [[PATTERN]] 11 11 11 11 +# CHECK7: [[PATTERN]] 12 34 56 78 [[PATTERN]] 90 ab cd ef +# CHECK7-NEXT: [[PATTERN]] fe dc ba 09 87 65 43 21 [[PATTERN]] +# CHECK7-NEXT: 22 22 22 22 [[PATTERN]] 33 33 33 33 [[PATTERN]] +# CHECK7-NEXT: [[PATTERN]] 44 44 44 44 [[PATTERN]] + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: blob1 + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x2000 + AddressAlign: 0x2000 + - Name: section1 + Type: SHT_PROGBITS + Address: 0x2004 + Content: '11223344' + - Name: blob2 + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x2008 + - Name: section2 + Type: SHT_NOBITS + Size: 4 + Address: 0x200C + - Name: blob3 + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x2010 + - Name: section3 + Type: SHT_PROGBITS + Content: '55667788' + Address: 0x2014 + - Name: blob4 + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x2018 + - Name: section4 + Type: SHT_PROGBITS + Content: '9900aabb' + Address: 0x2100 + AddressAlign: 0x100 + - Name: blob5 + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x2104 + - Name: section5 + Type: SHT_PROGBITS + Address: 0x2108 + Content: 'ccddeeff' + - Name: section6 + Type: SHT_PROGBITS + Content: 'fefefefe' + Address: 0x2200 + AddressAlign: 0x100 + - Name: blob6 + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x2300 + AddressAlign: 0x100 + - Name: sectionA + Type: SHT_PROGBITS + Content: 'ffffeeee' + Address: 0x3000 + AddressAlign: 0x1000 + - Name: sectionB + Type: SHT_PROGBITS + Content: 'ddddcccc' + Address: 0x3004 + - Name: blobA + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x3008 + - Name: sectionC + Type: SHT_PROGBITS + Content: 'bbbbaaaa' + Address: 0x300C + - Name: blobB + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x3010 + - Name: sectionD + Type: SHT_PROGBITS + Content: '00009999' + Address: 0x3014 + - Name: blobC + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x3018 + - Name: sectionE + Type: SHT_PROGBITS + Content: '88887777' + Address: 0x301C + - Name: blobD + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x3020 + - Name: sectionF + Type: SHT_PROGBITS + Content: '66665555' + Address: 0x3024 + - Name: blobE + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x3028 + - Name: blobF + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x302C + - Name: sectionG + Type: SHT_PROGBITS + Content: '44443333' + Address: 0x3030 + - Name: blobG + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x3034 + - Name: sectionH + Type: SHT_PROGBITS + Content: '22221111' + Address: 0x3038 + - Name: blobH + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x303C + - Name: sectionI + Type: SHT_PROGBITS + Content: '00112233' + Address: 0x3040 + - Name: blobz + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x4000 + AddressAlign: 0x1000 + - Name: sectionz + Type: SHT_PROGBITS + Content: '44556677' + Address: 0x4004 + - Name: bloby + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x4008 + - Name: sectiony + Type: SHT_PROGBITS + Content: '8899aabb' + Address: 0x400C + - Name: blobx + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x4010 + - Name: blobw + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x4014 + - Name: sectionx + Type: SHT_PROGBITS + Content: 'ccddeeff' + Address: 0x4018 + - Name: blobv + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x401C + - Name: sectionw + Type: SHT_PROGBITS + Content: 'ffeeddcc' + Address: 0x4020 + - Name: blobu + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x4024 + - Name: sectionv + Type: SHT_PROGBITS + Content: 'bbaa9988' + Address: 0x4028 + - Name: sectionu + Type: SHT_PROGBITS + Content: '77665544' + Address: 0x402C + - Name: sectiont + Type: SHT_PROGBITS + Content: '33221100' + Address: 0x4030 + - Name: blobt + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x4034 + - Name: sections + Type: SHT_PROGBITS + Content: '11111111' + Address: 0x4038 + - Name: bloba + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x5000 + AddressAlign: 0x1000 + - Name: sectiona + Type: SHT_PROGBITS + Content: '12345678' + Address: 0x5004 + - Name: blobb + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x5008 + - Name: sectionb + Type: SHT_PROGBITS + Content: '90abcdef' + Address: 0x500C + - Name: blobc + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x5010 + - Name: sectionc + Type: SHT_PROGBITS + Content: 'fedcba09' + Address: 0x5014 + - Name: sectiond + Type: SHT_PROGBITS + Content: '87654321' + Address: 0x5018 + - Name: blobd + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x501C + - Name: sectione + Type: SHT_PROGBITS + Content: '22222222' + Address: 0x5020 + - Name: blobe + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x5024 + - Name: sectionf + Type: SHT_PROGBITS + Content: '33333333' + Address: 0x5028 + - Name: blobf + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x502C + - Name: blobg + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x5030 + - Name: sectiong + Type: SHT_PROGBITS + Content: '44444444' + Address: 0x5034 + - Name: blobh + Type: SHT_PROGBITS + Content: 'abbababa' + Address: 0x5038 +ProgramHeaders: + # First segment has unlabelled space at start and end. + - Type: 0x6ABCDEF0 # Non-specific segment type. + VAddr: 0x2000 + PAddr: 0x2000 + Align: 0x2000 + Sections: + - Section: blob1 + - Section: section1 + - Section: blob2 + - Section: section2 # nobits + - Section: blob3 + - Section: section3 + - Section: blob4 + # Second segment has sections at start and end. + - Type: 0x6ABCDEF0 + VAddr: 0x2100 + PAddr: 0x2100 + Align: 0x100 + Sections: + - Section: section4 + - Section: blob5 + - Section: section5 + # Third segment is all covered by a section. + - Type: 0x6ABCDEF0 + VAddr: 0x2200 + PAddr: 0x2200 + Align: 0x100 + Sections: + - Section: section6 + # Fourth segment has no sections (after removing blob headers). + - Type: 0x6ABCDEF0 + VAddr: 0x2300 + PAddr: 0x2300 + Align: 0x100 + Sections: + - Section: blob6 + # Fifth segment is empty. + - Type: 0x6ABCDEF0 + VAddr: 0x2308 + PAddr: 0x2308 + Offset: 0x2308 + + # The next few segments test behaviour of fully nested segments. + # Sixth segment is the "parent" segment. + - Type: 0x6ABCDEF0 + VAddr: 0x3000 + PAddr: 0x3000 + Align: 0x1000 + Sections: + - Section: sectionA + - Section: sectionB + - Section: blobA + - Section: sectionC + - Section: blobB + - Section: sectionD + - Section: blobC + - Section: sectionE + - Section: blobD + - Section: sectionF + - Section: blobE + - Section: blobF + - Section: sectionG + - Section: blobG + - Section: sectionH + - Section: blobH + - Section: sectionI + # Seventh segment is empty and nested. + - Type: 0x6ABCDEF0 + VAddr: 0x3002 + PAddr: 0x3002 + Offset: 0x3002 + # Eighth segment contains only a section and is nested. + - Type: 0x6ABCDEF0 + VAddr: 0x3004 + PAddr: 0x3004 + Sections: + - Section: sectionB + # Ninth segment contains only unlabelled space and is nested. + - Type: 0x6ABCDEF0 + VAddr: 0x3008 + PAddr: 0x3008 + Sections: + - Section: blobA + # Tenth segment contains two sections with space between and is nested. + - Type: 0x6ABCDEF0 + VAddr: 0x300C + PAddr: 0x300C + Sections: + - Section: sectionC + - Section: blobB + - Section: sectionD + # Eleventh segment contains two sections with space between and at ends and is nested. + - Type: 0x6ABCDEF0 + VAddr: 0x3018 + PAddr: 0x3018 + Sections: + - Section: blobC + - Section: sectionE + - Section: blobD + - Section: sectionF + - Section: blobE + # Twelfth segment contains one section with space at ends adjacent to space in parent segment. + - Type: 0x6ABCDEF0 + VAddr: 0x302E + PAddr: 0x302E + Offset: 0x302E + FileSize: 8 + Sections: + - Section: sectionG + # Thirteenth segment contains overlaps sections at either end in parent segment. + - Type: 0x6ABCDEF0 + VAddr: 0x303A + PAddr: 0x303A + Offset: 0x303A + FileSize: 0x8 + Sections: + - Section: blobH + + # The next batch of segments are segments that only partially overlap other segments. + + # Segment14: |-unlabelled-|-Sec-| + # Segment15: |--|-Sec-|-unlabelled-| + - Type: 0x6ABCDEF0 + VAddr: 0x4000 + PAddr: 0x4000 + Sections: + - Section: blobz + - Section: sectionz + - Type: 0x6ABCDEF0 + VAddr: 0x4002 + PAddr: 0x4002 + Offset: 0x4002 + Sections: + - Section: sectionz + - Section: bloby + + # Segment16: |-Sec-|--| + # Segment17: |--|----unlabelled---| + - Type: 0x6ABCDEF0 + VAddr: 0x400C + PAddr: 0x400C + FileSize: 6 + Sections: + - Section: sectiony + - Type: 0x6ABCDEF0 + VAddr: 0x400E + PAddr: 0x400E + Offset: 0x400E + Sections: + - Section: blobx + + # Segment18: |-unlabelled-|-Sec-| + # Segment19: |-Sec-|-unlabelled-| + - Type: 0x6ABCDEF0 + VAddr: 0x4014 + PAddr: 0x4014 + Sections: + - Section: blobw + - Section: sectionx + - Type: 0x6ABCDEF0 + VAddr: 0x4018 + PAddr: 0x4018 + Sections: + - Section: sectionx + - Section: blobv + + # Segment20: |-Sec-| + # Segment21: |--|-unlabelled-|-Sec-| + - Type: 0x6ABCDEF0 + VAddr: 0x4020 + PAddr: 0x4020 + Sections: + - Section: sectionw + - Type: 0x6ABCDEF0 + VAddr: 0x4022 + PAddr: 0x4022 + Offset: 0x4022 + Sections: + - Section: blobu + - Section: sectionv + + # Segment22: |-Sec-| + # Segment23: |--|-Sec-| + - Type: 0x6ABCDEF0 + VAddr: 0x402C + PAddr: 0x402C + Sections: + - Section: sectionu + - Type: 0x6ABCDEF0 + VAddr: 0x402E + PAddr: 0x402E + Offset: 0x402E + Sections: + - Section: sectiont + + # Segment24: |-unlabelled-|--| + # Segment25: |--Sec--| + - Type: 0x6ABCDEF0 + VAddr: 0x4034 + PAddr: 0x4034 + FileSize: 6 + Sections: + - Section: blobt + - Type: 0x6ABCDEF0 + VAddr: 0x4038 + PAddr: 0x4038 + Sections: + - Section: sections + + # The next batch of segments represent groups of three nested/overlapping segments, + # with one parent segment containing two overlapping segments. + + # Segment26: |-unlabelled-|-Sec-|-unlabelled-| + # Segment27: |------------|--| + # Segment28: |-Sec-|------------| + - Type: 0x6ABCDEF0 + VAddr: 0x5000 + PAddr: 0x5000 + Align: 0x1000 + Sections: + - Section: bloba + - Section: sectiona + - Section: blobb + - Type: 0x6ABCDEF0 + VAddr: 0x5000 + PAddr: 0x5000 + FileSize: 6 + Sections: + - Section: bloba + - Type: 0x6ABCDEF0 + VAddr: 0x5004 + PAddr: 0x5004 + Sections: + - Section: sectiona + - Section: blobb + + # Segment29: |-Sec-|-unlabelled-|-Sec-| + # Segment30: |-Sec-|--------| + # Segment31: |---------|-Sec-| + - Type: 0x6ABCDEF0 + VAddr: 0x500C + PAddr: 0x500C + Sections: + - Section: sectionb + - Section: blobc + - Section: sectionc + - Type: 0x6ABCDEF0 + VAddr: 0x500C + PAddr: 0x500C + FileSize: 7 + Sections: + - Section: sectionb + - Type: 0x6ABCDEF0 + VAddr: 0x5011 + PAddr: 0x5011 + Offset: 0x5011 + Sections: + - Section: sectionc + + # Segment32: |-Sec-|-unlabelled-|-Sec-| + # Segment33: |-Sec-|------------| + # Segment34: |------------|-Sec-| + - Type: 0x6ABCDEF0 + VAddr: 0x5018 + PAddr: 0x5018 + Sections: + - Section: sectiond + - Section: blobd + - Section: sectione + - Type: 0x6ABCDEF0 + VAddr: 0x5018 + PAddr: 0x5018 + Sections: + - Section: sectiond + - Section: blobd + - Type: 0x6ABCDEF0 + VAddr: 0x501C + PAddr: 0x501C + Sections: + - Section: blobd + - Section: sectione + + # Segment35: |-unlabelled-|-Sec-|-unlabelled-| + # Segment36: |------------|-Sec-| + # Segment37: |-Sec-|------------| + - Type: 0x6ABCDEF0 + VAddr: 0x5024 + PAddr: 0x5024 + Sections: + - Section: blobe + - Section: sectionf + - Section: blobf + - Type: 0x6ABCDEF0 + VAddr: 0x5024 + PAddr: 0x5024 + Sections: + - Section: blobe + - Section: sectionf + - Type: 0x6ABCDEF0 + VAddr: 0x5028 + PAddr: 0x5028 + Sections: + - Section: sectionf + - Section: blobf + + # Segment38: |-unlabelled-|-Sec-|-unlabelled-| + # Segment39: |------------|---| + # Segment40: |---|------------| + - Type: 0x6ABCDEF0 + VAddr: 0x5030 + PAddr: 0x5030 + Sections: + - Section: blobg + - Section: sectiong + - Section: blobh + - Type: 0x6ABCDEF0 + VAddr: 0x5030 + PAddr: 0x5030 + FileSize: 7 + Sections: + - Section: blobg + - Type: 0x6ABCDEF0 + VAddr: 0x5035 + PAddr: 0x5035 + Offset: 0x5035 + Sections: + - Section: blobh diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-all-gnu.test b/llvm/test/tools/llvm-objcopy/ELF/strip-all-gnu.test --- a/llvm/test/tools/llvm-objcopy/ELF/strip-all-gnu.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-all-gnu.test @@ -1,74 +1,74 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy --strip-all-gnu %t %t2 -# RUN: llvm-strip --strip-all-gnu %t -o %t3 -# RUN: llvm-readobj --file-headers --sections %t2 | FileCheck %s -# RUN: cmp %t2 %t3 - -# Show that the debug section in a segment was removed, to match GNU. -# First validate that the offset in use is correct. -# RUN: llvm-objcopy %t %t4 -# RUN: od -t x1 -N 4 -j 120 %t4 | FileCheck %s --check-prefix=COPY-BYTES -# RUN: od -t x1 -N 4 -j 120 %t2 | FileCheck %s --check-prefix=STRIP-BYTES - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .debug_in_segment - Type: SHT_PROGBITS - Flags: [ ] - Content: "deadbeef" - - Name: .dynstr - Type: SHT_STRTAB - Flags: [ SHF_ALLOC ] - - Name: .symtab.dyn - Type: SHT_SYMTAB - Flags: [ SHF_ALLOC ] - Type: SHT_NOBITS - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Size: 4 - - Name: .debug_info - Type: SHT_PROGBITS - Flags: [ ] - AddressAlign: 0x1 - Size: 4 - - Name: .debug_loc - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC ] - AddressAlign: 0x1 - Size: 4 - - Name: .comment - Type: SHT_PROGBITS - - Name: .random_section_name - Type: SHT_PROGBITS - - Name: .debug_not_a_real_debug_section - Type: SHT_PROGBITS - - Name: .rel.text - Type: SHT_REL - Info: .text - - Name: .rela.text - Type: SHT_RELA - Info: .text -ProgramHeaders: - # Use an arbitrary segment type to show that the segment type is unimportant. - - Type: 0x61234567 - Sections: - - Section: .debug_in_segment - -# CHECK: SectionHeaderCount: 8 - -# CHECK: Name: .dynstr -# CHECK: Name: .symtab.dyn -# CHECK: Name: .text -# CHECK: Name: .debug_loc -# CHECK: Name: .comment -# CHECK: Name: .random_section_name -# CHECK: Name: .shstrtab - -# COPY-BYTES: de ad be ef -# STRIP-BYTES: 00 00 00 00 +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy --strip-all-gnu %t %t2 +# RUN: llvm-strip --strip-all-gnu %t -o %t3 +# RUN: llvm-readobj --file-headers --sections %t2 | FileCheck %s +# RUN: cmp %t2 %t3 + +# Show that the debug section in a segment was removed, to match GNU. +# First validate that the offset in use is correct. +# RUN: llvm-objcopy %t %t4 +# RUN: od -t x1 -N 4 -j 120 %t4 | FileCheck %s --ignore-case --check-prefix=COPY-BYTES +# RUN: od -t x1 -N 4 -j 120 %t2 | FileCheck %s --ignore-case --check-prefix=STRIP-BYTES + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .debug_in_segment + Type: SHT_PROGBITS + Flags: [ ] + Content: "deadbeef" + - Name: .dynstr + Type: SHT_STRTAB + Flags: [ SHF_ALLOC ] + - Name: .symtab.dyn + Type: SHT_SYMTAB + Flags: [ SHF_ALLOC ] + Type: SHT_NOBITS + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Size: 4 + - Name: .debug_info + Type: SHT_PROGBITS + Flags: [ ] + AddressAlign: 0x1 + Size: 4 + - Name: .debug_loc + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x1 + Size: 4 + - Name: .comment + Type: SHT_PROGBITS + - Name: .random_section_name + Type: SHT_PROGBITS + - Name: .debug_not_a_real_debug_section + Type: SHT_PROGBITS + - Name: .rel.text + Type: SHT_REL + Info: .text + - Name: .rela.text + Type: SHT_RELA + Info: .text +ProgramHeaders: + # Use an arbitrary segment type to show that the segment type is unimportant. + - Type: 0x61234567 + Sections: + - Section: .debug_in_segment + +# CHECK: SectionHeaderCount: 8 + +# CHECK: Name: .dynstr +# CHECK: Name: .symtab.dyn +# CHECK: Name: .text +# CHECK: Name: .debug_loc +# CHECK: Name: .comment +# CHECK: Name: .random_section_name +# CHECK: Name: .shstrtab + +# COPY-BYTES: de ad be ef +# STRIP-BYTES: 00 00 00 00 diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-sections.test b/llvm/test/tools/llvm-objcopy/ELF/strip-sections.test --- a/llvm/test/tools/llvm-objcopy/ELF/strip-sections.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-sections.test @@ -1,88 +1,88 @@ -# RUN: yaml2obj %s > %t -# RUN: llvm-objcopy --strip-sections %t %t2 -# RUN: llvm-readobj --file-headers --program-headers %t2 | FileCheck %s -# RUN: od -t x1 -j 4096 -N 12 %t2 | FileCheck %s --check-prefix=DATA - -## Sanity check the DATA-NOT line by showing that "fe ed fa ce" appears -## if --strip-sections is not specified. -# RUN: llvm-objcopy %t %t3 -# RUN: od -t x1 -j 4096 -N 12 %t3 | FileCheck %s --check-prefix=VALIDATE - -## Check that llvm-strip --strip-sections is equivalent to -## llvm-objcopy --strip-sections. -# RUN: llvm-strip --strip-sections %t -o %t4 -# RUN: cmp %t2 %t4 - -!ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - AddressAlign: 0x0000000000001000 - Content: "DEADBEEF" - - Name: .non_alloc_in_segment - Type: SHT_PROGBITS - Flags: [ ] - Content: "CAFEBABE" - - Name: .non_alloc_not_in_segment - Type: SHT_PROGBITS - Flags: [ ] - Content: "FEEDFACE" -ProgramHeaders: -- Type: PT_LOAD - Flags: [ PF_X, PF_R ] - Sections: - - Section: .text - - Section: .non_alloc_in_segment - -# DATA: {{^[^[:blank:]]+}} de ad be ef ca fe ba be -# DATA-NOT: fe ed fa ce - -# VALIDATE: {{^[^[:blank:]]+}} de ad be ef ca fe ba be fe ed fa ce - -# CHECK: ElfHeader { -# CHECK-NEXT: Ident { -# CHECK-NEXT: Magic: (7F 45 4C 46) -# CHECK-NEXT: Class: 64-bit (0x2) -# CHECK-NEXT: DataEncoding: LittleEndian (0x1) -# CHECK-NEXT: FileVersion: 1 -# CHECK-NEXT: OS/ABI: SystemV (0x0) -# CHECK-NEXT: ABIVersion: 0 -# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) -# CHECK-NEXT: } -# CHECK-NEXT: Type: Executable (0x2) -# CHECK-NEXT: Machine: EM_X86_64 (0x3E) -# CHECK-NEXT: Version: 1 -# CHECK-NEXT: Entry: 0x0 -# CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x0 -# CHECK-NEXT: Flags [ (0x0) -# CHECK-NEXT: ] -# CHECK-NEXT: HeaderSize: 64 -# CHECK-NEXT: ProgramHeaderEntrySize: 56 -# CHECK-NEXT: ProgramHeaderCount: 1 -# CHECK-NEXT: SectionHeaderEntrySize: 0 -# CHECK-NEXT: SectionHeaderCount: 0 -# CHECK-NEXT: StringTableSectionIndex: 0 -# CHECK-NEXT: } - -# CHECK: ProgramHeaders [ -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x0 -# CHECK-NEXT: PhysicalAddress: 0x0 -# CHECK-NEXT: FileSize: 8 -# CHECK-NEXT: MemSize: 8 -# CHECK-NEXT: Flags [ (0x5) -# CHECK-NEXT: PF_R (0x4) -# CHECK-NEXT: PF_X (0x1) -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 4096 -# CHECK-NEXT: } -# CHECK-NEXT: ] +# RUN: yaml2obj %s > %t +# RUN: llvm-objcopy --strip-sections %t %t2 +# RUN: llvm-readobj --file-headers --program-headers %t2 | FileCheck %s +# RUN: od -t x1 -j 4096 -N 12 %t2 | FileCheck %s --ignore-case --check-prefix=DATA + +## Sanity check the DATA-NOT line by showing that "fe ed fa ce" appears +## if --strip-sections is not specified. +# RUN: llvm-objcopy %t %t3 +# RUN: od -t x1 -j 4096 -N 12 %t3 | FileCheck %s --ignore-case --check-prefix=VALIDATE + +## Check that llvm-strip --strip-sections is equivalent to +## llvm-objcopy --strip-sections. +# RUN: llvm-strip --strip-sections %t -o %t4 +# RUN: cmp %t2 %t4 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000001000 + Content: "DEADBEEF" + - Name: .non_alloc_in_segment + Type: SHT_PROGBITS + Flags: [ ] + Content: "CAFEBABE" + - Name: .non_alloc_not_in_segment + Type: SHT_PROGBITS + Flags: [ ] + Content: "FEEDFACE" +ProgramHeaders: +- Type: PT_LOAD + Flags: [ PF_X, PF_R ] + Sections: + - Section: .text + - Section: .non_alloc_in_segment + +# DATA: {{^[^[:blank:]]+}} de ad be ef ca fe ba be +# DATA-NOT: fe ed fa ce + +# VALIDATE: {{^[^[:blank:]]+}} de ad be ef ca fe ba be fe ed fa ce + +# CHECK: ElfHeader { +# CHECK-NEXT: Ident { +# CHECK-NEXT: Magic: (7F 45 4C 46) +# CHECK-NEXT: Class: 64-bit (0x2) +# CHECK-NEXT: DataEncoding: LittleEndian (0x1) +# CHECK-NEXT: FileVersion: 1 +# CHECK-NEXT: OS/ABI: SystemV (0x0) +# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +# CHECK-NEXT: } +# CHECK-NEXT: Type: Executable (0x2) +# CHECK-NEXT: Machine: EM_X86_64 (0x3E) +# CHECK-NEXT: Version: 1 +# CHECK-NEXT: Entry: 0x0 +# CHECK-NEXT: ProgramHeaderOffset: 0x40 +# CHECK-NEXT: SectionHeaderOffset: 0x0 +# CHECK-NEXT: Flags [ (0x0) +# CHECK-NEXT: ] +# CHECK-NEXT: HeaderSize: 64 +# CHECK-NEXT: ProgramHeaderEntrySize: 56 +# CHECK-NEXT: ProgramHeaderCount: 1 +# CHECK-NEXT: SectionHeaderEntrySize: 0 +# CHECK-NEXT: SectionHeaderCount: 0 +# CHECK-NEXT: StringTableSectionIndex: 0 +# CHECK-NEXT: } + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 8 +# CHECK-NEXT: MemSize: 8 +# CHECK-NEXT: Flags [ (0x5) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } +# CHECK-NEXT: ] diff --git a/llvm/test/tools/yaml2obj/elf-override-shoffset.yaml b/llvm/test/tools/yaml2obj/elf-override-shoffset.yaml --- a/llvm/test/tools/yaml2obj/elf-override-shoffset.yaml +++ b/llvm/test/tools/yaml2obj/elf-override-shoffset.yaml @@ -1,106 +1,106 @@ -## Check we are able to set custom sh_offset field -## for different sections. - -# RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=CASE1 - -# CASE1: Section Headers: -# CASE1-NEXT: [Nr] Name Type Address Off -# CASE1-NEXT: [ 0] NULL {{.*}} 000000 -# CASE1-NEXT: [ 1] .dynsym DYNSYM {{.*}} 000001 -# CASE1-NEXT: [ 2] .symtab SYMTAB {{.*}} 000002 -# CASE1-NEXT: [ 3] .dynamic DYNAMIC {{.*}} 000003 -# CASE1-NEXT: [ 4] .rela RELA {{.*}} 000004 -# CASE1-NEXT: [ 5] .nobits NOBITS {{.*}} 000005 -# CASE1-NEXT: [ 6] .group GROUP {{.*}} 000006 -# CASE1-NEXT: [ 7] .gnu.version VERSYM {{.*}} 000007 -# CASE1-NEXT: [ 8] .gnu.version_r VERNEED {{.*}} 000008 -# CASE1-NEXT: [ 9] .gnu.version_d VERDEF {{.*}} 000009 -# CASE1-NEXT: [10] .regular PROGBITS {{.*}} 00000a -# CASE1-NEXT: [11] .strtab STRTAB {{.*}} 00000b - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .dynsym - Type: SHT_DYNSYM - ShOffset: 0x000000001 - - Name: .symtab - Type: SHT_SYMTAB - ShOffset: 0x000000002 - - Name: .dynamic - Type: SHT_DYNAMIC - ShOffset: 0x000000003 - - Name: .rela - Type: SHT_RELA - ShOffset: 0x000000004 - - Name: .nobits - Type: SHT_NOBITS - ShOffset: 0x000000005 - - Name: .group - Type: SHT_GROUP - Info: 0 - ShOffset: 0x000000006 - Members: - - Name: .gnu.version - Type: SHT_GNU_versym - Entries: [ ] - ShOffset: 0x000000007 - - Name: .gnu.version_r - Type: SHT_GNU_verneed - Info: 0x0000000000000001 - ShOffset: 0x000000008 - Dependencies: - - Name: .gnu.version_d - Type: SHT_GNU_verdef - Info: 0x0000000000000001 - ShOffset: 0x000000009 - Entries: - - Name: .regular - Type: SHT_PROGBITS - ShOffset: 0x00000000A - - Name: .strtab - Type: SHT_STRTAB - ShOffset: 0x00000000B - -## Here we check that defining ShOffset does not actually change -## the offset at which section data is placed and also does -## not affect file size. - -# RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: yaml2obj --docnum=3 %s -o %t3 -# RUN: od -t x1 -v %t2 > %t.txt -# RUN: od -t x1 -v %t3 >> %t.txt -# RUN: FileCheck %s --input-file=%t.txt --check-prefix=CASE2 - -# CASE2: [[OFFSET:.*]] fe fe fe fe fe fe fe fe -# CASE2: [[FILESIZE:.*]]{{$}} -# CASE2: [[OFFSET]] fe fe fe fe fe fe fe fe -# CASE2: [[FILESIZE]]{{$}} - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .foo - Type: SHT_PROGBITS - Content: "fefefefefefefefe" - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .foo - Type: SHT_PROGBITS - ShOffset: 0xFFFF0000 - Content: "fefefefefefefefe" +## Check we are able to set custom sh_offset field +## for different sections. + +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=CASE1 + +# CASE1: Section Headers: +# CASE1-NEXT: [Nr] Name Type Address Off +# CASE1-NEXT: [ 0] NULL {{.*}} 000000 +# CASE1-NEXT: [ 1] .dynsym DYNSYM {{.*}} 000001 +# CASE1-NEXT: [ 2] .symtab SYMTAB {{.*}} 000002 +# CASE1-NEXT: [ 3] .dynamic DYNAMIC {{.*}} 000003 +# CASE1-NEXT: [ 4] .rela RELA {{.*}} 000004 +# CASE1-NEXT: [ 5] .nobits NOBITS {{.*}} 000005 +# CASE1-NEXT: [ 6] .group GROUP {{.*}} 000006 +# CASE1-NEXT: [ 7] .gnu.version VERSYM {{.*}} 000007 +# CASE1-NEXT: [ 8] .gnu.version_r VERNEED {{.*}} 000008 +# CASE1-NEXT: [ 9] .gnu.version_d VERDEF {{.*}} 000009 +# CASE1-NEXT: [10] .regular PROGBITS {{.*}} 00000a +# CASE1-NEXT: [11] .strtab STRTAB {{.*}} 00000b + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .dynsym + Type: SHT_DYNSYM + ShOffset: 0x000000001 + - Name: .symtab + Type: SHT_SYMTAB + ShOffset: 0x000000002 + - Name: .dynamic + Type: SHT_DYNAMIC + ShOffset: 0x000000003 + - Name: .rela + Type: SHT_RELA + ShOffset: 0x000000004 + - Name: .nobits + Type: SHT_NOBITS + ShOffset: 0x000000005 + - Name: .group + Type: SHT_GROUP + Info: 0 + ShOffset: 0x000000006 + Members: + - Name: .gnu.version + Type: SHT_GNU_versym + Entries: [ ] + ShOffset: 0x000000007 + - Name: .gnu.version_r + Type: SHT_GNU_verneed + Info: 0x0000000000000001 + ShOffset: 0x000000008 + Dependencies: + - Name: .gnu.version_d + Type: SHT_GNU_verdef + Info: 0x0000000000000001 + ShOffset: 0x000000009 + Entries: + - Name: .regular + Type: SHT_PROGBITS + ShOffset: 0x00000000A + - Name: .strtab + Type: SHT_STRTAB + ShOffset: 0x00000000B + +## Here we check that defining ShOffset does not actually change +## the offset at which section data is placed and also does +## not affect file size. + +# RUN: yaml2obj --docnum=2 %s -o %t2 +# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: od -t x1 -v %t2 > %t.txt +# RUN: od -t x1 -v %t3 >> %t.txt +# RUN: FileCheck %s --input-file=%t.txt --ignore-case --check-prefix=CASE2 + +# CASE2: [[OFFSET:.*]] fe fe fe fe fe fe fe fe +# CASE2: [[FILESIZE:.*]]{{$}} +# CASE2: [[OFFSET]] fe fe fe fe fe fe fe fe +# CASE2: [[FILESIZE]]{{$}} + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS + Content: "fefefefefefefefe" + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS + ShOffset: 0xFFFF0000 + Content: "fefefefefefefefe" diff --git a/llvm/test/tools/yaml2obj/elf-override-shsize.yaml b/llvm/test/tools/yaml2obj/elf-override-shsize.yaml --- a/llvm/test/tools/yaml2obj/elf-override-shsize.yaml +++ b/llvm/test/tools/yaml2obj/elf-override-shsize.yaml @@ -1,159 +1,159 @@ -## Check we are able to set custom sh_size field -## for different sections. - -# RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=CASE1 - -# CASE1: Section Headers: -# CASE1-NEXT: [Nr] Name Type Address Off Size -# CASE1-NEXT: [ 0] NULL 0000000000000000 000000 000000 -# CASE1-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000040 000001 -# CASE1-NEXT: [ 2] .symtab SYMTAB 0000000000000000 000058 000002 -# CASE1-NEXT: [ 3] .dynamic DYNAMIC 0000000000000000 000070 000003 -# CASE1-NEXT: [ 4] .rela RELA 0000000000000000 000070 000004 -# CASE1-NEXT: [ 5] .nobits NOBITS 0000000000000000 000070 000005 -# CASE1-NEXT: [ 6] .group GROUP 0000000000000000 000070 000006 -# CASE1-NEXT: [ 7] .gnu.version VERSYM 0000000000000000 000070 000007 -# CASE1-NEXT: [ 8] .gnu.version_r VERNEED 0000000000000000 000070 000008 -# CASE1-NEXT: [ 9] .gnu.version_d VERDEF 0000000000000000 000070 000009 -# CASE1-NEXT: [10] .regular PROGBITS 0000000000000000 000070 00000a -# CASE1-NEXT: [11] .strtab STRTAB 0000000000000000 000070 00000b - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .dynsym - Type: SHT_DYNSYM - ShSize: 0x000000001 - - Name: .symtab - Type: SHT_SYMTAB - ShSize: 0x000000002 - - Name: .dynamic - Type: SHT_DYNAMIC - ShSize: 0x000000003 - - Name: .rela - Type: SHT_RELA - ShSize: 0x000000004 - - Name: .nobits - Type: SHT_NOBITS - ShSize: 0x000000005 - - Name: .group - Type: SHT_GROUP - Info: 0 - ShSize: 0x000000006 - Members: - - Name: .gnu.version - Type: SHT_GNU_versym - Entries: [ ] - ShSize: 0x000000007 - - Name: .gnu.version_r - Type: SHT_GNU_verneed - Info: 0x0000000000000001 - ShSize: 0x000000008 - Dependencies: - - Name: .gnu.version_d - Type: SHT_GNU_verdef - Info: 0x0000000000000001 - ShSize: 0x000000009 - Entries: - - Name: .regular - Type: SHT_PROGBITS - ShSize: 0x00000000A - - Name: .strtab - Type: SHT_STRTAB - ShSize: 0x00000000B - -## Here we check that defining ShSize does not actually change -## the content and also does not affect file size. - -# RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: yaml2obj --docnum=3 %s -o %t3 -# RUN: od -t x1 -v %t2 > %t.txt -# RUN: od -t x1 -v %t3 >> %t.txt -# RUN: FileCheck %s --input-file=%t.txt --check-prefix=CASE2 - -# CASE2: [[OFFSET:.*]] fe fe fe fe fe fe fe fe -# CASE2: [[FILESIZE:.*]]{{$}} -# CASE2: [[OFFSET]] fe fe fe fe fe fe fe fe -# CASE2: [[FILESIZE]]{{$}} - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .foo - Type: SHT_PROGBITS - Content: "fefefefefefefefe" - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .foo - Type: SHT_PROGBITS - ShSize: 1 - Content: "fefefefefefefefe" - -## Check we can define sh_size larger than section content size -## and thus create overlaping sections. - -# RUN: yaml2obj --docnum=4 %s -o %t4 -# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=CASE4 - -# CASE4: Name: .foo -# CASE4: SectionData ( -# CASE4-NEXT: 0000: AAAABBBB |....| -# CASE4: Name: .bar -# CASE4: SectionData ( -# CASE4-NEXT: 0000: BBBB |..| - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .foo - Type: SHT_PROGBITS - Content: "aaaa" - ShSize: 4 - - Name: .bar - Type: SHT_PROGBITS - Content: "bbbb" - -## Check we can set both Size and ShSize and the number of the actual -## bytes written is equal to Size in this case. - -# RUN: yaml2obj --docnum=5 %s -o %t5 -# RUN: od -t x1 -v %t5 | FileCheck %s --check-prefix=CASE5 - -# CASE5: aa aa 00 00 bb bb - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: - - Name: .foo - Type: SHT_PROGBITS - Content: "aaaa" - - Name: .bar - Type: SHT_PROGBITS - Size: 2 - ShSize: 4 - - Name: .zed - Type: SHT_PROGBITS - Content: "bbbb" +## Check we are able to set custom sh_size field +## for different sections. + +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=CASE1 + +# CASE1: Section Headers: +# CASE1-NEXT: [Nr] Name Type Address Off Size +# CASE1-NEXT: [ 0] NULL 0000000000000000 000000 000000 +# CASE1-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000040 000001 +# CASE1-NEXT: [ 2] .symtab SYMTAB 0000000000000000 000058 000002 +# CASE1-NEXT: [ 3] .dynamic DYNAMIC 0000000000000000 000070 000003 +# CASE1-NEXT: [ 4] .rela RELA 0000000000000000 000070 000004 +# CASE1-NEXT: [ 5] .nobits NOBITS 0000000000000000 000070 000005 +# CASE1-NEXT: [ 6] .group GROUP 0000000000000000 000070 000006 +# CASE1-NEXT: [ 7] .gnu.version VERSYM 0000000000000000 000070 000007 +# CASE1-NEXT: [ 8] .gnu.version_r VERNEED 0000000000000000 000070 000008 +# CASE1-NEXT: [ 9] .gnu.version_d VERDEF 0000000000000000 000070 000009 +# CASE1-NEXT: [10] .regular PROGBITS 0000000000000000 000070 00000a +# CASE1-NEXT: [11] .strtab STRTAB 0000000000000000 000070 00000b + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .dynsym + Type: SHT_DYNSYM + ShSize: 0x000000001 + - Name: .symtab + Type: SHT_SYMTAB + ShSize: 0x000000002 + - Name: .dynamic + Type: SHT_DYNAMIC + ShSize: 0x000000003 + - Name: .rela + Type: SHT_RELA + ShSize: 0x000000004 + - Name: .nobits + Type: SHT_NOBITS + ShSize: 0x000000005 + - Name: .group + Type: SHT_GROUP + Info: 0 + ShSize: 0x000000006 + Members: + - Name: .gnu.version + Type: SHT_GNU_versym + Entries: [ ] + ShSize: 0x000000007 + - Name: .gnu.version_r + Type: SHT_GNU_verneed + Info: 0x0000000000000001 + ShSize: 0x000000008 + Dependencies: + - Name: .gnu.version_d + Type: SHT_GNU_verdef + Info: 0x0000000000000001 + ShSize: 0x000000009 + Entries: + - Name: .regular + Type: SHT_PROGBITS + ShSize: 0x00000000A + - Name: .strtab + Type: SHT_STRTAB + ShSize: 0x00000000B + +## Here we check that defining ShSize does not actually change +## the content and also does not affect file size. + +# RUN: yaml2obj --docnum=2 %s -o %t2 +# RUN: yaml2obj --docnum=3 %s -o %t3 +# RUN: od -t x1 -v %t2 > %t.txt +# RUN: od -t x1 -v %t3 >> %t.txt +# RUN: FileCheck %s --input-file=%t.txt --ignore-case --check-prefix=CASE2 + +# CASE2: [[OFFSET:.*]] fe fe fe fe fe fe fe fe +# CASE2: [[FILESIZE:.*]]{{$}} +# CASE2: [[OFFSET]] fe fe fe fe fe fe fe fe +# CASE2: [[FILESIZE]]{{$}} + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS + Content: "fefefefefefefefe" + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS + ShSize: 1 + Content: "fefefefefefefefe" + +## Check we can define sh_size larger than section content size +## and thus create overlaping sections. + +# RUN: yaml2obj --docnum=4 %s -o %t4 +# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=CASE4 + +# CASE4: Name: .foo +# CASE4: SectionData ( +# CASE4-NEXT: 0000: AAAABBBB |....| +# CASE4: Name: .bar +# CASE4: SectionData ( +# CASE4-NEXT: 0000: BBBB |..| + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS + Content: "aaaa" + ShSize: 4 + - Name: .bar + Type: SHT_PROGBITS + Content: "bbbb" + +## Check we can set both Size and ShSize and the number of the actual +## bytes written is equal to Size in this case. + +# RUN: yaml2obj --docnum=5 %s -o %t5 +# RUN: od -t x1 -v %t5 | FileCheck %s --ignore-case --check-prefix=CASE5 + +# CASE5: aa aa 00 00 bb bb + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .foo + Type: SHT_PROGBITS + Content: "aaaa" + - Name: .bar + Type: SHT_PROGBITS + Size: 2 + ShSize: 4 + - Name: .zed + Type: SHT_PROGBITS + Content: "bbbb"