Skip to main content

ELF symbol isolation for bundled system dependencies

Project description

isolate-elf — ELF Symbol Isolation for Bundled System Dependencies

Tool for renaming dynamic symbols in shared libraries to prevent interposition when bundled copies coexist with system copies in the same process.

What it does

Given libzstd.so.1, isolate-elf produces four artifacts:

  1. Prefixed .so — all exported symbols renamed (ZSTD_decompressrocm_ZSTD_decompress) via direct ELF binary rewriting of .dynsym/.dynstr + hash table rebuild
  2. Trampoline .a — asm stubs exporting original names, tail-jumping to prefixed names via PLT
  3. Linker scriptINPUT(stubs.a AS_NEEDED(real.so.1)) installed as -lzstd
  4. Redirect header#define macros for compile-time bypass of trampolines

Autoconf AC_CHECK_LIB(zstd, ZSTD_decompress) works unmodified — the linker script provides the original name via the trampoline, which pulls in the real .so.

Usage

# Isolate a library
isolate-elf isolate libzstd.so.1 --prefix rocm_ --name zstd -o output/

# Dry-run: see what would be renamed
isolate-elf inspect libzstd.so.1

# Strict mode: treat warnings as errors
isolate-elf isolate libzstd.so.1 --prefix rocm_ --name zstd -o output/ --werror

# Allow specific warning categories
isolate-elf isolate libzstd.so.1 --prefix rocm_ --name zstd -o output/ --werror --allow-object-symbol

Symbol classification

What gets renamed

Only defined, exported symbols (GLOBAL or WEAK bind, DEFAULT or PROTECTED visibility, not UND section) that don't match the CRT/glibc exclusion list.

What does NOT get renamed

Undefined imports — symbols the library expects the linker to resolve from other DSOs. These include:

  • Standard libc imports (malloc, printf, dlopen, etc.)
  • Weak undefined hooks — symbols like ZSTD_trace_compress_begin that libraries declare as optional callbacks. These are intentionally left as external binding points:
    • If nobody provides them, they resolve to NULL (weak semantics)
    • If a consumer provides them, they bind in as designed
    • Renaming them would break the hook mechanism entirely
    • The -Bsymbolic flag (applied by TheRock) ensures the library's own defined symbols still resolve internally — these weak imports are the only deliberate opening

CRT/glibc symbols — even if a library re-exports malloc (common for allocator wrappers), we don't rename it. The CRT exclusion list covers ~150 common libc/pthread/math symbols plus glob patterns for __cxa_*, __gcc_*, etc.

Warning categories

Category Trigger Behavior
object-symbol OBJECT (global data) in exports Renamed in .so, excluded from trampolines (can't trampoline data)
tls-symbol TLS symbol in exports Renamed in .so, excluded from trampolines
ifunc-symbol GNU_IFUNC in exports Trampolined via PLT (works but less tested)
versioned-symbol Non-AMDROCM version tag Renamed, version tag preserved
weak-override WEAK symbol shadowing glibc name Excluded from renaming

Use --werror to make all warnings fatal, --allow-<category> to selectively permit specific categories.

ELF rewriting internals

objcopy --redefine-syms does not modify .dynsym (only .symtab), so isolate-elf includes its own ELF binary rewriter (elf_rewrite.py) that:

  1. Builds a new .dynstr with renamed strings appended
  2. Updates .dynsym st_name offsets
  3. Rewrites DT_SONAME to match the output filename
  4. Adds a new PT_LOAD segment for the grown .dynstr
  5. Relocates the PHDR table if needed (borrowed from kpack patterns)
  6. Rebuilds .gnu.hash and .hash tables with new name hashes
  7. Updates DT_STRTAB/DT_STRSZ in .dynamic

Testing

# Unit tests (synthetic test libraries)
pytest tests/

# Integration tests (real sysdep libraries from TheRock S3 mirror)
pytest integration/

# All tests
pytest tests/ integration/

# Dump before/after artifacts for manual inspection
pytest integration/ --dump-artifacts=/tmp/isolate-elf-dump

Integration tests download real sysdep sources, build them, isolate, then verify: symbol correctness (readelf), autoconf link simulation, negative link test, and runtime isolation via LD_DEBUG=bindings scraping.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

isolate_elf-0.1.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

isolate_elf-0.1.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file isolate_elf-0.1.0.tar.gz.

File metadata

  • Download URL: isolate_elf-0.1.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for isolate_elf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2fc43d0f650c5598bca47b1f28f852866faeaf1a409e171e2aaaad2d4b63b7df
MD5 ecf49a2abe60323b41752be7fcf8b03c
BLAKE2b-256 ff1643ed2da3b16532fe3c8ceaf2e7ff45799c7bd99091edca7400f8e80aaa25

See more details on using hashes here.

Provenance

The following attestation bundles were made for isolate_elf-0.1.0.tar.gz:

Publisher: release.yml on stellaraccident/isolate-elf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file isolate_elf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: isolate_elf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for isolate_elf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d9ee291754ba4e1af37f2c63cbc0c63f2a1d52e9fa7255886123f111cd3ab7a
MD5 8ce7ae70019dab25ec4355f49fd3787a
BLAKE2b-256 2e0b4612b239d34cfc840a236b4828def6b06bf4a642fc2d78b016cac8182a20

See more details on using hashes here.

Provenance

The following attestation bundles were made for isolate_elf-0.1.0-py3-none-any.whl:

Publisher: release.yml on stellaraccident/isolate-elf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page