ilmanzo / ilmanzo/BinaryCoverage

uninstall reverts a shared library's merged debug info even if another shimmed binary still needs it

Open
#139 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
9
Forks
6
Avg merge
1h 32m
Merged PRs (30d)
11

Description

When \`install --libraries\` (WithLibraries scope) shims a binary, \`mergeLibraryDebugInfo\`
(cmd/elfutil.go:116) merges external debug info into each dependency
**in place, at its real system path** — every other funkoverage target on the
system that links the same library picks up the merged copy too. The
pre-merge bytes are backed up under \`SAFE_BIN_DIR/libs/\`, tracked per
*installing* binary via a sidecar (\`funkutil.LibBackupPath\`).

\`uninstall\` (cmd/shim.go:179) calls \`restoreLibraryBackups\` (cmd/elfutil.go:161),
which restores every library in *that binary's own* backup sidecar back to
its pre-merge state — with no check for whether another still-installed
binary shares the same library and depends on the merge being there.

This is a real runtime break, not just cosmetic: \`Tracer.Start\`
(cmd/shim_binary/tracer.go:177) calls \`link.OpenExecutable(img)\` +
\`UprobeMulti\` fresh on **every invocation** of a shimmed binary, resolving
symbol names against whatever is currently on disk at \`img\`. So:

1. Install A and B, both with \`--libraries\`, both linking libfoo.so.
2. libfoo.so gets merged once (first install wins); both A and B's
func-lists include locally-scoped symbols only resolvable via that merge.
3. Uninstall A → libfoo.so is restored to its original, unmerged state.
4. B still runs fine at that instant, but its *next* invocation fails to
attach uprobes for those symbols — B's coverage silently degrades
without B itself ever being touched.

Already flagged as a known shortcut in the code:

// ponytail: no cross-target reference counting — if two installed targets
// share a library, uninstalling one restores it for both. Add a refcount
// sidecar under SAFE_BIN_DIR/libs/ if that becomes a real problem.
(cmd/elfutil.go:109-111)

Fix direction already sketched there: a refcount (or "which installed
targets reference this merged library" set) sidecar under
\`SAFE_BIN_DIR/libs/\`, consulted by \`restoreLibraryBackups\` so a shared
library is only reverted once no remaining installed target still needs it.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with mergeLibraryDebugInfo and restoreLibraryBackups in cmd/elfutil.go, then follow uninstall in cmd/shim.go and library resolution in cmd/shim_binary/tracer.go. Inspect the existing SAFE_BIN_DIR/libs/ backup sidecars and the ponytail comment for the intended reference tracking. Done means uninstalling one target does not restore a shared library while another installed target still needs its merged debug info, and the final target restores the original bytes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.