[llvm] 1562e45 - [llvm-objcopy][llvm-strip][test] Improve testing

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 4 03:33:41 PST 2021


Author: James Henderson
Date: 2021-03-04T11:32:27Z
New Revision: 1562e4552cd1b3d2eadd956c966f8a60e928b8ca

URL: https://github.com/llvm/llvm-project/commit/1562e4552cd1b3d2eadd956c966f8a60e928b8ca
DIFF: https://github.com/llvm/llvm-project/commit/1562e4552cd1b3d2eadd956c966f8a60e928b8ca.diff

LOG: [llvm-objcopy][llvm-strip][test] Improve testing

This patch adds a number of new test cases that cover various
llvm-objcopy and llvm-strip features that had missing test coverage of
various descriptions:
* --add-section - checked the shdr properties, not just the content.
* Dedicated test case for --add-symbol when there are many sections.
* Show that --change-start accepts negative values without overflow.
  This was previously present but got lost between review versions.
* --dump-section - show that multiple sections can be dumped
  simultaneously to different files, and that an error is reported when
  a section cannot be found.
* --globalize-symbol(s) - show that symbols that are not mentioned are
  not globalized, if they would otherwise be, and that missing symbols
  from the list do not cause problems.
* --keep-global-symbol - show that the --regex option can be used in
  conjunction with this option.
* --keep-symbol - show that the --regex option can be used in
  conjunction with this option.
* --localize-symbol(s) - show that symbols that are not mentioned are
  not localized, if they would otherwise be, and that missing symbols
  from the list do not cause problems.
* --prefix-alloc-sections - show the behaviour of an empty string
  argument and multiple arguments.
* --prefix-symbols - show the behaviour of an empty string argument and
  multiple arguments. Also show the option applies to undefined symbols.
* --redefine-symbol - show that symbols with no name can be renamed,
  that it is not an error if a symbol is not specified, and that the
  option doesn't chain (i.e. --redefine-sym a=b --redefine-sym b=c does
  not redefine a as c).
* --rename-section - show that all section flags are preserved if none
  are specified. Also show that the option does not chain.
* --set-section-alignment - show that only specified sections have
  their alignments changed.
* --set-section-flags - show which section flags are preserved when this
  option is used. Also show that unspecified sections are not affected.
* --preserve-dates - show that -p is an alias of --preserve-dates.
* --strip-symbol - show that --regex works with this option for
  llvm-objcopy as well as llvm-strip.
* --strip-unneeded-symbol(s) - show more clearly that needed symbols are
  not stripped even if requested by this option.
* --allow-broken-links - show the sh_link of a symbol table is set to 0
  when its string table has been removed when this option is specified.
* --weaken-symbol(s) - show that symbols that are not mentioned are not
  weakened, if they would otherwise be, and that missing symbols from
  the list do not cause problems.
* --wildcard - show the wildcard behaviour for several options that were
  previously unchecked.

Reviewed by: alexshap

Differential Revision: https://reviews.llvm.org/D97666

Added: 
    llvm/test/tools/llvm-objcopy/ELF/add-symbol-many-sections.test
    llvm/test/tools/llvm-objcopy/ELF/set-section-flags-preserved.test

Modified: 
    llvm/test/tools/llvm-objcopy/ELF/add-section.test
    llvm/test/tools/llvm-objcopy/ELF/change-entry-point.test
    llvm/test/tools/llvm-objcopy/ELF/dump-section.test
    llvm/test/tools/llvm-objcopy/ELF/globalize.test
    llvm/test/tools/llvm-objcopy/ELF/keep-global-symbols.test
    llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test
    llvm/test/tools/llvm-objcopy/ELF/localize.test
    llvm/test/tools/llvm-objcopy/ELF/prefix-alloc-sections.test
    llvm/test/tools/llvm-objcopy/ELF/prefix-symbols.test
    llvm/test/tools/llvm-objcopy/ELF/redefine-symbol.test
    llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
    llvm/test/tools/llvm-objcopy/ELF/rename-section.test
    llvm/test/tools/llvm-objcopy/ELF/set-section-alignment.test
    llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
    llvm/test/tools/llvm-objcopy/ELF/strip-preserve-mtime.test
    llvm/test/tools/llvm-objcopy/ELF/strip-symbol.test
    llvm/test/tools/llvm-objcopy/ELF/strip-unneeded.test
    llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
    llvm/test/tools/llvm-objcopy/ELF/weaken.test
    llvm/test/tools/llvm-objcopy/ELF/wildcard-flags.test

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/ELF/add-section.test b/llvm/test/tools/llvm-objcopy/ELF/add-section.test
index dc4bbddba5c0..2331157fb5ac 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/add-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/add-section.test
@@ -26,12 +26,24 @@ Sections:
 
 # CHECK: SectionHeaderCount: 6
 
-# CHECK: Name: .test1
-# CHECK: Name: .test3
-# CHECK: Name: .strtab
-# CHECK: Name: .shstrtab
-# CHECK: Name: .test2
-# CHECK: SectionData (
+# CHECK:      Name: .test1
+# CHECK:      Name: .test3
+# CHECK:      Name: .strtab
+# CHECK:      Name: .shstrtab
+# CHECK:      Offset: 0x[[#%x,OFFSET:]]
+# CHECK:      Size: [[#%u,SIZE:]]
+# CHECK:      Name: .test2
+# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Flags [ (0x0)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x0
+# CHECK-NEXT: Offset: 0x[[#%x,OFFSET+SIZE]]
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Link: 0
+# CHECK-NEXT: Info: 0
+# CHECK-NEXT: AddressAlignment: 1
+# CHECK-NEXT: EntrySize: 0
+# CHECK-NEXT: SectionData (
 # CHECK-NEXT:   0000: DEADBEEF
 # CHECK-NEXT: )
 

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/add-symbol-many-sections.test b/llvm/test/tools/llvm-objcopy/ELF/add-symbol-many-sections.test
new file mode 100644
index 000000000000..3a5420be8515
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/add-symbol-many-sections.test
@@ -0,0 +1,73 @@
+## Show that when adding a symbol defined in a section with section index >=
+## SHN_LORESERVE, the symbol's st_shndx value is set correctly, and the
+## SHT_SYMTAB_SHNDX is properly updated.
+## We don't bother to check the actual details of SHT_SYMTAB_SHNDX, because
+## llvm-readobj wouldn't be able to produce the right section indexes if it were
+## incorrect.
+
+## newsym1 = is in a section with index < SHN_LORESERVE.
+## newsym2 = is in a section with index == SHN_LORESERVE.
+## newsym3 = is in a section with index == SHN_ABS.
+## newsym4 = is in a section with index == SHN_COMMON.
+## newsym5 = is in a section with index == SHN_XINDEX.
+## newsym6 = is in a section with index > SHN_XINDEX.
+
+# RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
+# RUN: llvm-objcopy %t %t2 --add-symbol=newsym1=s1:0 --add-symbol=newsym2=s65280:0 \
+# RUN:                     --add-symbol=newsym3=s65521:0 --add-symbol=newsym4=s65522:0 \
+# RUN:                     --add-symbol=newsym5=s65535:0 --add-symbol=newsym6=s65536:0
+# RUN: llvm-readobj --symbols %t2 | FileCheck %s
+
+# CHECK:         Name: newsym1
+# CHECK-NEXT:    Value: 0x0
+# CHECK-NEXT:    Size: 0
+# CHECK-NEXT:    Binding: Global (0x1)
+# CHECK-NEXT:    Type: None (0x0)
+# CHECK-NEXT:    Other: 0
+# CHECK-NEXT:    Section: s1 (0x1)
+# CHECK-NEXT:  }
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: newsym2
+# CHECK-NEXT:    Value: 0x0
+# CHECK-NEXT:    Size: 0
+# CHECK-NEXT:    Binding: Global (0x1)
+# CHECK-NEXT:    Type: None (0x0)
+# CHECK-NEXT:    Other: 0
+# CHECK-NEXT:    Section: s65280 (0xFF00)
+# CHECK-NEXT:  }
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: newsym3
+# CHECK-NEXT:    Value: 0x0
+# CHECK-NEXT:    Size: 0
+# CHECK-NEXT:    Binding: Global (0x1)
+# CHECK-NEXT:    Type: None (0x0)
+# CHECK-NEXT:    Other: 0
+# CHECK-NEXT:    Section: s65521 (0xFFF1)
+# CHECK-NEXT:  }
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: newsym4
+# CHECK-NEXT:    Value: 0x0
+# CHECK-NEXT:    Size: 0
+# CHECK-NEXT:    Binding: Global (0x1)
+# CHECK-NEXT:    Type: None (0x0)
+# CHECK-NEXT:    Other: 0
+# CHECK-NEXT:    Section: s65522 (0xFFF2)
+# CHECK-NEXT:  }
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: newsym5
+# CHECK-NEXT:    Value: 0x0
+# CHECK-NEXT:    Size: 0
+# CHECK-NEXT:    Binding: Global (0x1)
+# CHECK-NEXT:    Type: None (0x0)
+# CHECK-NEXT:    Other: 0
+# CHECK-NEXT:    Section: s65535 (0xFFFF)
+# CHECK-NEXT:  }
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: newsym6
+# CHECK-NEXT:    Value: 0x0
+# CHECK-NEXT:    Size: 0
+# CHECK-NEXT:    Binding: Global (0x1)
+# CHECK-NEXT:    Type: None (0x0)
+# CHECK-NEXT:    Other: 0
+# CHECK-NEXT:    Section: s65536 (0x10000)
+# CHECK-NEXT:  }

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/change-entry-point.test b/llvm/test/tools/llvm-objcopy/ELF/change-entry-point.test
index 8136685065bc..4a37f00b28c8 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/change-entry-point.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/change-entry-point.test
@@ -14,23 +14,25 @@
 # RUN: llvm-readobj --file-headers %t6 | FileCheck %s --check-prefix=ADD
 # RUN: llvm-objcopy --change-start 0x100000000 %t %t7
 # RUN: llvm-readobj --file-headers %t7 | FileCheck %s --check-prefix=ADD-LARGE
-# RUN: llvm-objcopy --change-start -4353 %t %t8
-# RUN: llvm-readobj --file-headers %t8 | FileCheck %s --check-prefix=ADD-UNDERFLOW
-# RUN: llvm-objcopy --change-start -0x1101 %t %t9
-# RUN: cmp %t8 %t9
-# RUN: not llvm-objcopy --change-start -xyz %t %t10 2>&1 | FileCheck %s --check-prefix=ADD-ERR
+# RUN: llvm-objcopy --change-start -128 %t %t8
+# RUN: llvm-readobj --file-headers %t8 | FileCheck %s --check-prefix=SUB
+# RUN: llvm-objcopy --change-start -4353 %t %t9
+# RUN: llvm-readobj --file-headers %t9 | FileCheck %s --check-prefix=ADD-UNDERFLOW
+# RUN: llvm-objcopy --change-start -0x1101 %t %t10
+# RUN: cmp %t9 %t10
+# RUN: not llvm-objcopy --change-start -xyz %t %t11 2>&1 | FileCheck %s --check-prefix=ADD-ERR
 
 # Test --change-start after --set-start. Result should be 0x1150.
-# RUN: llvm-objcopy --set-start 0x1000 --change-start 0x100 --change-start 0x50 %t %t11
-# RUN: cmp %t6 %t11
+# RUN: llvm-objcopy --set-start 0x1000 --change-start 0x100 --change-start 0x50 %t %t12
+# RUN: cmp %t6 %t12
 
 # If --set-start is after --change-start then --change-start has no effect.
-# RUN: llvm-objcopy --change-start 0x150 --set-start 0x1000 %t %t12
-# RUN: cmp %t2 %t12
+# RUN: llvm-objcopy --change-start 0x150 --set-start 0x1000 %t %t13
+# RUN: cmp %t2 %t13
 
 # --adjust-start is an alias for --change-start.
-# RUN: llvm-objcopy --adjust-start -0x1101 %t %t13
-# RUN: cmp %t9 %t13
+# RUN: llvm-objcopy --adjust-start -0x1101 %t %t14
+# RUN: cmp %t10 %t14
 
 !ELF
 FileHeader:

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
index fe6f834b66ac..daa29b3948b2 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
@@ -4,6 +4,7 @@
 # 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: llvm-objcopy --dump-section .text=%t10 --dump-section .foo=%t11 %t /dev/null
 # RUN: llvm-objcopy --dump-section .empty=%t.empty %t /dev/null
 # RUN: od -t x1 %t2 | FileCheck %s --ignore-case
 # RUN: od -t x1 %t6 | FileCheck %s --ignore-case --check-prefix=NON-ALLOC
@@ -11,6 +12,8 @@
 # RUN: wc -c %t.empty | FileCheck %s --check-prefix=EMPTY
 # RUN: 
diff  %t2 %t3
 # RUN: 
diff  %t4 %t3
+# RUN: 
diff  %t10 %t3
+# RUN: 
diff  %t11 %t6
 
 !ELF
 FileHeader:
@@ -49,3 +52,10 @@ ProgramHeaders:
 # NOBITS: error: '[[INPUT]]': cannot dump section '.bar': it has no contents
 
 # EMPTY: 0
+
+# RUN: not llvm-objcopy --dump-section =/dev/null %t /dev/null 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ERR -DFILE=%t "-DSECTION="
+# RUN: not llvm-objcopy --dump-section .missing=/dev/null %t /dev/null 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ERR -DFILE=%t -DSECTION=.missing
+
+# ERR: error: '[[FILE]]': section '[[SECTION]]' not found

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/globalize.test b/llvm/test/tools/llvm-objcopy/ELF/globalize.test
index 8869e2d7bc02..044e5e8e6348 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/globalize.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/globalize.test
@@ -2,18 +2,20 @@
 # RUN: llvm-objcopy --globalize-symbol Global \
 # RUN:   --globalize-symbol Local \
 # RUN:   --globalize-symbol Weak \
-# RUN:   --globalize-symbol WeakUndef %t %t2
+# RUN:   --globalize-symbol WeakUndef \
+# RUN:   --globalize-symbol Missing %t %t2
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s
-# RUN: llvm-objcopy --regex --globalize-symbol='.*' %t %t3
+# RUN: llvm-objcopy --regex --globalize-symbol='[GLW].*' %t %t3
 # RUN: cmp %t2 %t3
 # RUN: echo " Global # global" > %t-list.txt
 # RUN: echo "Local" >> %t-list.txt
 # RUN: echo "Weak" >> %t-list.txt
 # RUN: echo "WeakUndef" >> %t-list.txt
+# RUN: echo "Missing" >> %t-list.txt
 # RUN: echo " # comment " >> %t-list.txt
 # RUN: llvm-objcopy --globalize-symbols %t-list.txt %t %t4
 # RUN: cmp %t2 %t4
-# RUN: echo ".+ # .+ " > %t-list2.txt
+# RUN: echo "[GLW].+ # .+ " > %t-list2.txt
 # RUN: llvm-objcopy --regex --globalize-symbols %t-list2.txt %t %t5
 # RUN: cmp %t2 %t5
 
@@ -50,6 +52,9 @@ Symbols:
     Binding:  STB_WEAK
   - Name:     WeakUndef
     Binding:  STB_WEAK
+  - Name:     Unspecified
+    Section:  .text
+    Binding:  STB_WEAK
 
 #CHECK: Symbols [
 #CHECK-NEXT:  Symbol {
@@ -97,4 +102,13 @@ Symbols:
 #CHECK-NEXT:    Other: 0
 #CHECK-NEXT:    Section: Undefined
 #CHECK-NEXT:  }
+#CHECK-NEXT:  Symbol {
+#CHECK-NEXT:    Name: Unspecified
+#CHECK-NEXT:    Value: 0x0
+#CHECK-NEXT:    Size: 0
+#CHECK-NEXT:    Binding: Weak
+#CHECK-NEXT:    Type: None
+#CHECK-NEXT:    Other: 0
+#CHECK-NEXT:    Section: .text
+#CHECK-NEXT:  }
 #CHECK-NEXT:]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/keep-global-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/keep-global-symbols.test
index a6ba1bee7c36..bfeaaf539621 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/keep-global-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/keep-global-symbols.test
@@ -45,6 +45,9 @@
 # RUN: llvm-objcopy  --regex --keep-global-symbols %t-globals-regexp.txt %t.o %t.3.o
 # RUN: llvm-readelf --symbols %t.3.o | FileCheck %s --check-prefix=REGEXP
 
+# RUN: llvm-objcopy --regex --keep-global-symbol='^Global[0-9]+([[:space:]]Global6)*$' %t.o %t.4.o
+# RUN: cmp %t.3.o %t.4.o
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test b/llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test
index b91510dff27d..5ff9c0ddf566 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test
@@ -8,11 +8,17 @@
 
 # RUN: echo 'foo' > %t.symbols
 # RUN: echo 'bar' >> %t.symbols
+# RUN: echo '.* # no regex without --regex' >> %t.symbols
 # RUN: llvm-objcopy --discard-all --keep-symbols %t.symbols %t %t5
 # RUN: llvm-objcopy -K foo -N foo -N bar --keep-symbols %t.symbols -N baz %t %t6
 # RUN: llvm-readobj --symbols %t5 | FileCheck %s
 # RUN: llvm-readobj --symbols %t6 | FileCheck %s
 
+# RUN: echo 'f.*' > %t.symbols.regex
+# RUN: echo '.*ar' >> %t.symbols.regex
+# RUN: llvm-objcopy --discard-all --keep-symbols %t.symbols.regex --regex %t %t7
+# RUN: cmp %t6 %t7
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/localize.test b/llvm/test/tools/llvm-objcopy/ELF/localize.test
index 8f8106eae737..97252fbd1689 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/localize.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/localize.test
@@ -5,15 +5,17 @@
 # RUN:     -L Local \
 # RUN:     -L Weak \
 # RUN:     -L GlobalCommon \
+# RUN:     -L Missing \
 # RUN:     %t %t2
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s
-# RUN: llvm-objcopy --regex --localize-symbol='.*' %t %t3
+# RUN: llvm-objcopy --regex --localize-symbol='[GLW].*' %t %t3
 # RUN: cmp %t2 %t3
 # RUN: echo "  Global # comment  " > %t-list.txt
 # RUN: echo "GlobalUndef" >> %t-list.txt
 # RUN: echo "Local" >> %t-list.txt
 # RUN: echo "Weak" >> %t-list.txt
 # RUN: echo "GlobalCommon" >> %t-list.txt
+# RUN: echo "Missing" >> %t-list.txt
 # RUN: echo " # comment " >> %t-list.txt
 # RUN: llvm-objcopy --localize-symbols %t-list.txt %t %t4
 # RUN: cmp %t2 %t4
@@ -68,6 +70,9 @@ Symbols:
     Section:  .text
     Value:    0x1008
     Binding:  STB_WEAK
+  - Name:     Unmentioned
+    Section:  .text
+    Binding:  STB_GLOBAL
 
 #CHECK: Symbols [
 #CHECK-NEXT:  Symbol {
@@ -122,6 +127,15 @@ Symbols:
 #CHECK-NEXT:    Binding: Global
 #CHECK-NEXT:    Type: Object
 #CHECK-NEXT:    Other: 0
-#CHECK-NEXT:    Section: Common (0xF
+#CHECK-NEXT:    Section: Common
+#CHECK-NEXT:  }
+#CHECK-NEXT:  Symbol {
+#CHECK-NEXT:    Name: Unmentioned
+#CHECK-NEXT:    Value:
+#CHECK-NEXT:    Size:
+#CHECK-NEXT:    Binding: Global
+#CHECK-NEXT:    Type:
+#CHECK-NEXT:    Other:
+#CHECK-NEXT:    Section: .text
 #CHECK-NEXT:  }
 #CHECK-NEXT:]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/prefix-alloc-sections.test b/llvm/test/tools/llvm-objcopy/ELF/prefix-alloc-sections.test
index 731c332cb268..faf07443eda2 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/prefix-alloc-sections.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/prefix-alloc-sections.test
@@ -2,6 +2,15 @@
 # RUN: llvm-objcopy --prefix-alloc-sections=.prefix %t %t2
 # RUN: llvm-readobj --sections %t2 | FileCheck %s
 
+## Show that an empty string is permitted as the argument to
+## --prefix-alloc-sections.
+# RUN: llvm-objcopy --prefix-alloc-sections= %t2 %t3
+# RUN: cmp %t2 %t3
+
+## Show that only the last prefix is applied.
+# RUN: llvm-objcopy --prefix-alloc-sections=.bar --prefix-alloc-sections=.prefix %t %t4
+# RUN: cmp %t2 %t4
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/prefix-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/prefix-symbols.test
index 3445183db77a..8c6503d4c8e0 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/prefix-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/prefix-symbols.test
@@ -4,6 +4,15 @@
 # RUN: llvm-objcopy --redefine-sym bar=baz --prefix-symbols prefix %t %t3
 # RUN: llvm-readobj --symbols %t3 | FileCheck %s --check-prefixes=COMMON,REDEF
 
+## Show that an empty string is permitted as the argument to
+## --prefix-symbols.
+# RUN: llvm-objcopy --prefix-symbols= %t2 %t4
+# RUN: cmp %t2 %t4
+
+## Show that the last prefix wins.
+# RUN: llvm-objcopy --prefix-symbols foo --prefix-symbols prefix %t %t5
+# RUN: cmp %t2 %t5
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64
@@ -28,6 +37,8 @@ Symbols:
     Type:     STT_FUNC
     Section:  .text
     Binding:  STB_GLOBAL
+  - Name:     undef
+    Binding:  STB_GLOBAL
 
 # COMMON: Symbols [
 # COMMON-NEXT:  Symbol {
@@ -67,4 +78,13 @@ Symbols:
 # COMMON-NEXT:    Other: 0
 # COMMON-NEXT:    Section: .text
 # COMMON-NEXT:  }
+# COMMON-NEXT:  Symbol {
+# COMMON-NEXT:    Name: prefixundef
+# COMMON-NEXT:    Value: 0x0
+# COMMON-NEXT:    Size: 0
+# COMMON-NEXT:    Binding: Global
+# COMMON-NEXT:    Type: None
+# COMMON-NEXT:    Other: 0
+# COMMON-NEXT:    Section: Undefined
+# COMMON-NEXT:  }
 # COMMON-NEXT:]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/redefine-symbol.test b/llvm/test/tools/llvm-objcopy/ELF/redefine-symbol.test
index 83506980e933..75f6f8d77322 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/redefine-symbol.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/redefine-symbol.test
@@ -1,5 +1,5 @@
 # RUN: yaml2obj %s -o %t
-# RUN: llvm-objcopy --redefine-sym foo=oof --redefine-sym empty= %t %t2
+# RUN: llvm-objcopy --redefine-sym foo=oof --redefine-sym =wasempty --redefine-sym empty= %t %t2
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s
 # RUN: echo "  bar   rab #rename bar  " > %t.rename1.txt
 # RUN: echo "foo oof #rename foo  " > %t.rename2.txt
@@ -43,6 +43,10 @@ Symbols:
     Section:  .text
     Value:    0x1008
     Binding:  STB_GLOBAL
+  - Type:     STT_OBJECT
+    Section:  .data
+    Value:    0x2008
+    Binding:  STB_GLOBAL
 
 #CHECK: Symbols [
 #CHECK-NEXT:  Symbol {
@@ -73,7 +77,7 @@ Symbols:
 #CHECK-NEXT:    Section: .data
 #CHECK-NEXT:  }
 #CHECK-NEXT:  Symbol {
-#CHECK-NEXT:    Name: 
+#CHECK-NEXT:    Name: (0)
 #CHECK-NEXT:    Value: 0x1008
 #CHECK-NEXT:    Size: 0
 #CHECK-NEXT:    Binding: Global
@@ -81,6 +85,15 @@ Symbols:
 #CHECK-NEXT:    Other: 0
 #CHECK-NEXT:    Section: .text
 #CHECK-NEXT:  }
+#CHECK-NEXT:  Symbol {
+#CHECK-NEXT:    Name: wasempty
+#CHECK-NEXT:    Value: 0x2008
+#CHECK-NEXT:    Size: 0
+#CHECK-NEXT:    Binding: Global
+#CHECK-NEXT:    Type: Object
+#CHECK-NEXT:    Other: 0
+#CHECK-NEXT:    Section: .data
+#CHECK-NEXT:  }
 
 #MULTIPLE-FILES:        Name: oof
 #MULTIPLE-FILES-NEXT:   Value: 0x1004
@@ -88,3 +101,13 @@ Symbols:
 #MULTIPLE-FILES-NEXT:   Value: 0x2000
 #MULTIPLE-FILES:        Name: ytpme
 #MULTIPLE-FILES-NEXT:   Value: 0x1008
+
+## Show that it is not an error if a specified symbol is not present.
+# RUN: llvm-objcopy %t2 %t5 --redefine-sym missing=blah
+# RUN: cmp %t2 %t5
+
+## Show that --redefine-sym doesn't chain together.
+# RUN: llvm-objcopy %t2 %t6 --redefine-sym oof=bob --redefine-sym bob=baz
+# RUN: llvm-readobj %t6 --syms | FileCheck %s --check-prefix=CHAIN --implicit-check-not="Name: baz"
+
+# CHAIN: Name: bob

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
index e3e0a3dac04c..f9e6f772a6ae 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/rename-section-flag-preserved.test
@@ -28,6 +28,11 @@
 # RUN: llvm-objcopy --rename-section=.foo=.bar,exclude %t %t.exclude
 # RUN: llvm-readobj --sections %t.exclude | FileCheck %s --check-prefixes=CHECK,WRITE,EXCLUDE
 
+## Show that if no flags are specified, all existing flags are preserved.
+## Note: GNU objcopy does not preserve the SHF_OS_NONCONFORMING flag.
+# RUN: llvm-objcopy --rename-section=.foo=.bar %t %t.none
+# RUN: llvm-readobj --sections %t.none | FileCheck %s --check-prefixes=CHECK,ALLOC,EXCLUDE,EXEC,MERGE,NONCONFORMING,STRINGS,WRITE
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64
@@ -56,18 +61,19 @@ Symbols:
   - Name:            dummy
     Section:         .group
 
-# CHECK:        Name: .bar
-# CHECK-NEXT:   Type: SHT_PROGBITS
-# CHECK-NEXT:   Flags [
-# ALLOC-NEXT:     SHF_ALLOC (0x2)
-# CHECK-NEXT:     SHF_COMPRESSED (0x800)
-# EXCLUDE-NEXT:   SHF_EXCLUDE (0x80000000)
-# EXEC-NEXT:      SHF_EXECINSTR (0x4)
-# CHECK-NEXT:     SHF_GROUP (0x200)
-# CHECK-NEXT:     SHF_INFO_LINK (0x40)
-# CHECK-NEXT:     SHF_LINK_ORDER (0x80)
-# MERGE-NEXT:     SHF_MERGE (0x10)
-# STRINGS-NEXT:   SHF_STRINGS (0x20)
-# CHECK-NEXT:     SHF_TLS (0x400)
-# WRITE-NEXT:     SHF_WRITE (0x1)
-# CHECK-NEXT:   ]
+# CHECK:              Name: .bar
+# CHECK-NEXT:         Type: SHT_PROGBITS
+# CHECK-NEXT:         Flags [
+# ALLOC-NEXT:           SHF_ALLOC (0x2)
+# CHECK-NEXT:           SHF_COMPRESSED (0x800)
+# EXCLUDE-NEXT:         SHF_EXCLUDE (0x80000000)
+# EXEC-NEXT:            SHF_EXECINSTR (0x4)
+# CHECK-NEXT:           SHF_GROUP (0x200)
+# CHECK-NEXT:           SHF_INFO_LINK (0x40)
+# CHECK-NEXT:           SHF_LINK_ORDER (0x80)
+# MERGE-NEXT:           SHF_MERGE (0x10)
+# NONCONFORMING-NEXT:   SHF_OS_NONCONFORMING (0x100)
+# STRINGS-NEXT:         SHF_STRINGS (0x20)
+# CHECK-NEXT:           SHF_TLS (0x400)
+# WRITE-NEXT:           SHF_WRITE (0x1)
+# CHECK-NEXT:         ]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/rename-section.test b/llvm/test/tools/llvm-objcopy/ELF/rename-section.test
index b2927c28b2ee..e113e7d2203b 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/rename-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/rename-section.test
@@ -4,6 +4,10 @@
 # RUN: not llvm-objcopy --rename-section=.foo.bar --rename-section=.foo=.other %t %t2 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
 # RUN: not llvm-objcopy --rename-section=.foo=.bar --rename-section=.foo=.other %t %t2 2>&1 | FileCheck %s --check-prefix=MULTIPLE-RENAMES
 
+## Section renames don't chain:
+# RUN: llvm-objcopy --rename-section=.foo=.bar --rename-section=.bar=.baz %t %t3
+# RUN: cmp %t2 %t3
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/set-section-alignment.test b/llvm/test/tools/llvm-objcopy/ELF/set-section-alignment.test
index d992a82e7a19..dbf5ddcbb35e 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/set-section-alignment.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/set-section-alignment.test
@@ -15,12 +15,19 @@
 # CHECK-SAME:                   0{{$}}
 
 ## If a section is specified multiple times, the last wins.
+## Also incidentally show that unmentioned sections are not impacted.
 # RUN: llvm-objcopy --set-section-alignment .foo=4 --set-section-alignment=.foo=7 %t %t.3
 # RUN: llvm-readobj --sections %t.3 | FileCheck --check-prefix=MULTI %s
 
 # MULTI:      Name: .foo
 # MULTI:      AddressAlignment:
 # MULTI-SAME:                   7{{$}}
+# MULTI:      Name: .bar
+# MULTI:      AddressAlignment:
+# MULTI-SAME:                   0{{$}}
+# MULTI:      Name: .baz
+# MULTI:      AddressAlignment:
+# MULTI-SAME:                   4{{$}}
 
 ## Ignore the option if the section does not exist.
 # RUN: llvm-objcopy --set-section-alignment .not_exist=4 %t.3 %t.4

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/set-section-flags-preserved.test b/llvm/test/tools/llvm-objcopy/ELF/set-section-flags-preserved.test
new file mode 100644
index 000000000000..573ff8e91177
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/set-section-flags-preserved.test
@@ -0,0 +1,73 @@
+# RUN: yaml2obj %s -o %t
+
+## Show which flags are preserved when setting other section flags.
+# RUN: llvm-objcopy --set-section-flags=.foo=alloc %t %t.alloc
+# RUN: llvm-readobj --sections %t.alloc | FileCheck %s --check-prefixes=CHECK,ALLOC,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=load %t %t.load
+# RUN: llvm-readobj --sections %t.load | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=noload %t %t.noload
+# RUN: llvm-readobj --sections %t.noload | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=readonly %t %t.readonly
+# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK
+# RUN: llvm-objcopy --set-section-flags=.foo=debug %t %t.debug
+# RUN: llvm-readobj --sections %t.debug | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=code %t %t.code
+# RUN: llvm-readobj --sections %t.code | FileCheck %s --check-prefixes=CHECK,EXEC,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=data %t %t.data
+# RUN: llvm-readobj --sections %t.data | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=rom %t %t.rom
+# RUN: llvm-readobj --sections %t.rom | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=contents %t %t.contents
+# RUN: llvm-readobj --sections %t.contents | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=merge %t %t.merge
+# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,MERGE,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=strings %t %t.strings
+# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,STRINGS,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=share %t %t.share
+# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,WRITE
+# RUN: llvm-objcopy --set-section-flags=.foo=exclude %t %t.exclude
+# RUN: llvm-readobj --sections %t.exclude | FileCheck %s --check-prefixes=CHECK,WRITE,EXCLUDE
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .infolink
+    Type:            SHT_NOBITS
+  - Name:            .group
+    Type:            SHT_GROUP
+    Link:            .symtab
+    Flags:           [ ]
+    Info:            dummy
+    Members:
+      - SectionOrType: GRP_COMDAT
+      - SectionOrType: .foo
+  - Name:            .foo
+    Type:            SHT_PROGBITS
+    Link:            .infolink
+    Flags:           [ SHF_ALLOC, SHF_COMPRESSED, SHF_EXCLUDE, SHF_EXECINSTR,
+                       SHF_GROUP, SHF_INFO_LINK, SHF_LINK_ORDER, SHF_MERGE,
+                       SHF_OS_NONCONFORMING, SHF_STRINGS, SHF_TLS, SHF_WRITE ]
+    Content:        "a4a4a4a4"
+Symbols:
+  - Name:            dummy
+    Section:         .group
+
+# CHECK:              Name: .foo
+# CHECK-NEXT:         Type: SHT_PROGBITS
+# CHECK-NEXT:         Flags [
+# ALLOC-NEXT:           SHF_ALLOC (0x2)
+# CHECK-NEXT:           SHF_COMPRESSED (0x800)
+# EXCLUDE-NEXT:         SHF_EXCLUDE (0x80000000)
+# EXEC-NEXT:            SHF_EXECINSTR (0x4)
+# CHECK-NEXT:           SHF_GROUP (0x200)
+# CHECK-NEXT:           SHF_INFO_LINK (0x40)
+# CHECK-NEXT:           SHF_LINK_ORDER (0x80)
+# MERGE-NEXT:           SHF_MERGE (0x10)
+# STRINGS-NEXT:         SHF_STRINGS (0x20)
+# CHECK-NEXT:           SHF_TLS (0x400)
+# WRITE-NEXT:           SHF_WRITE (0x1)
+# CHECK-NEXT:         ]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test b/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
index db063fd96e59..afcac5527a57 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
@@ -72,6 +72,10 @@
 # RUN:   --set-section-flags=.rela.baz=aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE %t %t.mixed
 # RUN: llvm-readobj --sections %t.mixed | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,MERGE,STRINGS
 
+## Unspecified sections are not affected:
+# RUN: llvm-objcopy --set-section-flags=.foo=alloc %t %t.unspecified
+# RUN: llvm-readobj --sections %t.unspecified | FileCheck %s --check-prefixes=UNSPECIFIED
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64
@@ -127,3 +131,20 @@ Sections:
 # MULTIPLE-SETS: --set-section-flags set multiple times for section '.foo'
 
 # BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, exclude, debug, code, data, rom, share, contents, merge, strings
+
+# UNSPECIFIED:      Name: .foo
+# UNSPECIFIED-NEXT: Type: SHT_PROGBITS
+# UNSPECIFIED-NEXT: Flags [
+# UNSPECIFIED-NEXT:   SHF_ALLOC (0x2)
+# UNSPECIFIED-NEXT:   SHF_WRITE (0x1)
+# UNSPECIFIED-NEXT: ]
+
+# UNSPECIFIED:      Name: .baz
+# UNSPECIFIED-NEXT: Type: SHT_NOBITS
+# UNSPECIFIED-NEXT: Flags [ (0x0)
+# UNSPECIFIED-NEXT: ]
+
+# UNSPECIFIED:      Name: .rela.baz
+# UNSPECIFIED-NEXT: Type: SHT_RELA
+# UNSPECIFIED-NEXT: Flags [ (0x0)
+# UNSPECIFIED-NEXT: ]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-mtime.test b/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-mtime.test
index aa1c37a1428f..0399c108ba20 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-mtime.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-mtime.test
@@ -1,6 +1,6 @@
-# Note: ls -l prints the modified timestamp
+## Note: ls -l prints the modified timestamp
 
-# Preserve dates when stripping to an output file.
+## Preserve dates when stripping to an output file.
 # RUN: yaml2obj %s -o %t.1.o
 # RUN: touch -m -t 199705050555.55 %t.1.o
 # RUN: llvm-strip -p %t.1.o -o %t-preserved.1.o
@@ -8,28 +8,28 @@
 # Check that the stripped output is in fact a valid object file.
 # RUN: llvm-readobj %t-preserved.1.o
 
-# Preserve dates available via objcopy interface as well.
+## Preserve dates available via objcopy interface as well.
 # RUN: yaml2obj %s -o %t.2.o
 # RUN: touch -m -t 199705050555.55 %t.2.o
 # RUN: llvm-objcopy -p %t.2.o %t-preserved.2.o
 # RUN: ls -l %t-preserved.2.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME
 # RUN: llvm-readobj %t-preserved.2.o
 
-# Preserve dates when stripping in place.
+## Preserve dates when stripping in place.
 # RUN: yaml2obj %s -o %t.3.o
 # RUN: touch -m -t 199705050555.55 %t.3.o
 # RUN: llvm-strip -p %t.3.o
 # RUN: ls -l %t.3.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME
 # RUN: llvm-readobj %t.3.o
 
-# Without -p set, don't preserve dates.
+## Without -p set, don't preserve dates.
 # RUN: yaml2obj %s -o %t.4.o
 # RUN: touch -m -t 199705050555.55 %t.4.o
 # RUN: llvm-strip %t.4.o
 # RUN: ls -l %t.4.o | FileCheck %s --check-prefix=CHECK-NO-PRESERVE-MTIME
 # RUN: llvm-readobj %t.4.o
 
-# Preserve dates in archives.
+## Preserve dates in archives.
 # RUN: yaml2obj %s -o %t.5.o
 # RUN: rm -f %t.a
 # RUN: llvm-ar cr %t.a %t.5.o
@@ -38,7 +38,7 @@
 # RUN: ls -l %t.a | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME
 # RUN: llvm-readobj %t.a
 
-# Preserve dates in split DWO files.
+## Preserve dates in split DWO files.
 # RUN: cp %p/Inputs/dwarf.dwo %t-input.dwo
 # RUN: touch -m -t 199705050555.55 %t-input.dwo
 # RUN: llvm-objcopy -p --split-dwo=%t-dwo %t-input.dwo %t-nondwo
@@ -47,6 +47,14 @@
 # RUN: ls -l %t-nondwo | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME
 # RUN: llvm-readobj %t-nondwo
 
+## --preserve-dates and -p are aliases.
+# RUN: llvm-strip --preserve-dates %t.1.o -o %t-preserved.1.alias.o
+# RUN: ls -l %t-preserved.1.alias.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME
+# RUN: cmp %t-preserved.1.alias.o %t-preserved.1.o
+# RUN: llvm-objcopy --preserve-dates %t.2.o %t-preserved.2.alias.o
+# RUN: ls -l %t-preserved.2.alias.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME
+# RUN: cmp %t-preserved.2.o %t-preserved.2.alias.o
+
 # CHECK-PRESERVE-MTIME:        {{[[:space:]]1997}}
 # CHECK-NO-PRESERVE-MTIME-NOT: {{[[:space:]]1997}}
 

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/strip-symbol.test b/llvm/test/tools/llvm-objcopy/ELF/strip-symbol.test
index 78de46cc47b5..1f6d066231b4 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-symbol.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-symbol.test
@@ -3,16 +3,18 @@
 # RUN: llvm-readobj --symbols --sections %t2 | FileCheck %s
 # RUN: llvm-strip --strip-symbol baz -N bar %t -o %t3
 # RUN: cmp %t2 %t3
-# RUN: llvm-strip --regex --strip-symbol '^b.*' -N bar %t -o %t4
-# RUN: cmp %t3 %t4
+# RUN: llvm-objcopy --regex --strip-symbol '^b.*' -N bar %t %t4
+# RUN: cmp %t2 %t4
+# RUN: llvm-strip --regex --strip-symbol '^b.*' -N bar %t -o %t5
+# RUN: cmp %t3 %t5
 # RUN: echo " bar # bar" > %t-list.txt
 # RUN: echo " baz # baz" >> %t-list.txt
 # RUN: echo " # no symbol" >> %t-list.txt
-# RUN: llvm-objcopy --strip-symbols %t-list.txt %t %t5
-# RUN: cmp %t3 %t5
-# RUN: echo "b.* # bar & baz" > %t-list2.txt
-# RUN: llvm-objcopy --regex --strip-symbols %t-list2.txt %t %t6
+# RUN: llvm-objcopy --strip-symbols %t-list.txt %t %t6
 # RUN: cmp %t3 %t6
+# RUN: echo "b.* # bar & baz" > %t-list2.txt
+# RUN: llvm-objcopy --regex --strip-symbols %t-list2.txt %t %t7
+# RUN: cmp %t3 %t7
 
 !ELF
 FileHeader:

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/strip-unneeded.test b/llvm/test/tools/llvm-objcopy/ELF/strip-unneeded.test
index 0556a4f127e0..5bed8a06c426 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-unneeded.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-unneeded.test
@@ -1,13 +1,13 @@
 # RUN: yaml2obj %s -o %t
 # RUN: cp %t %t1
 # RUN: llvm-objcopy --strip-unneeded %t %t2
-# Verify that llvm-objcopy has not modified the input.
+## Verify that llvm-objcopy has not modified the input.
 # RUN: cmp %t %t1
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s
 
-# Verify that --keep-file-symbols works together with --strip-unneeded
+## Verify that --keep-file-symbols works together with --strip-unneeded
 # RUN: llvm-objcopy --keep-file-symbols --strip-unneeded %t %t2b
-# RUN: llvm-readobj --symbols %t2b | FileCheck %s --check-prefix=FILESYM
+# RUN: llvm-readobj --symbols %t2b | FileCheck %s --check-prefixes=CHECK,FILESYM
 
 # RUN: llvm-objcopy --strip-unneeded-symbol=bar \
 # RUN:              %t %t3
@@ -16,10 +16,16 @@
 # RUN: llvm-objcopy --regex --strip-unneeded-symbol='.*' %t %t4
 # RUN: cmp %t2 %t4
 
+## Verify that --strip-unneeded-symbols removes all unneeded symbols listed in
+## the file, but not those that aren't.
+## In this case, fileSymbol isn't mentioned (so isn't removed), barbaz is
+## mentioned, but isn't removed (because it is needed) and bar, foobar and
+## foobaz are mentioned and removed.
 # RUN: echo " bar # bar " > %t.list.txt
 # RUN: echo "foobar" >> %t.list.txt
 # RUN: echo "foobaz" >> %t.list.txt
 # RUN: echo " # comment " >> %t.list.txt
+# RUN: echo "barbaz" >> %t.list.txt
 # RUN: llvm-objcopy --strip-unneeded-symbols %t.list.txt %t %t5
 # RUN: cmp %t2b %t5
 
@@ -27,7 +33,7 @@
 # RUN: llvm-objcopy --regex --strip-unneeded-symbols %t.list2.txt %t %t6
 # RUN: cmp %t2 %t6
 
-# Verify that llvm-strip modifies the symbol table the same way.
+## Verify that llvm-strip modifies the symbol table the same way.
 # RUN: llvm-strip --strip-unneeded %t
 # RUN: cmp %t %t2
 
@@ -78,6 +84,7 @@ Symbols:
     Value:    0x1010
   - Name:     fileSymbol
     Type:     STT_FILE
+    Index:    SHN_ABS
   - Name:     sectionSymbol
     Type:     STT_SECTION
   - Name:     foobar
@@ -127,6 +134,15 @@ Symbols:
 #CHECK-NEXT:    Other: 0
 #CHECK-NEXT:    Section: .text
 #CHECK-NEXT:  }
+#FILESYM-NEXT:Symbol {
+#FILESYM-NEXT:  Name: fileSymbol
+#FILESYM-NEXT:  Value: 0x0
+#FILESYM-NEXT:  Size: 0
+#FILESYM-NEXT:  Binding: Local
+#FILESYM-NEXT:  Type: File
+#FILESYM-NEXT:  Other: 0
+#FILESYM-NEXT:  Section: Absolute
+#FILESYM-NEXT:}
 #CHECK-NEXT:  Symbol {
 #CHECK-NEXT:    Name: sectionSymbol
 #CHECK-NEXT:    Value: 0x0
@@ -156,8 +172,6 @@ Symbols:
 #CHECK-NEXT:  }
 #CHECK-NEXT:]
 
-#FILESYM:       Name: fileSymbol
-#FILESYM-NEXT:  Value: 0x0
 
 #STRIP-BAR-NOT: Name: bar ({{.*}})
 #REMAIN: Name: foobar

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test b/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
index d74a755d257e..bb214d9750d7 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
@@ -15,9 +15,11 @@ Symbols: []
 # ERR2: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'
 
 # RUN: llvm-objcopy --allow-broken-links -R .strtab %t %t4
-# RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
+# RUN: llvm-readobj --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
 # RUN: cp %t %t5
 # RUN: llvm-strip --no-strip-all --allow-broken-links -R .strtab %t %t5
-# RUN: llvm-objdump --section-headers %t5 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
+# RUN: llvm-readobj --section-headers %t5 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
 
-# SECTIONS: .symtab
+# SECTIONS:      Name: .symtab
+# SECTIONS:      Link
+# SECTIONS-SAME:     : 0

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/weaken.test b/llvm/test/tools/llvm-objcopy/ELF/weaken.test
index 3c4a71136069..a23a4fc0fbc8 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/weaken.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/weaken.test
@@ -1,11 +1,12 @@
 # RUN: yaml2obj %s -o %t
-# RUN: llvm-objcopy --weaken-symbol Global -W Local -W Weak %t %t2
+# RUN: llvm-objcopy --weaken-symbol Global -W Local -W Weak -W Missing %t %t2
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s
-# RUN: llvm-objcopy --regex --weaken-symbol='.*' %t %t3
+# RUN: llvm-objcopy --regex --weaken-symbol='[LGW].*' %t %t3
 # RUN: cmp %t2 %t3
 # RUN: echo "  Global  # comment" > %t-list.txt
 # RUN: echo "Local" >> %t-list.txt
 # RUN: echo "Weak" >> %t-list.txt
+# RUN: echo "Missing" >> %t-list.txt
 # RUN: echo " # comment" >> %t-list.txt
 # RUN: llvm-objcopy --weaken-symbols %t-list.txt %t %t4
 # RUN: cmp %t2 %t4
@@ -45,6 +46,9 @@ Symbols:
     Section:  .text
     Value:    0x1008
     Binding:  STB_WEAK
+  - Name:     Unspecified
+    Section:  .text
+    Binding:  STB_GLOBAL
 
 #CHECK: Symbols [
 #CHECK-NEXT:  Symbol {
@@ -83,4 +87,13 @@ Symbols:
 #CHECK-NEXT:    Other: 0
 #CHECK-NEXT:    Section: .text
 #CHECK-NEXT:  }
+#CHECK-NEXT:  Symbol {
+#CHECK-NEXT:    Name: Unspecified
+#CHECK-NEXT:    Value: 0x0
+#CHECK-NEXT:    Size: 0
+#CHECK-NEXT:    Binding: Global
+#CHECK-NEXT:    Type: None
+#CHECK-NEXT:    Other: 0
+#CHECK-NEXT:    Section: .text
+#CHECK-NEXT:  }
 #CHECK-NEXT:]

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/wildcard-flags.test b/llvm/test/tools/llvm-objcopy/ELF/wildcard-flags.test
index 49f183858822..7d31e8100838 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/wildcard-flags.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/wildcard-flags.test
@@ -62,6 +62,14 @@
 # RUN: llvm-strip --discard-all -w --keep-symbol='f*' %t.o -o %t.ksym.4.o
 # RUN: cmp %t.ksym.3.o %t.ksym.4.o
 
+## --keep-symbols:
+# RUN: echo 'f*' > %t-fstar.txt
+# RUN: llvm-objcopy --discard-all --keep-symbols=%t-fstar.txt %t.o %t.ksym.5.o
+# RUN: cmp %t.ksym.5.o %t.ksym.1.o
+
+# RUN: llvm-objcopy --discard-all -w --keep-symbols=%t-fstar.txt %t.o %t.ksym.6.o
+# RUN: cmp %t.ksym.6.o %t.ksym.3.o
+
 ## --localize-symbol:
 ## Note: Use %t.globsym.2.o instead of %t.o since those symbols are global.
 # RUN: llvm-objcopy --localize-symbol='*' %t.globsym.2.o %t.localsym.1.o
@@ -74,6 +82,14 @@
 # RUN:   | FileCheck %s --implicit-check-not=Name: \
 # RUN:       --check-prefixes=CHECK,LOCAL,FOO-SYM,BAR-SYM
 
+## --localize-symbols:
+# RUN: echo '*' > %t-star.txt
+# RUN: llvm-objcopy --localize-symbols=%t-star.txt %t.globsym.2.o %t.localsym.3.o
+# RUN: cmp %t.localsym.3.o %t.localsym.1.o
+
+# RUN: llvm-objcopy -w --localize-symbols=%t-star.txt %t.globsym.2.o %t.localsym.4.o
+# RUN: cmp %t.localsym.4.o %t.localsym.2.o
+
 ## --strip-symbol:
 # RUN: llvm-objcopy --strip-symbol='f*' %t.o %t.stripsym.1.o
 # RUN: llvm-readobj --symbols %t.stripsym.1.o \
@@ -87,6 +103,13 @@
 # RUN: llvm-strip -w --strip-symbol='f*' %t.o -o %t.stripsym.4.o
 # RUN: cmp %t.stripsym.3.o %t.stripsym.4.o
 
+## --strip-symbols:
+# RUN: llvm-objcopy --strip-symbols=%t-fstar.txt %t.o %t.stripsym.5.o
+# RUN: cmp %t.stripsym.5.o %t.stripsym.1.o
+
+# RUN: llvm-objcopy -w --strip-symbols=%t-fstar.txt %t.o %t.stripsym.6.o
+# RUN: cmp %t.stripsym.6.o %t.stripsym.3.o
+
 ## --strip-unneeded-symbol:
 # RUN: llvm-objcopy --strip-unneeded-symbol='f*' %t.o %t.stripunsym.1.o
 # RUN: llvm-readobj --symbols %t.stripunsym.1.o \
@@ -96,6 +119,13 @@
 # RUN: llvm-readobj --symbols %t.stripunsym.2.o \
 # RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR-SYM
 
+## --strip-unneded-symbols:
+# RUN: llvm-objcopy --strip-unneeded-symbols=%t-fstar.txt %t.o %t.stripunsym.3.o
+# RUN: cmp %t.stripunsym.3.o %t.stripunsym.1.o
+
+# RUN: llvm-objcopy -w --strip-unneeded-symbols=%t-fstar.txt %t.o %t.stripunsym.4.o
+# RUN: cmp %t.stripunsym.4.o %t.stripunsym.2.o
+
 ## --weaken-symbol:
 ## Note: Use %t.globsym.2.o instead of %t.o since those symbols are global.
 # RUN: llvm-objcopy --weaken-symbol='*' %t.globsym.2.o %t.weaksym.1.o
@@ -108,6 +138,13 @@
 # RUN:   | FileCheck %s --implicit-check-not=Name: \
 # RUN:       --check-prefixes=CHECK,WEAK,FOO-SYM,BAR-SYM
 
+## --weaken-symbols:
+# RUN: llvm-objcopy --weaken-symbols=%t-star.txt %t.globsym.2.o %t.weaksym.3.o
+# RUN: cmp %t.weaksym.3.o %t.weaksym.1.o
+
+# RUN: llvm-objcopy -w --weaken-symbols=%t-star.txt %t.globsym.2.o %t.weaksym.4.o
+# RUN: cmp %t.weaksym.4.o %t.weaksym.2.o
+
 ## --keep-global-symbol:
 ## Note: Use %t.globsym.2.o instead of %t.o since those symbols are global.
 # RUN: llvm-objcopy --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.1.o
@@ -120,9 +157,16 @@
 # RUN:   | FileCheck %s --implicit-check-not=Name: \
 # RUN:       --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
 
+## --keep-global-symbols:
+# RUN: llvm-objcopy --keep-global-symbols=%t-star.txt %t.globsym.2.o %t.keepgsym.3.o
+# RUN: cmp %t.keepgsym.3.o %t.keepgsym.1.o
+
+# RUN: llvm-objcopy -w --keep-global-symbols=%t-star.txt %t.globsym.2.o %t.keepgsym.4.o
+# RUN: cmp %t.keepgsym.4.o %t.keepgsym.2.o
+
 ## Check that -w is accepted as an alias for --wildcard.
-# RUN: llvm-objcopy --wildcard --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.3.o
-# RUN: cmp %t.keepgsym.2.o %t.keepgsym.3.o
+# RUN: llvm-objcopy --wildcard --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.5.o
+# RUN: cmp %t.keepgsym.2.o %t.keepgsym.5.o
 
 # CHECK:   LoadName:
 # CHECK:   Name: (0)


        


More information about the llvm-commits mailing list