PIC `cc_library` dependencies for PIE binary emit does not satisfy link attributes
メンテナーはふだん 3 日以内に返信
@krasimirgg がすでに取り組んでいます。
2026年7月22日 から。
評価
この issue はまだ評価されていません。
説明
Description
Since #4062 (included in 0.71.0) rules_rust will pick PIC (position independent code) dependency variants when compiling a PIE (position independent executable) binary.
However PIC produced by rules_cc have a .pic infix (e.g. libseccomp.pic.a vs. libseccemp.a) that won't satisfy link attributes (e.g. #[link(name = "seccomp")). This is a problem when manually providing link_deps to third party crates (e.g. libseccomp-sys), as the link attribute must be removed for compilation to succeed under --compilation_mode=opt.
PIC dependencies should be resolvable by the linker without needing to remove the link attribute or adding the .pic infix.
Reproduction steps
- Download and extract repro tarball. repro.tar.gz
bazel build //:main(successful)bazel build -c opt //:main(fails, outputs something like below)
❯ bazel build -c opt //:main
INFO: Analyzed target //:main (95 packages loaded, 1194 targets configured).
ERROR: /___/rules-rust-pic-link-repro/BUILD.bazel:9:12: Compiling Rust bin main (1 file) failed: (Exit 1): process_wrapper failed: error executing Rustc command (from rust_binary rule target //:main) bazel-out/k8-opt-exec/bin/external/rules_rust+/util/process_wrapper/process_wrapper --subst 'pwd=${pwd}' --subst 'exec_root=${exec_root}' --subst 'output_base=${output_base}' -- ... (remaining 2 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error: linking with `/usr/bin/gcc` failed: exit status: 1
|
= note: "/usr/bin/gcc" "-m64" "/tmp/rustcHgpswx/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bdynamic" "-lfoo" "-Wl,-Bstatic" "-lfoo.pic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcHgpswx/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "bazel-out/k8-opt/bin" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "bazel-out/k8-opt/bin/main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-fuse-ld=lld" "-B/usr/bin" "-Wl,-no-as-needed" "-Wl,-z,relro,-z,now" "-pass-exit-codes" "-Wl,--gc-sections" "-Wl,--push-state,-as-needed" "-lstdc++" "-Wl,--pop-state" "-Wl,--push-state,-as-needed" "-lm" "-Wl,--pop-state" "-lfoo.pic"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: ld.lld: error: unable to find library -lfoo
collect2: error: ld returned 1 exit status
error: aborting due to 1 previous error
Target //:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.905s, Critical Path: 0.29s
INFO: 59 processes: 63 action cache hit, 57 internal, 2 linux-sandbox.
ERROR: Build did NOT complete successfully
Additional context
NA
Impact
Impact heavily depends on the code used, but if affected it causes compilation to fail as no suitable library is found to link against.
e.g.
ld.lld: error: unable to find library -lseccomp
A workaround for this issue is to patch rules_rust to symlink the PIC library without the .pic infix (building off existing logic designed to disambiguate libraries with the same filename).
Bazel and rules_rust version
Bazel: 9.1.1
rules_rust: 0.71.2 (with 9 unrelated patches)
- 主要言語
- Starlark
- スター
- 857
- フォーク
- 701
- 平均マージ
- 4日 7時間
- マージ済み PR(30日)
- 46
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bazelbuild/rules_rust のほかの issue
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfiles対応中かも @Wito-1 が 65 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
bazelbuild/rules_rust#4309 ·
メンテナーはふだん 3 日以内に返信
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain condition対応中かも @Mattbusel が 17 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
bazelbuild/rules_rust#4266 ·
メンテナーはふだん 3 日以内に返信
-
rust.toolchain(strip_level = ...) is silently ignored対応中かも @Mattbusel が 17 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
bazelbuild/rules_rust#4223 ·
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
bazelbuild/rules_rust#4152 · リアクション 1 件 ·
メンテナーはふだん 3 日以内に返信
-
awaiting-response
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bazelbuild/rules_rust#3599 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信