1 # REQUIRES: x86-registered-target
3 ## It is possible for the section header table and symbol table to share the
4 ## same string table for storing section and symbol names. This test shows that
5 ## under various circumstances, the names are still correct after llvm-objcopy
6 ## has copied such an object file, and that the name table is still shared.
7 ## This test uses the assembler rather than yaml2obj because yaml2obj generates
8 ## separate string tables, whereas the assembler shares them.
10 # RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux %s -o %t.o
11 ## Verify check that the string tables are shared:
12 # RUN: llvm-readobj --section-headers %t.o \
13 # RUN: | FileCheck %s --check-prefix=VALIDATE --implicit-check-not=.shstrtab
15 # VALIDATE: Name: .strtab
17 ## Case 1: basic copy.
18 # RUN: llvm-objcopy %t.o %t.basic
19 # RUN: llvm-readobj --section-headers --symbols %t.basic \
20 # RUN: | FileCheck %s --check-prefix=BASIC --implicit-check-not=.shstrtab
23 # BASIC: Name: .strtab (
28 ## Case 2: renaming a section.
29 # RUN: llvm-objcopy %t.o %t.rename-section --rename-section .foo=.oof
30 # RUN: llvm-readobj --section-headers --symbols %t.rename-section \
31 # RUN: | FileCheck %s --check-prefix=SECTION-RENAME --implicit-check-not=.shstrtab
33 # SECTION-RENAME: Sections [
34 # SECTION-RENAME: Name: .strtab (
35 # SECTION-RENAME: Name: .oof (
36 # SECTION-RENAME: Symbols [
37 # SECTION-RENAME: Name: foo (
39 ## Case 3: renaming a symbol.
40 # RUN: llvm-objcopy %t.o %t.redefine-symbol --redefine-sym foo=oof
41 # RUN: llvm-readobj --section-headers --symbols %t.redefine-symbol \
42 # RUN: | FileCheck %s --check-prefix=SYMBOL-RENAME --implicit-check-not=.shstrtab
44 # SYMBOL-RENAME: Sections [
45 # SYMBOL-RENAME: Name: .strtab (
46 # SYMBOL-RENAME: Name: .foo (
47 # SYMBOL-RENAME: Symbols [
48 # SYMBOL-RENAME: Name: oof (
50 ## Case 4: removing a section.
51 # RUN: llvm-objcopy %t.o %t.remove-section -R .foo
52 # RUN: llvm-readobj --section-headers --symbols %t.remove-section \
53 # RUN: | FileCheck %s --check-prefix=SECTION-REMOVE --implicit-check-not=.shstrtab --implicit-check-not=.foo
55 # SECTION-REMOVE: Sections [
56 # SECTION-REMOVE: Name: .strtab (
57 # SECTION-REMOVE: Symbols [
58 # SECTION-REMOVE: Name: foo (
60 ## Case 5: removing a symbol.
61 # RUN: llvm-objcopy %t.o %t.remove-symbol -N foo
62 # RUN: llvm-readobj --section-headers --symbols %t.remove-symbol \
63 # RUN: | FileCheck %s --check-prefix=SYMBOL-REMOVE --implicit-check-not=.shstrtab --implicit-check-not="Name: foo"
65 # SYMBOL-REMOVE: Sections [
66 # SYMBOL-REMOVE: Name: .strtab (
67 # SYMBOL-REMOVE: Name: .foo (
68 # SYMBOL-REMOVE: Symbols [
70 ## Case 6: adding a section.
71 # RUN: llvm-objcopy %t.o %t.add-section --add-section .bar=%s
72 # RUN: llvm-readobj --section-headers --symbols %t.add-section \
73 # RUN: | FileCheck %s --check-prefix=SECTION-ADD --implicit-check-not=.shstrtab
75 # SECTION-ADD: Sections [
76 # SECTION-ADD: Name: .strtab (
77 # SECTION-ADD: Name: .foo (
78 # SECTION-ADD: Name: .bar (
79 # SECTION-ADD: Symbols [
80 # SECTION-ADD: Name: foo (
82 ## Case 7: adding a symbol.
83 # RUN: llvm-objcopy %t.o %t.add-symbol --add-symbol bar=0x1234
84 # RUN: llvm-readobj --section-headers --symbols %t.add-symbol \
85 # RUN: | FileCheck %s --check-prefix=SYMBOL-ADD --implicit-check-not=.shstrtab
87 # SYMBOL-ADD: Sections [
88 # SYMBOL-ADD: Name: .strtab (
89 # SYMBOL-ADD: Name: .foo (
90 # SYMBOL-ADD: Symbols [
91 # SYMBOL-ADD: Name: foo (
92 # SYMBOL-ADD: Name: bar (
94 ## Case 8: removing all symbols.
95 # RUN: llvm-objcopy %t.o %t.strip-all --strip-all
96 # RUN: llvm-readobj --section-headers --symbols %t.strip-all \
97 # RUN: | FileCheck %s --check-prefix=STRIP-ALL --implicit-check-not=.shstrtab
99 # STRIP-ALL: Sections [
100 # STRIP-ALL: Name: .strtab (
101 # STRIP-ALL: Name: .foo (
102 # STRIP-ALL: Symbols [
105 .section .foo,"a",@progbits