llvm.org GIT mirror llvm / release_80 test / tools / llvm-objcopy / ELF / keep-global-symbols.test
release_80

Tree @release_80 (Download .tar.gz)

keep-global-symbols.test @release_80raw · history · blame

# RUN: yaml2obj %s > %t.o

# Tests that only global symbols (via -G/--keep-global-symbols) are kept via
# the several different variants of -G/--keep-global-symbol(s).
#
# Local1: Local because "-G Local1" doesn't make symbols global.
# Local2: Global because of "--globalize-symbol Local2".
# Weak1: Weak because "-G Weak1" doesn't make symbols global.
# Weak2: Global because of "--globalize-symbol Weak2".
# Weak3: Local because no -G flag covers it.
# Global1: Global because of "-G Global1".
# Global2: Global because of "--keep-global-symbol Global2".
# Global3: Global because of "--keep-global-symbols %t-globals1.txt".
# Global4: Global because of "--keep-global-symbols %t-globals2.txt".
# Global5: Local, it appears in %t-globals2.txt but only in comments and as
#     part of another symbol
# Global6: Local, it appears in %t-globals2.txt but only part of another symbol
# "Global5 Global6": Global, because it appears in %t-globals2.txt, but we only
#     trim leading and trailing whitespace. We don't just take the first chunk
#     that looks like a symbol.
# Global7: Global, because even though it doesn't appear as any -G flags, does
#     not get demoted since it's undefined.

# RUN: echo Global2 > %t-globals1.txt
# RUN: echo "  Global3  " > %t-globals2.txt
# RUN: echo "Global4 # Global5" >> %t-globals2.txt
# RUN: echo "  Global5 Global6  " >> %t-globals2.txt
# RUN: echo "Unknown" >> %t-globals2.txt
# RUN: echo "   " >> %t-globals2.txt
# RUN: echo "# File with no symbols" > %t-globals3.txt

# RUN: llvm-objcopy \
# RUN:   -G Global1 \
# RUN:   --keep-global-symbol Global2 \
# RUN:   --keep-global-symbols %t-globals1.txt \
# RUN:   --keep-global-symbols %t-globals2.txt \
# RUN:   -G Local1 \
# RUN:   --globalize-symbol Local2 \
# RUN:   -G Weak1 \
# RUN:   --globalize-symbol Weak2 \
# RUN:   %t.o %t.2.o
# RUN: llvm-readobj --elf-output-style=GNU --symbols %t.2.o | FileCheck %s

!ELF
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  Type:            ET_REL
  Machine:         EM_X86_64
Sections:
  - Name:          .text
    Type:          SHT_PROGBITS
    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
Symbols:
  Local:
    - Name:        Local1
      Section:     .text
    - Name:        Local2
      Section:     .text
  Weak:
    - Name:        Weak1
      Section:     .text
    - Name:        Weak2
      Section:     .text
    - Name:        Weak3
      Section:     .text
  Global:
    - Name:        Global1
      Section:     .text
    - Name:        Global2
      Section:     .text
    - Name:        Global3
      Section:     .text
    - Name:        Global4
      Section:     .text
    - Name:        Global5
      Section:     .text
    - Name:        Global6
      Section:     .text
    - Name:        "Global5 Global6"
      Section:     .text
    - Name:        Global7

# CHECK:      Symbol table '.symtab' contains 14 entries:
# CHECK-NEXT:    Num: Value Size Type Bind Vis Ndx Name
# CHECK-NEXT:      0: {{.*}}  LOCAL  {{.*}}
# CHECK-NEXT:      1: {{.*}}  LOCAL  {{.*}} Local1
# CHECK-NEXT:      2: {{.*}}  LOCAL  {{.*}} Global5
# CHECK-NEXT:      3: {{.*}}  LOCAL  {{.*}} Global6
# CHECK-NEXT:      4: {{.*}}  LOCAL  {{.*}} Weak3
# CHECK-NEXT:      5: {{.*}}  GLOBAL {{.*}} Local2
# CHECK-NEXT:      6: {{.*}}  GLOBAL {{.*}} Global1
# CHECK-NEXT:      7: {{.*}}  GLOBAL {{.*}} Global2
# CHECK-NEXT:      8: {{.*}}  GLOBAL {{.*}} Global3
# CHECK-NEXT:      9: {{.*}}  GLOBAL {{.*}} Global4
# CHECK-NEXT:     10: {{.*}}  GLOBAL {{.*}} Global5 Global6
# CHECK-NEXT:     11: {{.*}}  GLOBAL {{.*}} UND Global7
# CHECK-NEXT:     12: {{.*}}  WEAK   {{.*}} Weak1
# CHECK-NEXT:     13: {{.*}}  GLOBAL {{.*}} Weak2