Skip to content

Commit 04bf65c

Browse files
fboss-sim: resolve packaged libs via RUNPATH, not LD_LIBRARY_PATH union
resolve_dependencies() set LD_LIBRARY_PATH to a `find installed/` union of every lib dir under the getdeps installed/ tree before running ldd. LD_LIBRARY_PATH outranks the binary's RUNPATH and ldd takes the first dir on the path with a matching soname, so a stale dependency generation left in installed/ by a previous build could shadow the correct one and produce a package with ABI-mismatched libs (undefined symbol at load). Each binary's RUNPATH already points at the exact install dir it was linked against, so resolve via RUNPATH instead: strip any inherited LD_LIBRARY_PATH and let ldd use RUNPATH + default system paths (system libs resolve from /usr/lib64). Remove the now-unused get_lib_search_paths() helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2ed50fe commit 04bf65c

1 file changed

Lines changed: 7 additions & 32 deletions

File tree

fboss-sim/scripts/fboss-sim-docker-package.py

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,7 @@ def verify_binaries(build_dir: Path) -> None:
9494
print(f" ✓ All {len(REQUIRED_BINARIES)} required binaries present")
9595

9696

97-
def get_lib_search_paths(installed_dir: Path) -> list[str]:
98-
"""Find all lib/ and lib64/ directories under the getdeps installed dir.
99-
100-
Mirrors package-fboss.py's _update_ld_library_path logic.
101-
"""
102-
paths = []
103-
if not installed_dir.exists():
104-
return paths
105-
result = subprocess.run(
106-
["find", str(installed_dir), "-type", "d", "-regex", r".*/\(lib\|lib64\)"],
107-
capture_output=True,
108-
text=True,
109-
check=False,
110-
)
111-
if result.returncode == 0:
112-
paths = [p for p in result.stdout.strip().splitlines() if p]
113-
return paths
114-
115-
116-
def resolve_dependencies(binary_path: Path, lib_search_paths: list[str]) -> set[str]:
97+
def resolve_dependencies(binary_path: Path) -> set[str]:
11798
"""Use ldd to find shared library dependencies for a binary."""
11899
dependencies = set()
119100

@@ -125,13 +106,10 @@ def resolve_dependencies(binary_path: Path, lib_search_paths: list[str]) -> set[
125106
except subprocess.CalledProcessError:
126107
return dependencies
127108

128-
# Set up LD_LIBRARY_PATH so ldd can find libs from the build
109+
# Resolve via the binary's own RUNPATH; strip any inherited LD_LIBRARY_PATH
110+
# so a stale dep generation under installed/ can't shadow the correct one.
129111
env = os.environ.copy()
130-
extra_paths = ":".join(lib_search_paths)
131-
if env.get("LD_LIBRARY_PATH"):
132-
env["LD_LIBRARY_PATH"] = f"{extra_paths}:{env['LD_LIBRARY_PATH']}"
133-
else:
134-
env["LD_LIBRARY_PATH"] = extra_paths
112+
env.pop("LD_LIBRARY_PATH", None)
135113

136114
try:
137115
output = subprocess.check_output(
@@ -203,20 +181,17 @@ def copy_artifacts(
203181
else:
204182
print(" ⚠ setup_fboss_env not found in run_scripts/")
205183

206-
# 3. Resolve and copy shared library dependencies
207-
# Mirrors package-fboss.py exactly: set LD_LIBRARY_PATH to all lib/lib64 dirs
208-
# under the getdeps installed/ tree, then run ldd per binary.
184+
# 3. Resolve and copy shared library dependencies. ldd resolves each binary
185+
# via its own RUNPATH plus default system paths.
209186
# NOTE: this step must run inside the build container (CentOS) so that ldd
210187
# resolves system libs (libre2.so.9, libnl, libsodium, etc.) correctly.
211188
# The host invocation handles this via docker exec --collect-only.
212189
print("\n → Resolving shared library dependencies...")
213-
lib_search_paths = get_lib_search_paths(installed_dir)
214-
print(f" {len(lib_search_paths)} library search paths")
215190

216191
all_deps: set[str] = set()
217192
for binary in REQUIRED_BINARIES:
218193
binary_path = build_dir / binary
219-
all_deps.update(resolve_dependencies(binary_path, lib_search_paths))
194+
all_deps.update(resolve_dependencies(binary_path))
220195

221196
for lib_path in sorted(all_deps):
222197
lib_name = os.path.basename(lib_path)

0 commit comments

Comments
 (0)