155c81d42SFangrui Song# RUN: yaml2obj %s -o %t.o 26e4dc6f2SAlexander Shaposhnikov 36e4dc6f2SAlexander Shaposhnikov# Tests that only global symbols (via -G/--keep-global-symbols) are kept via 46e4dc6f2SAlexander Shaposhnikov# the several different variants of -G/--keep-global-symbol(s). 56e4dc6f2SAlexander Shaposhnikov# 66e4dc6f2SAlexander Shaposhnikov# Local1: Local because "-G Local1" doesn't make symbols global. 76e4dc6f2SAlexander Shaposhnikov# Local2: Global because of "--globalize-symbol Local2". 86e4dc6f2SAlexander Shaposhnikov# Weak1: Weak because "-G Weak1" doesn't make symbols global. 96e4dc6f2SAlexander Shaposhnikov# Weak2: Global because of "--globalize-symbol Weak2". 106e4dc6f2SAlexander Shaposhnikov# Weak3: Local because no -G flag covers it. 116e4dc6f2SAlexander Shaposhnikov# Global1: Global because of "-G Global1". 126e4dc6f2SAlexander Shaposhnikov# Global2: Global because of "--keep-global-symbol Global2". 136e4dc6f2SAlexander Shaposhnikov# Global3: Global because of "--keep-global-symbols %t-globals1.txt". 146e4dc6f2SAlexander Shaposhnikov# Global4: Global because of "--keep-global-symbols %t-globals2.txt". 156e4dc6f2SAlexander Shaposhnikov# Global5: Local, it appears in %t-globals2.txt but only in comments and as 166e4dc6f2SAlexander Shaposhnikov# part of another symbol 176e4dc6f2SAlexander Shaposhnikov# Global6: Local, it appears in %t-globals2.txt but only part of another symbol 186e4dc6f2SAlexander Shaposhnikov# "Global5 Global6": Global, because it appears in %t-globals2.txt, but we only 196e4dc6f2SAlexander Shaposhnikov# trim leading and trailing whitespace. We don't just take the first chunk 206e4dc6f2SAlexander Shaposhnikov# that looks like a symbol. 216e4dc6f2SAlexander Shaposhnikov# Global7: Global, because even though it doesn't appear as any -G flags, does 226e4dc6f2SAlexander Shaposhnikov# not get demoted since it's undefined. 236e4dc6f2SAlexander Shaposhnikov 246e4dc6f2SAlexander Shaposhnikov# RUN: echo Global2 > %t-globals1.txt 256e4dc6f2SAlexander Shaposhnikov# RUN: echo " Global3 " > %t-globals2.txt 266e4dc6f2SAlexander Shaposhnikov# RUN: echo "Global4 # Global5" >> %t-globals2.txt 276e4dc6f2SAlexander Shaposhnikov# RUN: echo " Global5 Global6 " >> %t-globals2.txt 286e4dc6f2SAlexander Shaposhnikov# RUN: echo "Unknown" >> %t-globals2.txt 296e4dc6f2SAlexander Shaposhnikov# RUN: echo " " >> %t-globals2.txt 306e4dc6f2SAlexander Shaposhnikov# RUN: echo "# File with no symbols" > %t-globals3.txt 31f324f6dcSEugene Leviant# RUN: echo "^Global[0-9]+([[:space:]]Global6)*$" > %t-globals-regexp.txt 326e4dc6f2SAlexander Shaposhnikov 336e4dc6f2SAlexander Shaposhnikov# RUN: llvm-objcopy \ 346e4dc6f2SAlexander Shaposhnikov# RUN: -G Global1 \ 356e4dc6f2SAlexander Shaposhnikov# RUN: --keep-global-symbol Global2 \ 366e4dc6f2SAlexander Shaposhnikov# RUN: --keep-global-symbols %t-globals1.txt \ 376e4dc6f2SAlexander Shaposhnikov# RUN: --keep-global-symbols %t-globals2.txt \ 386e4dc6f2SAlexander Shaposhnikov# RUN: -G Local1 \ 396e4dc6f2SAlexander Shaposhnikov# RUN: --globalize-symbol Local2 \ 406e4dc6f2SAlexander Shaposhnikov# RUN: -G Weak1 \ 416e4dc6f2SAlexander Shaposhnikov# RUN: --globalize-symbol Weak2 \ 426e4dc6f2SAlexander Shaposhnikov# RUN: %t.o %t.2.o 4397c17e83SFangrui Song# RUN: llvm-readelf --symbols %t.2.o | FileCheck %s 446e4dc6f2SAlexander Shaposhnikov 45f324f6dcSEugene Leviant# RUN: llvm-objcopy --regex --keep-global-symbols %t-globals-regexp.txt %t.o %t.3.o 4697c17e83SFangrui Song# RUN: llvm-readelf --symbols %t.3.o | FileCheck %s --check-prefix=REGEXP 47f324f6dcSEugene Leviant 48*1562e455SJames Henderson# RUN: llvm-objcopy --regex --keep-global-symbol='^Global[0-9]+([[:space:]]Global6)*$' %t.o %t.4.o 49*1562e455SJames Henderson# RUN: cmp %t.3.o %t.4.o 50*1562e455SJames Henderson 516e4dc6f2SAlexander Shaposhnikov!ELF 526e4dc6f2SAlexander ShaposhnikovFileHeader: 536e4dc6f2SAlexander Shaposhnikov Class: ELFCLASS64 546e4dc6f2SAlexander Shaposhnikov Data: ELFDATA2LSB 556e4dc6f2SAlexander Shaposhnikov Type: ET_REL 566e4dc6f2SAlexander Shaposhnikov Machine: EM_X86_64 576e4dc6f2SAlexander ShaposhnikovSections: 586e4dc6f2SAlexander Shaposhnikov - Name: .text 596e4dc6f2SAlexander Shaposhnikov Type: SHT_PROGBITS 606e4dc6f2SAlexander Shaposhnikov Flags: [ SHF_ALLOC, SHF_EXECINSTR ] 616e4dc6f2SAlexander ShaposhnikovSymbols: 626e4dc6f2SAlexander Shaposhnikov - Name: Local1 636e4dc6f2SAlexander Shaposhnikov Section: .text 646e4dc6f2SAlexander Shaposhnikov - Name: Local2 656e4dc6f2SAlexander Shaposhnikov Section: .text 666e4dc6f2SAlexander Shaposhnikov - Name: Global1 676e4dc6f2SAlexander Shaposhnikov Section: .text 686da44ad7SGeorge Rimar Binding: STB_GLOBAL 696e4dc6f2SAlexander Shaposhnikov - Name: Global2 706e4dc6f2SAlexander Shaposhnikov Section: .text 716da44ad7SGeorge Rimar Binding: STB_GLOBAL 726e4dc6f2SAlexander Shaposhnikov - Name: Global3 736e4dc6f2SAlexander Shaposhnikov Section: .text 746da44ad7SGeorge Rimar Binding: STB_GLOBAL 756e4dc6f2SAlexander Shaposhnikov - Name: Global4 766e4dc6f2SAlexander Shaposhnikov Section: .text 776da44ad7SGeorge Rimar Binding: STB_GLOBAL 786e4dc6f2SAlexander Shaposhnikov - Name: Global5 796e4dc6f2SAlexander Shaposhnikov Section: .text 806da44ad7SGeorge Rimar Binding: STB_GLOBAL 816e4dc6f2SAlexander Shaposhnikov - Name: Global6 826e4dc6f2SAlexander Shaposhnikov Section: .text 836da44ad7SGeorge Rimar Binding: STB_GLOBAL 846e4dc6f2SAlexander Shaposhnikov - Name: "Global5 Global6" 856e4dc6f2SAlexander Shaposhnikov Section: .text 866da44ad7SGeorge Rimar Binding: STB_GLOBAL 876e4dc6f2SAlexander Shaposhnikov - Name: Global7 886da44ad7SGeorge Rimar Binding: STB_GLOBAL 896da44ad7SGeorge Rimar - Name: Weak1 906da44ad7SGeorge Rimar Section: .text 916da44ad7SGeorge Rimar Binding: STB_WEAK 926da44ad7SGeorge Rimar - Name: Weak2 936da44ad7SGeorge Rimar Section: .text 946da44ad7SGeorge Rimar Binding: STB_WEAK 956da44ad7SGeorge Rimar - Name: Weak3 966da44ad7SGeorge Rimar Section: .text 976da44ad7SGeorge Rimar Binding: STB_WEAK 986e4dc6f2SAlexander Shaposhnikov 996e4dc6f2SAlexander Shaposhnikov# CHECK: Symbol table '.symtab' contains 14 entries: 1006e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name 1016e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 0: {{.*}} LOCAL {{.*}} 1026e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 1: {{.*}} LOCAL {{.*}} Local1 1036e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 2: {{.*}} LOCAL {{.*}} Global5 1046e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 3: {{.*}} LOCAL {{.*}} Global6 1056e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 4: {{.*}} LOCAL {{.*}} Weak3 1066e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 5: {{.*}} GLOBAL {{.*}} Local2 1076e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 6: {{.*}} GLOBAL {{.*}} Global1 1086e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 7: {{.*}} GLOBAL {{.*}} Global2 1096e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 8: {{.*}} GLOBAL {{.*}} Global3 1106e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 9: {{.*}} GLOBAL {{.*}} Global4 1116e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 10: {{.*}} GLOBAL {{.*}} Global5 Global6 1126e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 11: {{.*}} GLOBAL {{.*}} UND Global7 1136e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 12: {{.*}} WEAK {{.*}} Weak1 1146e4dc6f2SAlexander Shaposhnikov# CHECK-NEXT: 13: {{.*}} GLOBAL {{.*}} Weak2 115f324f6dcSEugene Leviant 116f324f6dcSEugene Leviant# REGEXP: 6: {{.*}} GLOBAL {{.*}} Global1 117f324f6dcSEugene Leviant# REGEXP-NEXT: 7: {{.*}} GLOBAL {{.*}} Global2 118f324f6dcSEugene Leviant# REGEXP-NEXT: 8: {{.*}} GLOBAL {{.*}} Global3 119f324f6dcSEugene Leviant# REGEXP-NEXT: 9: {{.*}} GLOBAL {{.*}} Global4 120f324f6dcSEugene Leviant# REGEXP-NEXT: 10: {{.*}} GLOBAL {{.*}} Global5 121f324f6dcSEugene Leviant# REGEXP-NEXT: 11: {{.*}} GLOBAL {{.*}} Global6 122f324f6dcSEugene Leviant# REGEXP-NEXT: 12: {{.*}} GLOBAL {{.*}} Global5 Global6 123f324f6dcSEugene Leviant# REGEXP-NEXT: 13: {{.*}} GLOBAL {{.*}} UND Global7 124