diff --git a/llvm/test/tools/llvm-objcopy/ELF/empty-section.test b/llvm/test/tools/llvm-objcopy/ELF/empty-section.test index 4216c5d9b57cf8..3ad1b7cae39cd2 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/empty-section.test +++ b/llvm/test/tools/llvm-objcopy/ELF/empty-section.test @@ -1,55 +1,94 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy %t %t2 -# RUN: llvm-readobj --sections %t2 | FileCheck %s +## .empty is not covered by a segment. Its offset is moved to 0x200 to fill the gap. +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: llvm-objcopy %t1 %t1.out +# RUN: llvm-readelf -S %t1.out | FileCheck --check-prefix=CHECK1 %s -!ELF +# CHECK1: Name Type Address Off +# CHECK1-NEXT: NULL 0000000000000000 000000 +# CHECK1-NEXT: .foo PROGBITS 0000000000000000 000100 +# CHECK1-NEXT: .empty PROGBITS 0000000000001000 000200 +# CHECK1-NEXT: .baz PROGBITS 0000000000001000 001000 + +--- !ELF FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Address: 0x0 - AddressAlign: 0x0000000000001000 - Content: "00000000" - - Name: .empty - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC ] - Address: 0x1000 - AddressAlign: 0x0000000000001000 - Content: "" - - Name: .data - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC ] - Address: 0x1000 - AddressAlign: 0x0000000000001000 - Content: "00000000" + - Name: gap + Type: Fill + Size: 0xE00 + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x100 + Address: 0 + Size: 0x100 + - Name: .empty + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x1000 + - Name: .baz + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x1000 + Address: 0x1000 + Size: 0x100 +## Test that we attribute .empty to the second segment. Its offset is assigned according to +## the p_offset of the second segment. +# RUN: yaml2obj --docnum=2 %s -o %t2 +# RUN: llvm-objcopy %t2 %t2.out +# RUN: llvm-readelf -S -l %t2.out | FileCheck --check-prefix=CHECK2 %s -# CHECK: Name: .text -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_EXECINSTR -# CHECK-NEXT: ] +# CHECK2: Name Type Address Off +# CHECK2-NEXT: NULL 0000000000000000 000000 +# CHECK2-NEXT: .foo PROGBITS 0000000000000000 000100 +# CHECK2-NEXT: .empty PROGBITS 0000000000001000 001000 +# CHECK2-NEXT: .baz PROGBITS 0000000000001000 001000 -# CHECK: Name: .empty -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x1000 -# CHECK-NEXT: Offset: 0x2000 -# CHECK-NEXT: Size: 0 +# CHECK2: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# CHECK2-NEXT: LOAD 0x000100 0x0000000000000000 0x0000000000000000 0x000100 0x000100 0x100 +# CHECK2-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000100 0x000100 0x1000 -# CHECK: Name: .data -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x1000 -# CHECK-NEXT: Offset: 0x2000 -# CHECK-NEXT: Size: 4 +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: gap + Type: Fill + Size: 0xE00 + - Name: .foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x100 + Address: 0 + Size: 0x100 + - Name: .empty + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x1000 + - Name: .baz + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x1000 + Address: 0x1000 + Size: 0x100 +ProgramHeaders: + - Type: PT_LOAD + VAddr: 0 + PAddr: 0 + Align: 0x100 + Sections: + - Section: .foo + - Type: PT_LOAD + VAddr: 0x1000 + PAddr: 0x1000 + Align: 0x1000 + Sections: + - Section: .empty + - Section: .baz diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-non-alloc.test b/llvm/test/tools/llvm-objcopy/ELF/strip-non-alloc.test index cf6561d0891a15..1cfb596ea5cfc6 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/strip-non-alloc.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-non-alloc.test @@ -1,8 +1,14 @@ -# RUN: yaml2obj %s -o %t -# RUN: llvm-objcopy --strip-non-alloc %t %t2 -# RUN: llvm-readobj --file-headers --sections %t2 | FileCheck %s +# RUN: yaml2obj --docnum=1 %s -o %t +# RUN: llvm-objcopy --strip-non-alloc %t %t.out +# RUN: llvm-readobj --file-headers --sections %t.out | FileCheck %s -!ELF +# CHECK: SectionHeaderCount: 5 +# CHECK: Name: non_alloc_in_segment +# CHECK: Name: .bss +# CHECK: Name: .text +# CHECK: Name: .shstrtab + +--- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB @@ -19,18 +25,38 @@ Sections: - Name: .text Type: SHT_PROGBITS Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - - Name: .blarg - Type: SHT_PROGBITS - Flags: [ ] ProgramHeaders: # Use an arbitrary segment type to show that the segment type is unimportant. - Type: 0x61234567 Sections: - Section: non_alloc_in_segment -# CHECK: SectionHeaderCount: 5 +# RUN: yaml2obj --docnum=2 %s -o %t2 +# RUN: llvm-objcopy --strip-non-alloc %t2 %t2.out +# RUN: llvm-readobj --file-headers --sections %t2.out | FileCheck --check-prefix=CHECK2 %s -# CHECK: Name: non_alloc_in_segment -# CHECK: Name: .bss -# CHECK: Name: .text -# CHECK: Name: .shstrtab +# CHECK2: SectionHeaderCount: 3 +# CHECK2: Name: .text +# CHECK2: Name: .shstrtab + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +## empty_trailing_non_alloc is considered included by the segment, +## so it will be retained. + - Name: empty_trailing_non_alloc + Type: SHT_PROGBITS + - Name: trailing_non_alloc + Type: SHT_PROGBITS + Content: 00 +ProgramHeaders: + - Type: 0x61234567 + Sections: + - Section: .text