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
207 lines
7.9 KiB
Plaintext
207 lines
7.9 KiB
Plaintext
## This test checks basic functionality of glob (or "shell wildcard") matching,
|
|
## as well as verifying all the relevant flags in llvm-objcopy and llvm-strip
|
|
## are configured correctly.
|
|
## For more detailed syntax tests, see wildcard-syntax.test.
|
|
|
|
# RUN: yaml2obj %s -o %t.o
|
|
|
|
## Check that --regex and --wildcard cannot be used together.
|
|
# RUN: not llvm-objcopy --regex --wildcard %t.o %t.err.o 2>&1 \
|
|
# RUN: | FileCheck %s --check-prefix=ERR
|
|
# RUN: not llvm-strip --regex --wildcard %t.o -o %t.err.o 2>&1 \
|
|
# RUN: | FileCheck %s --check-prefix=ERR
|
|
|
|
# ERR: error: --regex and --wildcard are incompatible
|
|
|
|
## Check that section removal flags default to glob matches.
|
|
|
|
## --keep-section:
|
|
# RUN: llvm-objcopy --strip-all --keep-section='.f*' %t.o %t.ksec.1.o
|
|
# RUN: llvm-readobj --sections %t.ksec.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,SEC,FOO-SEC
|
|
# RUN: llvm-strip --strip-all --keep-section='.f*' %t.o -o %t.ksec.2.o
|
|
# RUN: cmp %t.ksec.1.o %t.ksec.2.o
|
|
|
|
## --only-section:
|
|
# RUN: llvm-objcopy --strip-all --only-section='.f*' %t.o %t.osec.1.o
|
|
# RUN: llvm-readobj --sections %t.osec.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,SEC,FOO-SEC
|
|
|
|
## --remove-section:
|
|
# RUN: llvm-objcopy --strip-debug --remove-section='.s??tab' %t.o %t.rsec.1.o
|
|
# RUN: llvm-readobj --sections %t.rsec.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: \
|
|
# RUN: --check-prefixes=CHECK,SEC,FOO-SEC,BAR-SEC
|
|
# RUN: llvm-strip --strip-debug --remove-section='.s??tab' %t.o -o %t.rsec.2.o
|
|
# RUN: cmp %t.rsec.1.o %t.rsec.2.o
|
|
|
|
## Check that symbol removal options default to literal matches. Adding -w
|
|
## enables glob support for these options.
|
|
|
|
## --globalize-symbol:
|
|
# RUN: llvm-objcopy --globalize-symbol='*' %t.o %t.globsym.1.o
|
|
# RUN: llvm-readobj --symbols %t.globsym.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: \
|
|
# RUN: --check-prefixes=CHECK,LOCAL,FOO-SYM,BAR-SYM
|
|
|
|
# RUN: llvm-objcopy -w --globalize-symbol='*' %t.o %t.globsym.2.o
|
|
# RUN: llvm-readobj --symbols %t.globsym.2.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: \
|
|
# RUN: --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
|
|
|
|
## --keep-symbol:
|
|
# RUN: llvm-objcopy --discard-all --keep-symbol='f*' %t.o %t.ksym.1.o
|
|
# RUN: llvm-readobj --symbols %t.ksym.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK
|
|
# RUN: llvm-strip --discard-all --keep-symbol='f*' %t.o -o %t.ksym.2.o
|
|
# RUN: cmp %t.ksym.1.o %t.ksym.2.o
|
|
|
|
# RUN: llvm-objcopy --discard-all -w --keep-symbol='f*' %t.o %t.ksym.3.o
|
|
# RUN: llvm-readobj --symbols %t.ksym.3.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO-SYM
|
|
# 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
|
|
# RUN: llvm-readobj --symbols %t.localsym.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: \
|
|
# RUN: --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
|
|
|
|
# RUN: llvm-objcopy -w --localize-symbol='*' %t.globsym.2.o %t.localsym.2.o
|
|
# RUN: llvm-readobj --symbols %t.localsym.2.o \
|
|
# 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 \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO-SYM,BAR-SYM
|
|
# RUN: llvm-strip --strip-symbol='f*' %t.o -o %t.stripsym.2.o
|
|
# RUN: cmp %t.stripsym.1.o %t.stripsym.2.o
|
|
|
|
# RUN: llvm-objcopy -w --strip-symbol='f*' %t.o %t.stripsym.3.o
|
|
# RUN: llvm-readobj --symbols %t.stripsym.3.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR-SYM
|
|
# 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 \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO-SYM,BAR-SYM
|
|
|
|
# RUN: llvm-objcopy -w --strip-unneeded-symbol='f*' %t.o %t.stripunsym.2.o
|
|
# 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
|
|
# RUN: llvm-readobj --symbols %t.weaksym.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: \
|
|
# RUN: --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
|
|
|
|
# RUN: llvm-objcopy -w --weaken-symbol='*' %t.globsym.2.o %t.weaksym.2.o
|
|
# RUN: llvm-readobj --symbols %t.weaksym.2.o \
|
|
# 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
|
|
# RUN: llvm-readobj --symbols %t.keepgsym.1.o \
|
|
# RUN: | FileCheck %s --implicit-check-not=Name: \
|
|
# RUN: --check-prefixes=CHECK,LOCAL,FOO-SYM,BAR-SYM
|
|
|
|
# RUN: llvm-objcopy -w --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.2.o
|
|
# RUN: llvm-readobj --symbols %t.keepgsym.2.o \
|
|
# 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.5.o
|
|
# RUN: cmp %t.keepgsym.2.o %t.keepgsym.5.o
|
|
|
|
# CHECK: LoadName:
|
|
# CHECK: Name: (0)
|
|
|
|
# FOO-SEC: Name: .foo
|
|
|
|
# FOO-SYM: Name: foo
|
|
# GLOBAL: Binding: Global
|
|
# WEAK: Binding: Weak
|
|
# LOCAL: Binding: Local
|
|
|
|
# BAR-SEC: Name: .bar
|
|
# BAR-SYM: Name: bar
|
|
# GLOBAL: Binding: Global
|
|
# WEAK: Binding: Weak
|
|
# LOCAL: Binding: Local
|
|
|
|
# SEC: Name: .shstrtab
|
|
|
|
!ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .foo
|
|
Type: SHT_PROGBITS
|
|
- Name: .bar
|
|
Type: SHT_PROGBITS
|
|
Symbols:
|
|
- Name: foo
|
|
Type: STT_FUNC
|
|
Section: .foo
|
|
- Name: bar
|
|
Type: STT_FUNC
|
|
Section: .foo
|