Skip to content

Commit 0557c2d

Browse files
committed
[llvm] Fix MachO exports trie parsing.
The exports trie parser ordinal validation check doesn't consider the case where the ordinal can be zero or negative for certain special values that are defined in BindSpecialDylib. Update the validation to account for that fact and add a test case. This fixes rdar://94844233. Differential Revision: https://reviews.llvm.org/D127806
1 parent 601ec17 commit 0557c2d

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2997,7 +2997,9 @@ void ExportEntry::pushNode(uint64_t offset) {
29972997
return;
29982998
}
29992999
if (O != nullptr) {
3000-
if (State.Other > O->getLibraryCount()) {
3000+
// Only positive numbers represent library ordinals. Zero and negative
3001+
// numbers have special meaning (see BindSpecialDylib).
3002+
if ((int64_t)State.Other > 0 && State.Other > O->getLibraryCount()) {
30013003
*E = malformedError(
30023004
"bad library ordinal: " + Twine((int)State.Other) + " (max " +
30033005
Twine((int)O->getLibraryCount()) +
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RUN: rm -rf %t && mkdir -p %t
2+
RUN: yaml2obj %p/../Inputs/MachO/flat-reexport.yaml -o %t/flat-reexport
3+
RUN: llvm-nm --dyldinfo-only %t/flat-reexport | FileCheck %s
4+
5+
CHECK-NOT: error
6+
CHECK: _fputc
7+
CHECK: _sym1
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# echo "_fputc" >> reexports.exp
2+
# echo "void sym1(void){}" | xcrun clang --target=arm64-apple-macos11.0 -o flat-reexport -dynamiclib -Wl,-reexported_symbols_list,reexports.exp -Wl,-flat_namespace -x c -
3+
# obj2yaml --raw-segment=data --raw-segment=linkedit flat-reexport > flat-reexport.yaml
4+
--- !mach-o
5+
FileHeader:
6+
magic: 0xFEEDFACF
7+
cputype: 0x100000C
8+
cpusubtype: 0x0
9+
filetype: 0x6
10+
ncmds: 13
11+
sizeofcmds: 672
12+
flags: 0x108004
13+
reserved: 0x0
14+
LoadCommands:
15+
- cmd: LC_SEGMENT_64
16+
cmdsize: 232
17+
segname: __TEXT
18+
vmaddr: 0
19+
vmsize: 16384
20+
fileoff: 0
21+
filesize: 16384
22+
maxprot: 5
23+
initprot: 5
24+
nsects: 2
25+
flags: 0
26+
Sections:
27+
- sectname: __text
28+
segname: __TEXT
29+
addr: 0x3FB4
30+
size: 4
31+
offset: 0x3FB4
32+
align: 2
33+
reloff: 0x0
34+
nreloc: 0
35+
flags: 0x80000400
36+
reserved1: 0x0
37+
reserved2: 0x0
38+
reserved3: 0x0
39+
content: C0035FD6
40+
- sectname: __unwind_info
41+
segname: __TEXT
42+
addr: 0x3FB8
43+
size: 72
44+
offset: 0x3FB8
45+
align: 2
46+
reloff: 0x0
47+
nreloc: 0
48+
flags: 0x0
49+
reserved1: 0x0
50+
reserved2: 0x0
51+
reserved3: 0x0
52+
content: 010000001C000000000000001C000000000000001C00000002000000B43F00003400000034000000B93F00000000000034000000030000000C000100100001000000000000000002
53+
- cmd: LC_SEGMENT_64
54+
cmdsize: 72
55+
segname: __LINKEDIT
56+
vmaddr: 16384
57+
vmsize: 16384
58+
fileoff: 16384
59+
filesize: 442
60+
maxprot: 1
61+
initprot: 1
62+
nsects: 0
63+
flags: 0
64+
- cmd: LC_ID_DYLIB
65+
cmdsize: 40
66+
dylib:
67+
name: 24
68+
timestamp: 1
69+
current_version: 0
70+
compatibility_version: 0
71+
Content: flat-reexport
72+
ZeroPadBytes: 3
73+
- cmd: LC_DYLD_INFO_ONLY
74+
cmdsize: 48
75+
rebase_off: 0
76+
rebase_size: 0
77+
bind_off: 0
78+
bind_size: 0
79+
weak_bind_off: 0
80+
weak_bind_size: 0
81+
lazy_bind_off: 0
82+
lazy_bind_size: 0
83+
export_off: 16384
84+
export_size: 40
85+
- cmd: LC_SYMTAB
86+
cmdsize: 24
87+
symoff: 16432
88+
nsyms: 4
89+
stroff: 16496
90+
strsize: 40
91+
- cmd: LC_DYSYMTAB
92+
cmdsize: 80
93+
ilocalsym: 0
94+
nlocalsym: 0
95+
iextdefsym: 0
96+
nextdefsym: 2
97+
iundefsym: 2
98+
nundefsym: 2
99+
tocoff: 0
100+
ntoc: 0
101+
modtaboff: 0
102+
nmodtab: 0
103+
extrefsymoff: 0
104+
nextrefsyms: 0
105+
indirectsymoff: 0
106+
nindirectsyms: 0
107+
extreloff: 0
108+
nextrel: 0
109+
locreloff: 0
110+
nlocrel: 0
111+
- cmd: LC_UUID
112+
cmdsize: 24
113+
uuid: 840B0A4F-3749-37F1-B52C-37DC65AAA0DB
114+
- cmd: LC_BUILD_VERSION
115+
cmdsize: 32
116+
platform: 1
117+
minos: 720896
118+
sdk: 787712
119+
ntools: 1
120+
Tools:
121+
- tool: 3
122+
version: 53280768
123+
- cmd: LC_SOURCE_VERSION
124+
cmdsize: 16
125+
version: 0
126+
- cmd: LC_LOAD_DYLIB
127+
cmdsize: 56
128+
dylib:
129+
name: 24
130+
timestamp: 2
131+
current_version: 85948417
132+
compatibility_version: 65536
133+
Content: '/usr/lib/libSystem.B.dylib'
134+
ZeroPadBytes: 6
135+
- cmd: LC_FUNCTION_STARTS
136+
cmdsize: 16
137+
dataoff: 16424
138+
datasize: 8
139+
- cmd: LC_DATA_IN_CODE
140+
cmdsize: 16
141+
dataoff: 16432
142+
datasize: 0
143+
- cmd: LC_CODE_SIGNATURE
144+
cmdsize: 16
145+
dataoff: 16544
146+
datasize: 282
147+
__LINKEDIT: 00015F0005000273796D310014667075746300190300B47F000C08FEFFFFFFFFFFFFFFFF01000000B47F000000000000020000000B0000000200000000000000090000000F010000B43F0000000000000F0000000100000000000000000000001600000001000000000000000000000020005F6670757463005F73796D31005F66707574630064796C645F737475625F62696E64657200000000000000000000FADE0CC00000011A000000010000000000000014FADE0C0200000106000204000002000200000066000000580000000000000005000040A02002000C000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000666C61742D72656578706F727400865F77AB8871951DEC5737A30B021C8E233E3E095F50DBA58B565C3D6E2430FBAD7FACB2586FC6E966C004D7D1D16B024F5805FF7CB47C7A85DABD8B48892CA7AD7FACB2586FC6E966C004D7D1D16B024F5805FF7CB47C7A85DABD8B48892CA7A54BC24923D5539A8353B9794289E00284149CD938F194E3682F4E35DED490FA8992AD48884D239DE460B5F73DE2583146FF7DA8718E7AD5F985E9464529B170
148+
...

0 commit comments

Comments
 (0)