Skip to content

Commit 40c168c

Browse files
lhamesmemfrob
authored andcommitted
[JITLink] Read symbol linkage from the correct field.
MachO symbol linkage is described by the desc field of the nlist entry, not the type field.
1 parent 8f4444b commit 40c168c

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Error MachOLinkGraphBuilder::createNormalizedSymbols() {
274274

275275
IndexToSymbol[SymbolIndex] =
276276
&createNormalizedSymbol(*Name, Value, Type, Sect, Desc,
277-
getLinkage(Type), getScope(*Name, Type));
277+
getLinkage(Desc), getScope(*Name, Type));
278278
}
279279

280280
return Error::success();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Supplies a weak def, WeakDef, and a pointer holding its address,
2+
# WeakDefAddrInExtraFile.
3+
4+
.section __TEXT,__text,regular,pure_instructions
5+
.build_version macos, 10, 14 sdk_version 10, 14
6+
.section __DATA,__data
7+
.globl WeakDef
8+
.weak_definition WeakDef
9+
.p2align 2
10+
WeakDef:
11+
.long 2
12+
13+
.globl WeakDefAddrInExtraFile
14+
.p2align 3
15+
WeakDefAddrInExtraFile:
16+
.quad WeakDef
17+
18+
19+
.subsections_via_symbols
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RUN: rm -rf %t && mkdir -p %t
2+
# RUN: llvm-mc -triple x86_64-apple-macosx10.9 -filetype=obj \
3+
# RUN: -o %t/MachO_weak_defs_extra.o %S/Inputs/MachO_weak_defs_extra.s
4+
# RUN: llvm-mc -triple x86_64-apple-macosx10.9 -filetype=obj \
5+
# RUN: -o %t/MachO_weak_definitions.o %s
6+
# RUN: llvm-jitlink -noexec -check=%s %t/MachO_weak_definitions.o \
7+
# RUN: %t/MachO_weak_defs_extra.o
8+
#
9+
# Check that objects linked separately agree on the address of weak symbols.
10+
#
11+
# jitlink-check: *{8}WeakDefAddrInThisFile = *{8}WeakDefAddrInExtraFile
12+
13+
.section __TEXT,__text,regular,pure_instructions
14+
.build_version macos, 10, 14 sdk_version 10, 14
15+
.globl _main
16+
.p2align 4, 0x90
17+
_main:
18+
retq
19+
20+
.section __DATA,__data
21+
.globl WeakDef
22+
.weak_definition WeakDef
23+
.p2align 2
24+
WeakDef:
25+
.long 1
26+
27+
.globl WeakDefAddrInThisFile
28+
.p2align 3
29+
WeakDefAddrInThisFile:
30+
.quad WeakDef
31+
32+
# Take the address of WeakDefAddrInExtraFile to force its materialization
33+
.globl extra_file_anchor
34+
.p2align 3
35+
extra_file_anchor:
36+
.quad WeakDefAddrInExtraFile
37+
38+
39+
.subsections_via_symbols

0 commit comments

Comments
 (0)