export: Restore exclusion of private shared library dependencies from checks
Refactoring in !7165 (merged) accidentally dropped the behavior change from commit 0ad2a1c1. Restore the behavior and add a test.
Fixes: #23838 (closed)
Backport: release