File: add-symbol-no-symtab.test

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (130 lines) | stat: -rw-r--r-- 3,812 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
## Test --add-symbol creates .symtab if it does not exist.

# RUN: yaml2obj --docnum=1 %s -o %t

## If a non-SHF_ALLOC SHT_STRTAB exists but SHT_SYMTAB does not, create .symtab
## and set its sh_link to the SHT_STRTAB.
# RUN: llvm-objcopy --remove-section=.symtab %t %t.no.symtab
# RUN: llvm-objcopy --add-symbol='abs1=1' %t.no.symtab %t.add.both
# RUN: llvm-readobj -S %t.add.both | FileCheck --check-prefix=SEC %s
# RUN: llvm-readelf -s %t.add.both | FileCheck %s

# SEC:      Index: 1
# SEC-NEXT: Name: .strtab
# SEC-NEXT: Type: SHT_STRTAB
# SEC:      Index: 2
# SEC-NEXT: Name: .shstrtab
# SEC-NEXT: Type: SHT_STRTAB
# SEC:      Index: 3
# SEC-NEXT: Name: .symtab
# SEC-NEXT: Type: SHT_SYMTAB
# SEC-NOT:  }
# SEC:      Link: 1

# CHECK:      0: 0000000000000000 0 NOTYPE LOCAL  DEFAULT UND
# CHECK-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT ABS abs1

## Don't create .symtab if --add-symbol is not specified.
# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t %t.no
# RUN: llvm-objcopy %t.no %t.nop
# RUN: llvm-readobj -S %t.nop | FileCheck --implicit-check-not=.symtab --implicit-check-not=.strtab /dev/null

## Reuse the existing .shstrtab (section names) for symbol names.
## This may look strange but it works.
# RUN: llvm-objcopy --add-symbol='abs1=1' %t.no %t.add.symtab
# RUN: llvm-readobj -S %t.add.symtab | FileCheck --check-prefix=SEC2 %s --implicit-check-not=.strtab
# RUN: llvm-readelf -s %t.add.symtab | FileCheck %s

# SEC2:      Index: 1
# SEC2-NEXT: Name: .shstrtab
# SEC2-NEXT: Type: SHT_STRTAB
# SEC2:      Index: 2
# SEC2-NEXT: Name: .symtab
# SEC2-NEXT: Type: SHT_SYMTAB
# SEC2-NOT:  }
# SEC2:      Link: 1

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Name: .strtab
    Type: SHT_STRTAB
  - Name: .shstrtab
    Type: SHT_STRTAB
Symbols: []
...

## Check that we prefer the string table that is not the section header string table.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t2 %t2.no
# RUN: llvm-objcopy --add-symbol='abs1=1' %t2.no %t2.add.symtab
# RUN: llvm-readobj -S %t2.add.symtab | FileCheck --check-prefix=SEC2 %s
# RUN: llvm-readelf -s %t2.add.symtab | FileCheck %s

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  # .shstrtab is reordered before .strtab
  - Name: .shstrtab
    Type: SHT_STRTAB
  - Name: .strtab
    Type: SHT_STRTAB
Symbols: []
...

## Check the created .symtab does not link to .dynstr (SHF_ALLOC).
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-objcopy --remove-section=.symtab --remove-section=.strtab %t3 %t3.no
# RUN: llvm-objcopy --add-symbol='abs1=1' %t3.no %t3.not.dynstr
# RUN: llvm-readobj -S %t3.not.dynstr | FileCheck --check-prefix=SEC3 %s

# SEC3:      Index: 3
# SEC3-NEXT: Name: .shstrtab
# SEC3-NEXT: Type: SHT_STRTAB
# SEC3:      Name: .symtab
# SEC3-NEXT: Type: SHT_SYMTAB
# SEC3-NOT:  }
# SEC3:      Link: 3

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
DynamicSymbols:
  - Name:    dummy
    Binding: STB_GLOBAL
Symbols: []
...

## Check the created .symtab is correct when there are program headers.
# RUN: yaml2obj --docnum=4 %s -o %t4
# RUN: llvm-objcopy %t4 %t4.add --add-symbol foo=1234
# RUN: llvm-readelf -s %t4.add | FileCheck --check-prefix=SEC4 %s

# SEC4:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND 
# SEC4-NEXT: 1: 00000000000004d2     0 NOTYPE  GLOBAL DEFAULT   ABS foo

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
Sections:
  - Name:    .foo
    Type:    SHT_PROGBITS
ProgramHeaders:
  - Type:     PT_LOAD
    FirstSec: .foo
    LastSec:  .foo
...