Skip to content

Add vendor binary ABI audit tool and hi3516cv100 uclibc compat shim - #1993

Merged
widgetii merged 1 commit into
masterfrom
vendor-abi-audit-and-shim
Apr 12, 2026
Merged

Add vendor binary ABI audit tool and hi3516cv100 uclibc compat shim#1993
widgetii merged 1 commit into
masterfrom
vendor-abi-audit-and-shim

Conversation

@widgetii

Copy link
Copy Markdown
Member

Summary

  • Add general/scripts/audit-vendor-abi.py — a tool that definitively detects ABI incompatibilities between vendor prebuilt .so files (uclibc/glibc) and the musl libc used by OpenIPC. Checks actual symbol availability against the platform's musl libc.so and compiles struct size probes with the cross-compiler.
  • Replace the libhisicompat hack (custom sTaT symbol) with a proper libc-compat/uclibc-compat.so shim for hi3516cv100 that handles stat (struct translator via raw fstatat64 syscall), mmap (SYS_mmap2 bypassing off_t mismatch), and __aeabi_d2iz.
  • Restore original vendor libmpi.so that imports standard stat() instead of the custom sTaT workaround.

Audit findings across 15 packages (492 binaries)

  • 272 missing symbols — vendor imports that musl doesn't export
  • 20 struct layout mismatches — same function, different struct sizes
  • 15 binaries across 8 packages import stat/fstat/stat64 with uclibc's 88-byte struct vs musl's 152-byte struct

Test plan

  • Run python3 general/scripts/audit-vendor-abi.py --package hisilicon-osdrv-hi3516cv100 — should detect struct stat, off_t, and __aeabi_d2iz issues
  • Build: make BOARD=hi3516cv100_lite br-hisilicon-osdrv-hi3516cv100 — shim compiles
  • Verify readelf -W --dyn-syms on restored libmpi.so shows stat (not sTaT)
  • Boot test on hi3516cv100 hardware

Ref: #1992

🤖 Generated with Claude Code

@widgetii
widgetii force-pushed the vendor-abi-audit-and-shim branch 4 times, most recently from 64e5732 to fa6d379 Compare April 12, 2026 08:18
…ompat

- Add general/scripts/audit-vendor-abi.py: checks vendor imports against
  actual musl libc.so exports and compiles struct size probes with the
  platform cross-compiler.  Auto-downloads per-platform toolchains.

- hi3516cv100: replace libhisicompat (sTaT hack) with uclibc-compat
  dependency.  Restore original vendor libmpi.so that imports standard
  stat() instead of the custom sTaT workaround.  Delete libhisicompat/.

- Register uclibc-compat in general/package/Config.in

Ref: #1992

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii
widgetii force-pushed the vendor-abi-audit-and-shim branch from fa6d379 to d8bc9e8 Compare April 12, 2026 16:44
@widgetii
widgetii merged commit b581a5a into master Apr 12, 2026
172 of 176 checks passed
@widgetii
widgetii deleted the vendor-abi-audit-and-shim branch April 14, 2026 05:13
widgetii added a commit that referenced this pull request May 18, 2026
Vendor glibc binaries from the V2 era (e.g. hi3520dv200's libmpi.so)
were built without _FILE_OFFSET_BITS=64 so their mmap() takes a 32-bit
off_t. musl's mmap() exports 64-bit off_t — when libmpi dynamic-links
against musl on a modern rootfs, the high 32 bits of the offset arg
come from uninitialised stack and the kernel sees a garbage pgoff,
rejecting with EINVAL.

Symptom on hi3520dv200: every HI_MPI_VENC_CreateChn returns 0xa007800c
(EN_ERR_VENC_NOMEM) because libmpi can't mmap the model_buf via
/dev/venc. Confirmed via LD_PRELOAD trace shim that wraps mmap():
the syscall reaches the kernel with off=0x402b65d8 — a userspace VA
(varies between runs with ASLR), clearly stack garbage.

Fix: add glibc-compat-static.c with a 32-bit off_t mmap()/mmap64()
wrapper that goes straight to SYS_mmap2 bypassing musl's libc wrapper.
Same pattern as #2000 (uclibc-compat-static for hi3516cv100). The
function must be statically linked into the consumer executable (not
in a .so) so the dynamic linker resolves vendor .so imports of mmap
to the executable's symbol table BEFORE musl — putting it in a .so
would override musl process-wide and break musl's own internal mmap
callers (malloc, dlopen, etc.).

- glibc-compat/src/glibc-compat-static.c: new file, mmap()/mmap64()
  wrappers calling SYS_mmap2 with pgoff
- glibc-compat/src/Makefile: build both libglibc-compat.so and
  libglibc-compat-static.a
- glibc-compat/glibc-compat.mk: INSTALL_STAGING=YES, install .a to
  STAGING_DIR so dependent packages can link -lglibc-compat-static
- Makefile (BUNDLE_SDK): produce libglibc-compat.so and
  libglibc-compat-static.a in the published toolchain SDK tarball,
  mirroring the existing uclibc-compat handling

Verified on lab DVR (openipc-hi3520dv200.dlab.torturelabs.com):
linking dvr_home with the mmap shim makes HI_MPI_VENC_CreateChn
succeed on all 4 channels.

Refs: #1992 (toolchain ABI audit), #1993 (cv100 stat shim),
      #2000 (cv100 static-link split)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant