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

[Bug]: Hermetic GCC toolchain and @io_bazel_rules_go produce warnings building debug-mode shared libraries #160

Open
rbosetti opened this issue Dec 6, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rbosetti
Copy link

rbosetti commented Dec 6, 2023

What happened?

What happened: linking a Cgo library into a Go binary produces a warning about incorrect use of DT_TEXTREL in a PIE target.
What I expected: no warnings, because consistent link strategies are used for intermediate and final results.

A Go package that uses cgo, compiled as a library in debug mode, will normally produce a .gopclntab that requires relocations. When using the standard Go rules with a system C toolchain on various flavors of Ubuntu, cgo=True libraries are built such that .gopclntab and other relocated read-only sections are prefixed with .data.relro. It appears that some interaction between the Aspect GCC toolchain and the Go rules is leading to a situation where intermediate .o files for Go builds are using internal linkage, while the final link step is using GNU ld as an external linker.

That conflict causes warnings and has in the past been a sign of binaries with executable data sections that need to be specially handled by the system loader. Notably, various musl-based systems are not able to correctly load such binaries.

One possible cause here is that the PIE-by-default nature of the GCC toolchain is not correctly detected by the Go rules.

See golang/go issue 10914, 17847, and 59866 for related discussions.

Version

Development (host) and target OS/architectures:
Host is Ubuntu 22.04.3 LTS, uname -srv Linux 6.2.0-1018-gcp #20~22.04.1-Ubuntu SMP Mon Oct 23 12:29:43 UTC 2023
Target is Linux x86-64, with similar kernel revisions

Output of bazel --version: bazel 6.4.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: @io_bazel_rules_go = v0.43.0, Go toolchain = 1.20.2, Aspect GCC toolchain = 0.4.2

Complete repo available at https://github.com/rbosetti/aspect-repro

Language(s) and/or frameworks involved: Go, C

How to reproduce

`bazel build //:demobin` from the workspace in https://github.com/rbosetti/aspect-repro

Any other information?

Output from the repro step.

INFO: Analyzed target //:demobin (55 packages loaded, 16855 targets configured).
INFO: Found 1 target...
INFO: From GoLink demobin_/demobin:
/home/rlb/.cache/bazel/_bazel_rlb/5d655e0d5670b9e1307c236b8abb2e79/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: /tmp/go-link-2297262172/go.o: warning: relocation in read-only section `.gopclntab'
/home/rlb/.cache/bazel/_bazel_rlb/5d655e0d5670b9e1307c236b8abb2e79/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: warning: creating DT_TEXTREL in a PIE
Target //:demobin up-to-date:
  bazel-bin/demobin_/demobin
INFO: Elapsed time: 191.332s, Critical Path: 166.08s
INFO: 13 processes: 7 internal, 6 linux-sandbox.
INFO: Build completed successfully, 13 total actions
@rbosetti rbosetti added the bug Something isn't working label Dec 6, 2023
@github-actions github-actions bot added the untriaged Requires traige label Dec 6, 2023
@f0rmiga
Copy link
Owner

f0rmiga commented Mar 1, 2024

Thank you for the complete report and repro. I'll look into this.

@f0rmiga f0rmiga removed the untriaged Requires traige label Mar 1, 2024
@f0rmiga f0rmiga self-assigned this Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants