bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.36k stars 635 forks source link

Setting `--compilation_mode=opt` results in a binary with debug info + symbol table not being stripped #3917

Closed Strum355 closed 4 weeks ago

Strum355 commented 2 months ago

What version of rules_go are you using?

0.46.0

What version of gazelle are you using?

0.35.0

What version of Bazel are you using?

7.1.0

Does this issue reproduce with the latest releases of all the above?

yes

What operating system and processor architecture are you using?

x86_64 linux (also tested on macOS)

Any other potentially useful information about your toolchain?

https://github.com/uber/hermetic_cc_toolchain on linux, presumably host toolchain on maOS

What did you do?

bazel build --compilation_mode={fastbuild,dbg,opt} //some/go_binary:target

What did you expect to see?

Setting --compilation_mode=opt results in a stripped binary without debug info. The current behaviour may be WIA, in which case this issue can probably be closed.

See Bazel slack thread for some discussion https://bazelbuild.slack.com/archives/CDBP88Z0D/p1712748379078069

What did you see instead?

batcheshelper.dbg:  ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, Go BuildID=redacted, with debug_info, not stripped
batcheshelper.fast: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, Go BuildID=redacted, stripped
batcheshelper.opt:  ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=redacted, with debug_info, not stripped
malt3 commented 1 month ago

The current behavior was actually last modified by me in #3527

I looked into Bazel's documented behavior for --strip. It says:

 --strip (always|never|sometimes)

This option determines whether Bazel will strip debugging information from all binaries and shared libraries, by invoking the linker with the -Wl,--strip-debug option.

--strip=always means always strip debugging information.
--strip=never means never strip debugging information.
The default value of --strip=sometimes means strip if the --compilation_mode is fastbuild.

https://bazel.build/docs/user-manual#strip

To the best of my understanding, this works as intended.

Strum355 commented 4 weeks ago

I think you're right, Im not sure why I thought otherwise anymore :woozy_face: