-Werror=global-constructors for heapprofd_client_api.

Change-Id: I0e2b7bdfac6201bf297fe68dfa625b6d360c5875
Bug: 141241849
diff --git a/Android.bp b/Android.bp
index 1a7af3d..a0f9563 100644
--- a/Android.bp
+++ b/Android.bp
@@ -270,6 +270,8 @@
   ],
   cflags: [
     "-DPERFETTO_ANDROID_ASYNC_SAFE_LOG",
+    "-Werror=global-constructors",
+    "-Wglobal-constructors",
   ],
   include_dirs: [
     "bionic/libc",
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index 676b7dd..f825363 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -165,6 +165,10 @@
         ('include_dirs', {'bionic/libc'}),
         ('static_libs', {'libasync_safe'}),
         ('header_libs', {'bionic_libc_platform_headers'}),
+        # heapprofd_client_api MUST NOT have global constructors. Because it
+        # is loaded in an __attribute__((constructor)) of libc, we cannot
+        # guarantee that the global constructors get run before it is used.
+        ('cflags', {'-Wglobal-constructors', '-Werror=global-constructors'}),
     ],
     'heapprofd_client': [
         ('include_dirs', {'bionic/libc'}),