xref: /llvm-project/llvm/test/tools/llvm-ar/symtab.test (revision ceb9094a49134d21333150dd876fbb09a165eb3a)
1## Test the s and S modifiers. Build and do not build a symbol table.
2
3# RUN: yaml2obj %s -o %t.o
4# RUN: touch %t-other.txt
5
6## Default:
7# RUN: rm -f %t-default.a
8# RUN: llvm-ar rc %t-default.a %t.o
9# RUN: llvm-nm --print-armap %t-default.a \
10# RUN:   | FileCheck %s --check-prefix=SYMTAB
11
12## Use a modifer:
13# RUN: rm -f %t-symtab.a
14# RUN: llvm-ar rcs %t-symtab.a %t.o
15# RUN: llvm-nm --print-armap %t-symtab.a \
16# RUN:   | FileCheck %s --check-prefix=SYMTAB
17
18# RUN: rm -f %t-no-symtab.a
19# RUN: llvm-ar rcS %t-no-symtab.a %t.o
20# RUN: llvm-nm --print-armap %t-no-symtab.a \
21# RUN:   | FileCheck %s --check-prefix=NO-SYMTAB
22
23## Use both modifers:
24# RUN: rm -f %t-symtab-last.a
25# RUN: llvm-ar rcSs %t-symtab-last.a %t.o
26# RUN: llvm-nm --print-armap %t-symtab-last.a \
27# RUN:   | FileCheck %s --check-prefix=SYMTAB
28
29# RUN: rm -f %t-no-symtab-last.a
30# RUN: llvm-ar rcsS %t-no-symtab-last.a %t.o
31# RUN: llvm-nm --print-armap %t-no-symtab-last.a \
32# RUN:   | FileCheck %s --check-prefix=NO-SYMTAB
33
34## Use an existing archive:
35# RUN: rm -f %t-to-symtab.a
36# RUN: llvm-ar rcS %t-to-symtab.a %t.o
37# RUN: llvm-ar rs %t-to-symtab.a %t-other.txt
38# RUN: llvm-nm --print-armap %t-to-symtab.a \
39# RUN:   | FileCheck %s --check-prefix=SYMTAB
40
41# RUN: llvm-ar rs %t-to-symtab.a %t-other.txt
42# RUN: llvm-nm --print-armap %t-to-symtab.a \
43# RUN:   | FileCheck %s --check-prefix=SYMTAB
44
45# RUN: rm -f %t-to-no-symtab.a
46# RUN: llvm-ar rcs %t-to-no-symtab.a %t.o
47# RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt
48# RUN: llvm-nm --print-armap %t-to-no-symtab.a \
49# RUN:   | FileCheck %s --check-prefix=NO-SYMTAB
50
51# RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt
52# RUN: llvm-nm --print-armap %t-to-no-symtab.a \
53# RUN:   | FileCheck %s --check-prefix=NO-SYMTAB
54
55## Thin Archive:
56# RUN: rm -f %t-thin.a
57# RUN: llvm-ar rcT %t-thin.a %t.o
58# RUN: llvm-nm --print-armap %t-thin.a \
59# RUN:   | FileCheck %s --check-prefix=SYMTAB
60
61## llvm-ranlib does not change a thin archive to a regular one.
62# RUN: rm -f %t-thin.a && llvm-ar rcTS %t-thin.a %t.o
63# RUN: llvm-nm --print-armap %t-thin.a | FileCheck %s --check-prefix=NO-SYMTAB
64# RUN: llvm-ranlib %t-thin.a
65# RUN: llvm-nm --print-armap %t-thin.a | FileCheck %s --check-prefix=SYMTAB
66# RUN: FileCheck --input-file=%t-thin.a %s --check-prefixes=THIN
67
68## llvm-ar -s is identical to ranlib and a duplicated operation does not change the output.
69# RUN: rm -f %t-thin2.a && llvm-ar rcTS %t-thin2.a %t.o
70# RUN: llvm-ar s %t-thin2.a && cmp %t-thin.a %t-thin2.a
71# RUN: llvm-ar s %t-thin2.a && cmp %t-thin.a %t-thin2.a
72
73# SYMTAB:        symbol in
74# NO-SYMTAB-NOT: symbol in
75
76# THIN: !<thin>
77
78--- !ELF
79FileHeader:
80  Class:   ELFCLASS64
81  Data:    ELFDATA2LSB
82  Type:    ET_REL
83  Machine: EM_X86_64
84Sections:
85  - Name: .text
86    Type: SHT_PROGBITS
87Symbols:
88  - Name:    symbol
89    Binding: STB_GLOBAL
90    Section: .text
91