Repository: bazelbuild/bazel
Issue: Cross-compiling for Android (arm) is missing debug symbols (-g)
Labels: team-Android
untriaged

### Description of the problem / feature request:

According to the [Compilation Mode Docs](https://docs.bazel.build/versions/master/user-manual.html#flag--compilation_mode), building with `--compilation_mode=dbg` should include `--copt=-g` to request debug symbols.

When building for Android (arm), this flag is not passed to the compiler, and debug symbols are missing. When building for Android (x86), host, or iOS, this flag is passed correctly.

It's easy enough to add this to our `bazelrc`, but this behavior is inconsistent across the platforms and contrary to the docs so I thought I'd share. 

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Build an Android app with native library dependencies for arm architecture, observe the compiler invocations for the native library.

`./bazel-debug build //host/Applications/HeliosNativeAndroid/app:Helios  --fat_apk_cpu=arm64-v8a  -s`

### What operating system are you running Bazel on?

macOS 10.13.6

### What's the output of `bazel info release`?

`release 0.17.1`


Issue comments:
Just for completeness, which NDK revision are you on?
@jin r17b

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r10e/ArmCrosstools.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r10e/ArmCrosstools.java
index b2a7c4a826f156..440b2c9fcd4e8e 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r10e/ArmCrosstools.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r10e/ArmCrosstools.java
@@ -124,6 +124,7 @@ private CToolchain.Builder createAarch64Toolchain() {
         .addCompilationModeFlags(CompilationModeFlags.newBuilder()
             .setMode(CompilationMode.DBG)
             .addCompilerFlag("-O0")
+            .addCompilerFlag("-g")
             .addCompilerFlag("-UNDEBUG")
             .addCompilerFlag("-fno-omit-frame-pointer")
             .addCompilerFlag("-fno-strict-aliasing"));
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r11/ArmCrosstools.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r11/ArmCrosstools.java
index 75e452909b7229..17c03cab1a74fc 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r11/ArmCrosstools.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r11/ArmCrosstools.java
@@ -108,6 +108,7 @@ private CToolchain.Builder createAarch64Toolchain() {
         .addCompilationModeFlags(CompilationModeFlags.newBuilder()
             .setMode(CompilationMode.DBG)
             .addCompilerFlag("-O0")
+            .addCompilerFlag("-g")
             .addCompilerFlag("-UNDEBUG")
             .addCompilerFlag("-fno-omit-frame-pointer")
             .addCompilerFlag("-fno-strict-aliasing"));
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r12/ArmCrosstools.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r12/ArmCrosstools.java
index e4c0480076c315..54ccc4ac34f560 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r12/ArmCrosstools.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r12/ArmCrosstools.java
@@ -88,6 +88,7 @@ private CToolchain.Builder createAarch64Toolchain() {
                 CompilationModeFlags.newBuilder()
                     .setMode(CompilationMode.DBG)
                     .addCompilerFlag("-O0")
+                    .addCompilerFlag("-g")
                     .addCompilerFlag("-UNDEBUG"));
 
     stlImpl.addStlImpl(toolchain, "4.9");
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r13/ArmCrosstools.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r13/ArmCrosstools.java
index 6578cc4f3e0cb7..32477426692807 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r13/ArmCrosstools.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r13/ArmCrosstools.java
@@ -94,6 +94,7 @@ private CToolchain.Builder createAarch64ClangToolchain() {
                 CompilationModeFlags.newBuilder()
                     .setMode(CompilationMode.DBG)
                     .addCompilerFlag("-O0")
+                    .addCompilerFlag("-g")
                     .addCompilerFlag("-UNDEBUG"));
 
     stlImpl.addStlImpl(toolchain, "4.9");
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r15/ArmCrosstools.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r15/ArmCrosstools.java
index cf69457ae0159c..867e0386afc5ca 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r15/ArmCrosstools.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r15/ArmCrosstools.java
@@ -99,6 +99,7 @@ private CToolchain.Builder createAarch64ClangToolchain() {
                 CompilationModeFlags.newBuilder()
                     .setMode(CompilationMode.DBG)
                     .addCompilerFlag("-O0")
+                    .addCompilerFlag("-g")
                     .addCompilerFlag("-UNDEBUG"));
 
     stlImpl.addStlImpl(toolchain, "4.9");
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r17/ArmCrosstools.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r17/ArmCrosstools.java
index eb6a0fec7fa226..cf05cf590044d9 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r17/ArmCrosstools.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r17/ArmCrosstools.java
@@ -103,6 +103,7 @@ private CToolchain.Builder createAarch64ClangToolchain() {
             CompilationModeFlags.newBuilder()
                 .setMode(CompilationMode.DBG)
                 .addCompilerFlag("-O0")
+                .addCompilerFlag("-g")
                 .addCompilerFlag("-UNDEBUG"));
   }
 


Test patch: