llvm-project/llvm/test/tools/llvm-objcopy/ELF/set-section-flags.test
James Henderson 1562e4552c [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
2021-03-04 11:32:27 +00:00

151 lines
7.5 KiB
Plaintext

# RUN: yaml2obj %s -o %t
# Single flags on a section with no flags:
# RUN: llvm-objcopy --set-section-flags=.foo=alloc \
# RUN: --set-section-flags=.baz=alloc --set-section-flags=.rela.baz=alloc %t %t.alloc
# RUN: llvm-readobj --sections %t.alloc | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=load \
# RUN: --set-section-flags=.baz=load --set-section-flags=.rela.baz=load %t %t.load
# RUN: llvm-readobj --sections %t.load | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=noload \
# RUN: --set-section-flags=.baz=noload --set-section-flags=.rela.baz=noload %t %t.noload
# RUN: llvm-readobj --sections %t.noload | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=readonly \
# RUN: --set-section-flags=.baz=readonly --set-section-flags=.rela.baz=readonly %t %t.readonly
# RUN: llvm-readobj --sections %t.readonly | FileCheck %s --check-prefixes=CHECK,PROGBITS
# RUN: llvm-objcopy --set-section-flags=.foo=exclude \
# RUN: --set-section-flags=.baz=exclude --set-section-flags=.rela.baz=exclude %t %t.exclude
# RUN: llvm-readobj --sections %t.exclude | FileCheck %s --check-prefixes=CHECK,PROGBITS,EXCLUDE,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=debug \
# RUN: --set-section-flags=.baz=debug --set-section-flags=.rela.baz=debug %t %t.debug
# RUN: llvm-readobj --sections %t.debug | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=code \
# RUN: --set-section-flags=.baz=code --set-section-flags=.rela.baz=code %t %t.code
# RUN: llvm-readobj --sections %t.code | FileCheck %s --check-prefixes=CHECK,PROGBITS,EXEC,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=data \
# RUN: --set-section-flags=.baz=data --set-section-flags=.rela.baz=data %t %t.data
# RUN: llvm-readobj --sections %t.data | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=rom \
# RUN: --set-section-flags=.baz=rom --set-section-flags=.rela.baz=rom %t %t.rom
# RUN: llvm-readobj --sections %t.rom | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=contents \
# RUN: --set-section-flags=.baz=contents --set-section-flags=.rela.baz=contents %t %t.contents
# RUN: llvm-readobj --sections %t.contents | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=merge \
# RUN: --set-section-flags=.baz=merge --set-section-flags=.rela.baz=merge %t %t.merge
# RUN: llvm-readobj --sections %t.merge | FileCheck %s --check-prefixes=CHECK,MERGE,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=strings \
# RUN: --set-section-flags=.baz=strings --set-section-flags=.rela.baz=strings %t %t.strings
# RUN: llvm-readobj --sections %t.strings | FileCheck %s --check-prefixes=CHECK,STRINGS,PROGBITS,WRITE
# RUN: llvm-objcopy --set-section-flags=.foo=share \
# RUN: --set-section-flags=.baz=share --set-section-flags=.rela.baz=share %t %t.share
# RUN: llvm-readobj --sections %t.share | FileCheck %s --check-prefixes=CHECK,PROGBITS,WRITE
# Multiple flags:
# RUN: llvm-objcopy --set-section-flags=.foo=alloc,readonly,strings \
# RUN: --set-section-flags=.baz=alloc,readonly,strings \
# RUN: --set-section-flags=.rela.baz=alloc,readonly,strings %t %t.alloc_ro_strings
# RUN: llvm-readobj --sections %t.alloc_ro_strings | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,STRINGS
# RUN: llvm-objcopy --set-section-flags=.foo=alloc,code \
# RUN: --set-section-flags=.baz=alloc,code \
# RUN: --set-section-flags=.rela.baz=alloc,code %t %t.alloc_code
# RUN: llvm-readobj --sections %t.alloc_code | FileCheck %s --check-prefixes=CHECK,NOBITS,ALLOC,EXEC,WRITE
# Invalid flags:
# RUN: not llvm-objcopy --set-section-flags=.foo=xyzzy %t %t.xyzzy 2>&1 | FileCheck %s --check-prefix=BAD-FLAG
# Bad flag format:
# RUN: not llvm-objcopy --set-section-flags=.foo %t %t2 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
# Setting flags for the same section multiple times:
# RUN: not llvm-objcopy --set-section-flags=.foo=alloc --set-section-flags=.foo=load %t %t2 2>&1 | FileCheck %s --check-prefix=MULTIPLE-SETS
# Upper-case flags:
# RUN: llvm-objcopy --set-section-flags=.foo=ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE \
# RUN: --set-section-flags=.baz=ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE \
# RUN: --set-section-flags=.rela.baz=ALLOC,LOAD,NOLOAD,READONLY,DEBUG,CODE,DATA,ROM,CONTENTS,MERGE,STRINGS,SHARE %t %t.upper
# RUN: llvm-readobj --sections %t.upper | FileCheck %s --check-prefixes=CHECK,PROGBITS,ALLOC,EXEC,MERGE,STRINGS
# Mixed-case flags:
# RUN: llvm-objcopy --set-section-flags=.foo=aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE \
# RUN: --set-section-flags=.baz=aLlOc,LoAd,NoLoad,rEAdONly,Debug,codE,DaTa,rOm,CoNtEnTs,mErGe,sTRINGs,SharE \
# 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
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
Flags: [ ]
- Name: .baz
Type: SHT_NOBITS
Flags: [ ]
- Name: .rela.baz
Type: SHT_RELA
Info: .baz
# CHECK: Name: .foo
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# ALLOC-NEXT: SHF_ALLOC (0x2)
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
# CHECK: Name: .baz
# NOBITS-NEXT: Type: SHT_NOBITS
# PROGBITS-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# ALLOC-NEXT: SHF_ALLOC (0x2)
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
# CHECK: Name: .rela.baz
# CHECK-NEXT: Type: SHT_RELA
# CHECK-NEXT: Flags [
# ALLOC-NEXT: SHF_ALLOC (0x2)
# EXEC-NEXT: SHF_EXECINSTR (0x4)
# MERGE-NEXT: SHF_MERGE (0x10)
# STRINGS-NEXT: SHF_STRINGS (0x20)
# EXCLUDE-NEXT: SHF_EXCLUDE (0x80000000)
# WRITE-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
# BAD-FORMAT: bad format for --set-section-flags: missing '='
# 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: ]