Home | History | Annotate | Download | only in llvm-objcopy
      1 # This test is checking to ensure that if a section is removed in the presence
      2 # of a segment that the segment maintains its shape and properties and that any
      3 # section inside that segment maintains the relative positioning it had in the
      4 # segment. Note worthy is that .text3 keeps its offset despite it being
      5 # possible to place it after .text when .text2 is removed.
      6 
      7 # RUN: yaml2obj %s -o %t
      8 # RUN: llvm-objcopy -R .text2 %t %t2
      9 # RUN: llvm-readobj -file-headers -program-headers -sections %t2 | FileCheck %s
     10 # RUN: od -t x1 -j 8192 %t2 | FileCheck %s --check-prefix=DATA
     11 
     12 !ELF
     13 FileHeader:
     14   Class:           ELFCLASS64
     15   Data:            ELFDATA2LSB
     16   Type:            ET_EXEC
     17   Machine:         EM_X86_64
     18 Sections:
     19   - Name:            .text
     20     Type:            SHT_PROGBITS
     21     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
     22     Address:         0x1000
     23     AddressAlign:    0x1000
     24     Size:            4096
     25   - Name:            .text2
     26     Type:            SHT_PROGBITS
     27     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
     28     Address:         0x2000
     29     AddressAlign:    0x1000
     30     Size:            4096
     31     Content:         "DEADBEEF"
     32   - Name:            .text3
     33     Type:            SHT_PROGBITS
     34     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
     35     Address:         0x3000
     36     AddressAlign:    0x1000
     37     Size:            4096
     38 ProgramHeaders:
     39   - Type: PT_LOAD
     40     Flags: [ PF_X, PF_R ]
     41     Sections:
     42       - Section: .text
     43       - Section: .text2
     44       - Section: .text3
     45 
     46 # Make sure that when we remove a section we overwrite it with zeros
     47 # DATA: 0020000 00 00 00 00
     48 
     49 #CHECK: SectionHeaderCount: 6
     50 
     51 # CHECK: Sections [
     52 # CHECK:   Section {
     53 # CHECK-NEXT:     Index: 0
     54 # CHECK-NEXT:     Name:  (0)
     55 # CHECK-NEXT:     Type: SHT_NULL (0x0)
     56 # CHECK-NEXT:     Flags [ (0x0)
     57 # CHECK-NEXT:     ]
     58 # CHECK-NEXT:     Address: 0x0
     59 # CHECK-NEXT:     Offset:
     60 # CHECK-NEXT:     Size:
     61 # CHECK-NEXT:     Link: 0
     62 # CHECK-NEXT:     Info: 0
     63 # CHECK-NEXT:     AddressAlignment: 0
     64 # CHECK-NEXT:     EntrySize: 0
     65 # CHECK-NEXT:   }
     66 # CHECK-NEXT:   Section {
     67 # CHECK-NEXT:     Index: 1
     68 # CHECK-NEXT:     Name: .text
     69 # CHECK-NEXT:     Type: SHT_PROGBITS
     70 # CHECK-NEXT:     Flags [
     71 # CHECK-NEXT:       SHF_ALLOC
     72 # CHECK-NEXT:       SHF_EXECINSTR
     73 # CHECK-NEXT:     ]
     74 # CHECK-NEXT:     Address: 0x1000
     75 # CHECK-NEXT:     Offset: 0x1000
     76 # CHECK-NEXT:     Size:
     77 # CHECK-NEXT:     Link: 0
     78 # CHECK-NEXT:     Info: 0
     79 # CHECK-NEXT:     AddressAlignment: 4096
     80 # CHECK-NEXT:     EntrySize: 0
     81 # CHECK-NEXT:   }
     82 # CHECK-NEXT:   Section {
     83 # CHECK-NEXT:     Index: 2
     84 # CHECK-NEXT:     Name: .text3
     85 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
     86 # CHECK-NEXT:     Flags [
     87 # CHECK-NEXT:       SHF_ALLOC
     88 # CHECK-NEXT:       SHF_EXECINSTR
     89 # CHECK-NEXT:     ]
     90 # CHECK-NEXT:     Address: 0x3000
     91 # CHECK-NEXT:     Offset: 0x3000
     92 # CHECK-NEXT:     Size:
     93 # CHECK-NEXT:     Link: 0
     94 # CHECK-NEXT:     Info: 0
     95 # CHECK-NEXT:     AddressAlignment: 4096
     96 # CHECK-NEXT:     EntrySize: 0
     97 # CHECK-NEXT:   }
     98 # CHECK-NEXT:   Section {
     99 # CHECK-NEXT:     Index: 3
    100 # CHECK-NEXT:     Name: .symtab
    101 # CHECK-NEXT:     Type: SHT_SYMTAB (0x2)
    102 # CHECK-NEXT:     Flags [ (0x0)
    103 # CHECK-NEXT:     ]
    104 # CHECK-NEXT:     Address: 0x0
    105 # CHECK-NEXT:     Offset:
    106 # CHECK-NEXT:     Size:
    107 # CHECK-NEXT:     Link: 4
    108 # CHECK-NEXT:     Info: 1
    109 # CHECK-NEXT:     AddressAlignment: 8
    110 # CHECK-NEXT:     EntrySize: 24
    111 # CHECK-NEXT:   }
    112 # CHECK-NEXT:   Section {
    113 # CHECK-NEXT:     Index: 4
    114 # CHECK-NEXT:     Name: .strtab
    115 # CHECK-NEXT:     Type: SHT_STRTAB (0x3)
    116 # CHECK-NEXT:     Flags [ (0x0)
    117 # CHECK-NEXT:     ]
    118 # CHECK-NEXT:     Address: 0x0
    119 # CHECK-NEXT:     Offset:
    120 # CHECK-NEXT:     Size:
    121 # CHECK-NEXT:     Link: 0
    122 # CHECK-NEXT:     Info: 0
    123 # CHECK-NEXT:     AddressAlignment: 1
    124 # CHECK-NEXT:     EntrySize: 0
    125 # CHECK-NEXT:   }
    126 # CHECK-NEXT:   Section {
    127 # CHECK-NEXT:     Index: 5
    128 # CHECK-NEXT:     Name: .shstrtab
    129 # CHECK-NEXT:     Type: SHT_STRTAB (0x3)
    130 # CHECK-NEXT:     Flags [ (0x0)
    131 # CHECK-NEXT:     ]
    132 # CHECK-NEXT:     Address: 0x0
    133 # CHECK-NEXT:     Offset:
    134 # CHECK-NEXT:     Size:
    135 # CHECK-NEXT:     Link: 0
    136 # CHECK-NEXT:     Info: 0
    137 # CHECK-NEXT:     AddressAlignment: 1
    138 # CHECK-NEXT:     EntrySize: 0
    139 # CHECK-NEXT:   }
    140 # CHECK-NEXT: ]
    141 
    142 #CHECK:     ProgramHeaders [
    143 #CHECK-NEXT:  ProgramHeader {
    144 #CHECK-NEXT:    Type: PT_LOAD (0x1)
    145 #CHECK-NEXT:    Offset: 0x1000
    146 #CHECK-NEXT:    VirtualAddress: 0x0
    147 #CHECK-NEXT:    PhysicalAddress: 0x0
    148 #CHECK-NEXT:    FileSize: 12288
    149 #CHECK-NEXT:    MemSize: 12288
    150 #CHECK-NEXT:    Flags [ (0x5)
    151 #CHECK-NEXT:      PF_R (0x4)
    152 #CHECK-NEXT:      PF_X (0x1)
    153 #CHECK-NEXT:    ]
    154 #CHECK-NEXT:    Alignment: 4096
    155 #CHECK-NEXT:  }
    156 #CHECK-NEXT:]
    157