Repository navigation
Commit f715ad2
authored
Strip local symbols from the macOS wheel's binaries (pytorch#22272)
## Summary
The macOS wheel carries about **7 MB of local symbols** that the Linux
wheel does not.
Both are Release builds. The difference is the linker: the GNU one
discards these, Apple's
keeps them. The Linux libraries have no `.symtab` section at all, while
every macOS one
carries a local symbol per internal function:
| file | external | local |
| --- | --- | --- |
| `libexecutorch.dylib` | 333 | 448 |
| `libexecutorch_kernels_optimized.dylib` | 1463 | 4190 |
| `data/bin/flatc` | 3737 | **35496** |
`flatc` is most of it. At 11,629,400 bytes it is 5.3 MB *larger* than
the Linux copy, and
stripped it comes to 5,571,232, which is **smaller** than Linux's
6,313,152. So this one file
explains nearly the entire size gap between the two wheels.
## The change
`strip -x` removes local symbols and keeps every external one, so
nothing a consumer can
link against changes. That flag matters: anything broader would remove
exported symbols and
break linking.
It runs on the wheel copy only, right after the runtime path rewrite
that already runs there,
and deliberately not on the editable copy, where a developer's debugger
and profiler want
those symbols. A failure warns and ships the file as built, because a
wheel that is larger
than intended beats a build that stops.
## Test plan
Measured on the published macOS arm64 wheel: native payload **32.8 MB to
25.7 MB, saving
7.2 MB (21%)**.
Stripped a copy of an installed wheel and ran from a neutral directory:
| check | result |
| --- | --- |
| exported symbol list, before vs after | identical |
| registered backends | CoreML, MLX, Vgf, Xnnpack |
| XNNPACK export + run | `[3.0, 3.0, 3.0, 3.0]` |
| MLX export + run | `[3.0, 3.0, 3.0, 3.0]` |
| C++ app via `find_package(executorch)` | builds, `load_method 0x0`,
out `3.0` x4 |
The helper itself, four ways: on a Linux file it does nothing; with no
`strip` on PATH it
returns quietly; on a real failure, tested with a read-only file, it
warns and does not
raise; and on a Mach-O library it removes 11 percent while leaving the
exported set byte
identical.1 parent f2d148b commit f715ad2
3 files changed
Lines changed: 81 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
12 | 23 | | |
13 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
8 | 19 | | |
9 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1272 | 1272 | | |
1273 | 1273 | | |
1274 | 1274 | | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
1275 | 1283 | | |
1276 | 1284 | | |
1277 | 1285 | | |
| |||
1354 | 1362 | | |
1355 | 1363 | | |
1356 | 1364 | | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1357 | 1398 | | |
1358 | 1399 | | |
1359 | 1400 | | |
| |||
0 commit comments