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

Bazel adds "-g" in opt compilation mode when using NDK #89

Open
xiaobao520123 opened this issue Nov 5, 2023 · 7 comments
Open

Bazel adds "-g" in opt compilation mode when using NDK #89

xiaobao520123 opened this issue Nov 5, 2023 · 7 comments

Comments

@xiaobao520123
Copy link

xiaobao520123 commented Nov 5, 2023

Description of the bug:

Seen at src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r19/ArmCrosstools.java:91

When building my library using NDK with opt mode, bazel always adds the flag "-g" into the command line arguments.
This causes some problems for me because I don't want any debugging information to appear inside my library.

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@keith
Copy link
Member

keith commented Nov 6, 2023

For releases where you don't want debug info you should pass --compilation_mode=opt to bazel

@Pavank1992
Copy link

Hi @xiaobao520123, could you please try above and issue still persist, please help us how to reproduce this with all information i.e. bazel version, OS versions etc.

@xiaobao520123
Copy link
Author

Hi @xiaobao520123, could you please try above and issue still persist, please help us how to reproduce this with all information i.e. bazel version, OS versions etc.

well I try to use -c opt -compilation_mode=opt at the same time but it seems like it still adds "-g"

external/androidndk/ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang '-D__ANDROID_API__=21' -isystemexternal/androidndk/ndk/sysroot/usr/include/arm-linux-androideabi -target armv7-none-linux-androideabi '-march=armv7-a' '-mfloat-abi=softfp' '-mfpu=vfpv3-d16' -gcc-toolchain external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 -fpic -no-canonical-prefixes -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -funwind-tables -fstack-protector-strong -fno-addrsig '-Werror=return-type' '-Werror=int-to-pointer-cast' '-Werror=pointer-to-int-cast' '-Werror=implicit-function-declaration' -mthumb -Os -g -DNDEBUG -MD -MF ......

Bazelisk version: development
Build label: 6.4.0
Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Oct 19 17:08:20 2023 (1697735300)
Build timestamp: 1697735300
Build timestamp as int: 1697735300

My bazel version is bazel 6.4.0 and the NDK I use is android-ndk-r21e
Working on macOS 14.1

@keith
Copy link
Member

keith commented Nov 6, 2023

Ah right, because it wants to give you debug info in case you need it for crash reports. You can either strip the final binary (maybe --strip=always works?) or you can pass --copt=-gnone to negate the -g

@xiaobao520123
Copy link
Author

Ah right, because it wants to give you debug info in case you need it for crash reports. You can either strip the final binary (maybe --strip=always works?) or you can pass --copt=-gnone to negate the -g

yeah I've used the latter way you suggest, and it works. But I think when building in opt mode, debug info should not be included by default.

@keith
Copy link
Member

keith commented Nov 7, 2023

I think the crash reporting case is why it is, probably better to knowingly have to strip than to forget to enable -g when you need it and not be able to symbolicate production crashes

@ahumesky
Copy link
Collaborator

Native android_ndk_repository has been removed from bazel 8, but it looks like this is still set in the Starlark version:

so I'll move this issue there

@ahumesky ahumesky transferred this issue from bazelbuild/bazel Dec 13, 2024
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

6 participants