Home | History | Annotate | Download | only in llvm-objcopy
      1 # RUN: yaml2obj %s > %t
      2 # RUN: cp %t %t3
      3 # RUN: llvm-objcopy -strip-debug %t %t2
      4 # RUN: llvm-readobj -file-headers -sections -symbols %t2 | FileCheck %s
      5 
      6 # Verify that the previous run of llvm-objcopy has not modified the input.
      7 # RUN: cmp %t %t3
      8 
      9 # RUN: llvm-strip -strip-debug %t3
     10 # RUN: cmp %t2 %t3
     11 
     12 # RUN: cp %t %t4
     13 # RUN: llvm-strip -d %t4
     14 # RUN: cmp %t2 %t4
     15 
     16 # RUN: cp %t %t5
     17 # RUN: llvm-strip -g %t5
     18 # RUN: cmp %t2 %t5
     19 
     20 # RUN: cp %t %t6
     21 # RUN: llvm-strip -S %t6
     22 # RUN: cmp %t2 %t6
     23 
     24 # RUN: rm -f %t.a
     25 # RUN: llvm-ar crs %t.a %t
     26 # RUN: llvm-objcopy --strip-debug %t.a %t.a
     27 # RUN: llvm-ar p %t.a > %t7
     28 # RUN: cmp %t2 %t7
     29 
     30 # Verify that an archive with multiple object files is handled correctly.
     31 # RUN: cp %t %t.duplicate
     32 # RUN: cp %t2 %t.duplicate.stripped
     33 # RUN: rm -f %t.multiple-stripped-obj.a
     34 # RUN: llvm-ar crs %t.multiple-stripped-obj.a %t2 %t.duplicate.stripped
     35 # RUN: rm -f %t.multiple-obj.a
     36 # RUN: llvm-ar crs %t.multiple-obj.a %t %t.duplicate
     37 # RUN: llvm-objcopy --strip-debug %t.multiple-obj.a %t.multiple-obj.stripped.a
     38 # RUN: llvm-ar p %t.multiple-stripped-obj.a > %t.multiple-stripped-obj.a.dump
     39 # RUN: llvm-ar p %t.multiple-obj.stripped.a > %t.multiple-obj.stripped.a.dump
     40 # RUN: cmp %t.multiple-stripped-obj.a.dump %t.multiple-obj.stripped.a.dump
     41 
     42 # We can not use %t inside the patterns passed to FileCheck,
     43 # thus we have to use "recognizable" file names.
     44 # RUN: cp %t %t1.o
     45 # RUN: cp %s %t2.txt
     46 # RUN: cp %t %t3.o
     47 # RUN: rm -f %t.non-object.a
     48 # RUN: llvm-ar cr %t.non-object.a %t1.o %t2.txt %t3.o
     49 # RUN: llvm-ar t %t.non-object.a | FileCheck %s --check-prefix=NON-OBJECT-ARCHIVE-MEMBERS
     50 
     51 # NON-OBJECT-ARCHIVE-MEMBERS: 1.o
     52 # NON-OBJECT-ARCHIVE-MEMBERS-NEXT: 2.txt
     53 # NON-OBJECT-ARCHIVE-MEMBERS-NEXT: 3.o
     54 
     55 # RUN: cp %t.non-object.a %t.non-object.copy.a
     56 # RUN: not llvm-objcopy --strip-debug %t.non-object.a %t2.non-object.a 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
     57 
     58 # BAD-FORMAT: The file was not recognized as a valid object file
     59 
     60 # Verify that %t.non-object.a has not been modified.
     61 # RUN: cmp %t.non-object.a %t.non-object.copy.a
     62 
     63 # RUN: rm -f %t.thin.a
     64 # Copy %t to %t.thin.archive.member to avoid changing %t directly.
     65 # RUN: cp %t %t.thin.archive.member
     66 # RUN: llvm-ar crsT %t.thin.a %t.thin.archive.member
     67 # RUN: llvm-objcopy --strip-debug %t.thin.a %t2.thin.a
     68 # RUN: cat %t.thin.a | FileCheck %s --check-prefix=VERIFY-THIN-ARCHIVE
     69 # RUN: cat %t2.thin.a | FileCheck %s --check-prefix=VERIFY-THIN-ARCHIVE
     70 
     71 # VERIFY-THIN-ARCHIVE: !<thin>
     72 
     73 # Verify that the member of a thin archive was properly modified.
     74 # RUN: cmp %t2 %t.thin.archive.member
     75 
     76 # RUN: rm -f %t.non-object.thin.a
     77 # RUN: llvm-ar crsT %t.non-object.thin.a %t1.o %t2.txt %t3.o
     78 # RUN: cp %t.non-object.thin.a %t.non-object.thin.copy.a
     79 # RUN: not llvm-objcopy --strip-debug %t.non-object.thin.a %t.non-object.thin.a 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
     80 
     81 # Verify that in the case of error thin archive and its memebers are not getting modified.
     82 # RUN: cmp %t.non-object.thin.a %t.non-object.thin.copy.a
     83 # RUN: cmp %t %t1.o
     84 # RUN: cmp %s %t2.txt
     85 # RUN: cmp %t %t3.o
     86 
     87 !ELF
     88 FileHeader:
     89   Class:           ELFCLASS64
     90   Data:            ELFDATA2LSB
     91   Type:            ET_REL
     92   Machine:         EM_X86_64
     93 Sections:
     94   - Name:            .debugfoo
     95     Type:            SHT_PROGBITS
     96     Content:         "00000000"
     97   - Name:            .zdebugfoo
     98     Type:            SHT_PROGBITS
     99     Content:         "00000000"
    100   - Name:            .gdb_index
    101     Type:            SHT_PROGBITS
    102     Content:         "00000000"
    103   - Name:            .text
    104     Type:            SHT_PROGBITS
    105     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    106     AddressAlign:    0x0000000000000010
    107     Content:         "00000000"
    108 Symbols:
    109   Global:
    110     - Name: foo
    111       Section: .text
    112     - Name: debugfoo
    113       Section: .debugfoo
    114 
    115 # CHECK: SectionHeaderCount: 5
    116 
    117 # CHECK: Name: .text
    118 # CHECK: Name: .symtab
    119 # CHECK: Name: .strtab
    120 # CHECK: Name: .shstrtab
    121 
    122 # Check that *only* foo is copied and not debugfoo
    123 # CHECK:      Symbols [
    124 # CHECK-NEXT:   Symbol {
    125 # CHECK-NEXT:     Name:
    126 # CHECK-NEXT:     Value:
    127 # CHECK-NEXT:     Size:
    128 # CHECK-NEXT:     Binding:
    129 # CHECK-NEXT:     Type:
    130 # CHECK-NEXT:     Other:
    131 # CHECK-NEXT:     Section: Undefined
    132 # CHECK-NEXT:   }
    133 # CHECK-NEXT:   Symbol {
    134 # CHECK-NEXT:     Name: foo
    135 # CHECK-NEXT:     Value:
    136 # CHECK-NEXT:     Size:
    137 # CHECK-NEXT:     Binding: Global
    138 # CHECK-NEXT:     Type:
    139 # CHECK-NEXT:     Other:
    140 # CHECK-NEXT:     Section: .text
    141 # CHECK-NEXT:   }
    142 # CHECK-NEXT: ]
    143