Skip to content

Commit 1ea0bca

Browse files
Visibility controls on public API (#121)
1 parent fa33007 commit 1ea0bca

53 files changed

Lines changed: 788 additions & 194 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2026 LiveKit
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
"""
17+
Verify that liblivekit's exported ABI does not leak private dependency symbols.
18+
19+
The LiveKit SDK statically links several private dependencies (spdlog, fmt,
20+
google::protobuf, absl). When those symbols escape the dynamic symbol table
21+
of liblivekit.{so,dylib,dll}, they collide at runtime with the same libraries
22+
loaded elsewhere in the host process (a common failure mode is ROS 2's
23+
rcl_logging_spdlog ABI-clashing with our vendored spdlog and crashing inside
24+
spdlog::pattern_formatter).
25+
26+
This script lists exported defined symbols from the supplied shared library
27+
using the platform-appropriate tool and fails (exit code 1) if any of them
28+
match a forbidden pattern.
29+
30+
Usage:
31+
python3 check_no_private_symbols.py <path-to-shared-library>
32+
33+
Optional environment variables:
34+
LIVEKIT_SYMBOL_CHECK_VERBOSE=1 Print every leaked symbol (default: print
35+
up to 20 examples).
36+
LIVEKIT_SYMBOL_CHECK_EXTRA_FORBIDDEN=foo,bar Additional comma-separated
37+
patterns to forbid.
38+
"""
39+
40+
import os
41+
import re
42+
import shutil
43+
import subprocess
44+
import sys
45+
from pathlib import Path
46+
47+
# Substring patterns that must NOT appear in any exported symbol after
48+
# demangling. We use plain-substring semantics for readability; if you need a
49+
# regex, switch to re.search.
50+
DEFAULT_FORBIDDEN = [
51+
"spdlog::",
52+
"fmt::v",
53+
"google::protobuf",
54+
"absl::",
55+
]
56+
57+
MAX_REPORTED_LEAKS = 20
58+
59+
60+
def _which_or_die(name: str) -> str:
61+
path = shutil.which(name)
62+
if not path:
63+
sys.stderr.write(f"error: required tool '{name}' not found on PATH\n")
64+
sys.exit(2)
65+
return path
66+
67+
68+
def _list_exports_macos(lib: Path) -> list[str]:
69+
nm = _which_or_die("nm")
70+
cxxfilt = shutil.which("c++filt")
71+
# -gU: external (global) defined symbols.
72+
raw = subprocess.run(
73+
[nm, "-gU", str(lib)],
74+
check=True,
75+
capture_output=True,
76+
text=True,
77+
).stdout
78+
if cxxfilt:
79+
raw = subprocess.run(
80+
[cxxfilt],
81+
input=raw,
82+
check=True,
83+
capture_output=True,
84+
text=True,
85+
).stdout
86+
return raw.splitlines()
87+
88+
89+
def _list_exports_linux(lib: Path) -> list[str]:
90+
nm = _which_or_die("nm")
91+
cxxfilt = shutil.which("c++filt")
92+
# -D: dynamic symbols (i.e., what's actually visible to the dynamic linker)
93+
# --defined-only: drop UND entries
94+
raw = subprocess.run(
95+
[nm, "-D", "--defined-only", str(lib)],
96+
check=True,
97+
capture_output=True,
98+
text=True,
99+
).stdout
100+
if cxxfilt:
101+
raw = subprocess.run(
102+
[cxxfilt],
103+
input=raw,
104+
check=True,
105+
capture_output=True,
106+
text=True,
107+
).stdout
108+
return raw.splitlines()
109+
110+
111+
def _find_dumpbin_via_vswhere() -> str | None:
112+
"""Locate dumpbin.exe under the latest installed Visual Studio.
113+
114+
GitHub-hosted Windows runners (and standard local VS installs) don't add
115+
dumpbin to PATH unless the user opens a Developer Command Prompt. vswhere
116+
ships at a fixed location with every Visual Studio install since 2017 and
117+
is the supported way to discover the install tree from a vanilla shell.
118+
"""
119+
program_files_x86 = os.environ.get(
120+
"ProgramFiles(x86)", r"C:\Program Files (x86)"
121+
)
122+
vswhere = Path(program_files_x86) / "Microsoft Visual Studio" / "Installer" \
123+
/ "vswhere.exe"
124+
if not vswhere.exists():
125+
return None
126+
try:
127+
proc = subprocess.run(
128+
[
129+
str(vswhere),
130+
"-latest",
131+
"-products", "*",
132+
"-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
133+
"-property", "installationPath",
134+
],
135+
check=True,
136+
capture_output=True,
137+
text=True,
138+
)
139+
except subprocess.CalledProcessError:
140+
return None
141+
install_path = proc.stdout.strip()
142+
if not install_path:
143+
return None
144+
msvc_root = Path(install_path) / "VC" / "Tools" / "MSVC"
145+
if not msvc_root.is_dir():
146+
return None
147+
# Pick the highest-versioned toolchain present (lexicographic order matches
148+
# version order for dotted MSVC versions like "14.44.35207").
149+
for version_dir in sorted(msvc_root.iterdir(), reverse=True):
150+
candidate = version_dir / "bin" / "Hostx64" / "x64" / "dumpbin.exe"
151+
if candidate.exists():
152+
return str(candidate)
153+
return None
154+
155+
156+
def _list_exports_windows(lib: Path) -> list[str]:
157+
# dumpbin ships with MSVC; it understands import libs (.lib) and DLLs.
158+
dumpbin = shutil.which("dumpbin") or _find_dumpbin_via_vswhere()
159+
if not dumpbin:
160+
sys.stderr.write(
161+
"error: 'dumpbin' not on PATH and could not be located via "
162+
"vswhere; run from a Visual Studio Developer command prompt or "
163+
"ensure dumpbin.exe is available\n"
164+
)
165+
sys.exit(2)
166+
raw = subprocess.run(
167+
[dumpbin, "/exports", str(lib)],
168+
check=True,
169+
capture_output=True,
170+
text=True,
171+
).stdout
172+
# dumpbin output lines for export entries look like
173+
# " 1 0 00001000 ?foo@@YAHXZ = ?foo@@YAHXZ (int __cdecl foo(void))"
174+
# We keep all of stdout: the substring search will only fire on actual
175+
# symbol names, headers/footers are harmless.
176+
return raw.splitlines()
177+
178+
179+
def _list_exports(lib: Path) -> list[str]:
180+
if sys.platform == "darwin":
181+
return _list_exports_macos(lib)
182+
if sys.platform.startswith("linux"):
183+
return _list_exports_linux(lib)
184+
if os.name == "nt" or sys.platform == "win32":
185+
return _list_exports_windows(lib)
186+
sys.stderr.write(f"error: unsupported platform '{sys.platform}'\n")
187+
sys.exit(2)
188+
189+
190+
def main(argv: list[str]) -> int:
191+
if len(argv) != 2:
192+
sys.stderr.write(__doc__ or "")
193+
return 2
194+
195+
lib = Path(argv[1]).resolve()
196+
if not lib.exists():
197+
sys.stderr.write(f"error: library not found: {lib}\n")
198+
return 2
199+
200+
forbidden = list(DEFAULT_FORBIDDEN)
201+
extra = os.environ.get("LIVEKIT_SYMBOL_CHECK_EXTRA_FORBIDDEN", "")
202+
if extra:
203+
forbidden.extend(p for p in extra.split(",") if p)
204+
205+
verbose = bool(os.environ.get("LIVEKIT_SYMBOL_CHECK_VERBOSE"))
206+
207+
print(f"[symbol-check] library : {lib}")
208+
print(f"[symbol-check] platform: {sys.platform}")
209+
print(f"[symbol-check] forbidden patterns: {forbidden}")
210+
211+
lines = _list_exports(lib)
212+
print(f"[symbol-check] {len(lines)} lines of nm/dumpbin output")
213+
214+
# Group leaks by pattern for a tidy summary.
215+
leaks_by_pattern: dict[str, list[str]] = {p: [] for p in forbidden}
216+
for line in lines:
217+
for pat in forbidden:
218+
if pat in line:
219+
leaks_by_pattern[pat].append(line.rstrip())
220+
221+
total_leaks = sum(len(v) for v in leaks_by_pattern.values())
222+
if total_leaks == 0:
223+
print("[symbol-check] OK: no forbidden symbols exported")
224+
return 0
225+
226+
print(f"[symbol-check] FAIL: {total_leaks} forbidden symbol(s) exported")
227+
for pat, hits in leaks_by_pattern.items():
228+
if not hits:
229+
continue
230+
print(f" pattern {pat!r}: {len(hits)} hit(s)")
231+
shown = hits if verbose else hits[:MAX_REPORTED_LEAKS]
232+
for h in shown:
233+
print(f" {h}")
234+
if not verbose and len(hits) > MAX_REPORTED_LEAKS:
235+
print(f" ... and {len(hits) - MAX_REPORTED_LEAKS} more "
236+
"(set LIVEKIT_SYMBOL_CHECK_VERBOSE=1 to see all)")
237+
238+
print(
239+
"\nliblivekit must not re-export private dependency symbols.\n"
240+
"If you intentionally added a public symbol that triggered this, mark\n"
241+
"it with LIVEKIT_API in include/livekit/visibility.h and rebuild.\n"
242+
)
243+
return 1
244+
245+
246+
if __name__ == "__main__":
247+
sys.exit(main(sys.argv))

‎.github/workflows/builds.yml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
- cpp-example-collection/**
1010
- bridge/**
1111
- client-sdk-rust/**
12+
- cmake/**
13+
- scripts/**
1214
- CMakeLists.txt
1315
- build.sh
1416
- build.cmd
@@ -27,6 +29,8 @@ on:
2729
- cpp-example-collection/**
2830
- bridge/**
2931
- client-sdk-rust/**
32+
- cmake/**
33+
- scripts/**
3034
- CMakeLists.txt
3135
- build.sh
3236
- build.cmd
@@ -133,15 +137,14 @@ jobs:
133137
libssl-dev \
134138
libprotobuf-dev protobuf-compiler \
135139
libabsl-dev \
136-
libwayland-dev libdecor-0-dev \
137-
libspdlog-dev
140+
libwayland-dev libdecor-0-dev
138141
139142
- name: Install deps (macOS)
140143
if: runner.os == 'macOS'
141144
run: |
142145
set -eux
143146
brew update
144-
brew install cmake ninja protobuf abseil spdlog
147+
brew install cmake ninja protobuf abseil
145148
146149
# ---------- Rust toolchain ----------
147150
- name: Install Rust (stable)

‎.github/workflows/make-release.yml‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,49 @@ jobs:
200200
Write-Host "Bundle contents:"
201201
Get-ChildItem -Recurse -File $bundleDir | Select-Object -First 200 | ForEach-Object { $_.FullName }
202202
203+
# ---------- Verify exported ABI: no third-party symbol leaks ----------
204+
- name: Setup Python
205+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v6.0.0
206+
with:
207+
python-version: '3.x'
208+
209+
- name: Symbol leak check (Unix)
210+
if: runner.os != 'Windows'
211+
shell: bash
212+
run: |
213+
set -eux
214+
libdir="build-release/lib"
215+
if [[ "$RUNNER_OS" == "macOS" ]]; then
216+
lib="${libdir}/liblivekit.dylib"
217+
if [[ ! -f "${lib}" ]]; then
218+
lib="build-release/bin/liblivekit.dylib"
219+
fi
220+
else
221+
lib="${libdir}/liblivekit.so"
222+
if [[ ! -f "${lib}" ]]; then
223+
lib="build-release/bin/liblivekit.so"
224+
fi
225+
fi
226+
python3 .github/scripts/check_no_private_symbols.py "${lib}"
227+
228+
- name: Symbol leak check (Windows)
229+
if: runner.os == 'Windows'
230+
shell: pwsh
231+
run: |
232+
$candidates = @(
233+
"build-release/bin/livekit.dll",
234+
"build-release/lib/livekit.dll"
235+
)
236+
$lib = $null
237+
foreach ($p in $candidates) {
238+
if (Test-Path -LiteralPath $p) { $lib = $p; break }
239+
}
240+
if ($null -eq $lib) {
241+
Write-Error "livekit.dll not found in any of: $($candidates -join ', ')"
242+
exit 1
243+
}
244+
python .github/scripts/check_no_private_symbols.py "$lib"
245+
203246
# ---------- Upload artifact (raw directory, no pre-compression) ----------
204247
- name: Upload build artifact
205248
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1

‎.github/workflows/tests.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,14 @@ jobs:
115115
libprotobuf-dev protobuf-compiler \
116116
libabsl-dev \
117117
libwayland-dev libdecor-0-dev \
118-
libspdlog-dev \
119118
jq
120119
121120
- name: Install deps (macOS)
122121
if: runner.os == 'macOS'
123122
run: |
124123
set -eux
125124
brew update
126-
brew install cmake ninja protobuf abseil spdlog jq
125+
brew install cmake ninja protobuf abseil jq
127126
128127
# ---------- Rust toolchain ----------
129128
- name: Install Rust (stable)

0 commit comments

Comments
 (0)