Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting statically linked native libraries from build scripts #11

Open
tofay opened this issue Jul 10, 2022 · 2 comments
Open

Detecting statically linked native libraries from build scripts #11

tofay opened this issue Jul 10, 2022 · 2 comments

Comments

@tofay
Copy link
Contributor

tofay commented Jul 10, 2022

Rust binaries can statically link to native libraries generated by build scripts. These libraries should be included in the SBOM.

cargo build JSON messages can show what libraries are linked (via the linked_libs field) , and the linker search paths configured by the build script. cargo-spdx could use this to look for the linked libraries.

Examples (from cargo build --message-format json | grep build-script of cargo-spdx itself):

{"reason":"build-script-executed","package_id":"openssl-sys 0.9.74 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":["static=ssl","static=crypto"],"linked_paths":["native=/home/tom/.target/debug/build/openssl-sys-15856e134bacc665/out/openssl-build/install/lib"],"cfgs":["const_fn","osslconf=\"OPENSSL_NO_COMP\"","osslconf=\"OPENSSL_NO_SSL3_METHOD\"","osslconf=\"OPENSSL_NO_SEED\"","ossl101","ossl102","ossl102f","ossl102h","ossl110","ossl110f","ossl110g","ossl110h","ossl111","ossl111b","ossl111c"],"env":[],"out_dir":"/home/tom/.target/debug/build/openssl-sys-15856e134bacc665/out"}
{"reason":"build-script-executed","package_id":"libssh2-sys 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":["static=ssh2"],"linked_paths":["native=/home/tom/.target/debug/build/libssh2-sys-eb5dddeb5944716b/out/build"],"cfgs":[],"env":[],"out_dir":"/home/tom/.target/debug/build/libssh2-sys-eb5dddeb5944716b/out"}
{"reason":"build-script-executed","package_id":"libgit2-sys 0.13.4+1.4.2 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":["static=git2"],"linked_paths":["native=/home/tom/.target/debug/build/libgit2-sys-ebe9f6f73e42c271/out/build"],"cfgs":["libgit2_vendored"],"env":[],"out_dir":"/home/tom/.target/debug/build/libgit2-sys-ebe9f6f73e42c271/out"}

The out_dir typically contains the sources used to build the linked library - suspect we should include SBOM entries for all files in the out_dir.

@alilleybrinker
Copy link
Owner

Yeah I agree with this, including the specifics of the technical approach for implementing it.

@prabhu
Copy link

prabhu commented Apr 21, 2024

@tofay could you share any sample project? Would love to test this PR in blint.

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

No branches or pull requests

3 participants