Skip to content

Commit 5273773

Browse files
committed
[JITLink] Allow duplicate symbol names for locals
Local symbols can have the same name. I ran into this with JITLink while working with an object file that had been run through `strip -S` that had many "func.eh" symbols, but it can also happen using `ld -r`. rdar://85352156 Differential Revision: https://reviews.llvm.org/D114042
1 parent f07ddbc commit 5273773

File tree

2 files changed

+128
-5
lines changed

2 files changed

+128
-5
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,11 @@ class LinkGraph {
11201120
Symbol &addDefinedSymbol(Block &Content, JITTargetAddress Offset,
11211121
StringRef Name, JITTargetAddress Size, Linkage L,
11221122
Scope S, bool IsCallable, bool IsLive) {
1123-
assert(llvm::count_if(defined_symbols(),
1124-
[&](const Symbol *Sym) {
1125-
return Sym->getName() == Name;
1126-
}) == 0 &&
1127-
"Duplicate defined symbol");
1123+
assert(S == Scope::Local || llvm::count_if(defined_symbols(),
1124+
[&](const Symbol *Sym) {
1125+
return Sym->getName() == Name;
1126+
}) == 0 &&
1127+
"Duplicate defined symbol");
11281128
auto &Sym =
11291129
Symbol::constructNamedDef(Allocator.Allocate<Symbol>(), Content, Offset,
11301130
Name, Size, L, S, IsLive, IsCallable);
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: llvm-jitlink -noexec -show-graph %t | FileCheck %s
3+
4+
# The below describes an object with two local symbols named _foo, each
5+
# referenced by _main to keep it live. Ensure we can link it.
6+
7+
# CHECK: scope: local, live - _foo
8+
# CHECK: scope: local, live - _foo
9+
# CHECK: scope: default, live - _main
10+
# CHECK-NEXT: edges:
11+
# CHECK-NEXT: target = _foo
12+
# CHECK-NEXT: target = _foo
13+
14+
--- !mach-o
15+
FileHeader:
16+
magic: 0xFEEDFACF
17+
cputype: 0x1000007
18+
cpusubtype: 0x3
19+
filetype: 0x1
20+
ncmds: 4
21+
sizeofcmds: 280
22+
flags: 0x0
23+
reserved: 0x0
24+
LoadCommands:
25+
- cmd: LC_SEGMENT_64
26+
cmdsize: 152
27+
segname: ''
28+
vmaddr: 0
29+
vmsize: 13
30+
fileoff: 312
31+
filesize: 13
32+
maxprot: 7
33+
initprot: 7
34+
nsects: 1
35+
flags: 0
36+
Sections:
37+
- sectname: __text
38+
segname: __TEXT
39+
addr: 0x0
40+
size: 13
41+
offset: 0x138
42+
align: 0
43+
reloff: 0x145
44+
nreloc: 2
45+
flags: 0x80000400
46+
reserved1: 0x0
47+
reserved2: 0x0
48+
reserved3: 0x0
49+
content: 9090E800000000E80000000090
50+
relocations:
51+
- address: 0x8
52+
symbolnum: 1
53+
pcrel: true
54+
length: 2
55+
extern: true
56+
type: 2
57+
scattered: false
58+
value: 0
59+
- address: 0x3
60+
symbolnum: 0
61+
pcrel: true
62+
length: 2
63+
extern: true
64+
type: 2
65+
scattered: false
66+
value: 0
67+
- cmd: LC_BUILD_VERSION
68+
cmdsize: 24
69+
platform: 1
70+
minos: 786432
71+
sdk: 0
72+
ntools: 0
73+
- cmd: LC_SYMTAB
74+
cmdsize: 24
75+
symoff: 341
76+
nsyms: 3
77+
stroff: 389
78+
strsize: 16
79+
- cmd: LC_DYSYMTAB
80+
cmdsize: 80
81+
ilocalsym: 0
82+
nlocalsym: 2
83+
iextdefsym: 2
84+
nextdefsym: 1
85+
iundefsym: 3
86+
nundefsym: 0
87+
tocoff: 0
88+
ntoc: 0
89+
modtaboff: 0
90+
nmodtab: 0
91+
extrefsymoff: 0
92+
nextrefsyms: 0
93+
indirectsymoff: 0
94+
nindirectsyms: 0
95+
extreloff: 0
96+
nextrel: 0
97+
locreloff: 0
98+
nlocrel: 0
99+
LinkEditData:
100+
NameList:
101+
- n_strx: 1
102+
n_type: 0xE
103+
n_sect: 1
104+
n_desc: 0
105+
n_value: 0
106+
- n_strx: 1
107+
n_type: 0xE
108+
n_sect: 1
109+
n_desc: 0
110+
n_value: 1
111+
- n_strx: 6
112+
n_type: 0xF
113+
n_sect: 1
114+
n_desc: 0
115+
n_value: 2
116+
StringTable:
117+
- ''
118+
- _foo
119+
- _main
120+
- ''
121+
- ''
122+
- ''
123+
- ''

0 commit comments

Comments
 (0)