libvulkan: refactor for _FORTIFY_SOURCE=3 support.

You can't use malloc_usable_size() when built with _FORTIFY_SOURCE=3, so pull out the allocator into a file that can be built _FORTIFY_SOURCE=2 while still getting the benefits for the rest of the code.

Bug: http://b/291762537
Change-Id: Ic3a71bd8eadeb2da167edc0ba28becba2f95f82e
diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp
index 879d2d0..7e7fdc4 100644
--- a/vulkan/libvulkan/Android.bp
+++ b/vulkan/libvulkan/Android.bp
@@ -41,14 +41,9 @@
     aconfig_declarations: "libvulkan_flags",
 }
 
-cc_library_shared {
-    name: "libvulkan",
-    llndk: {
-        symbol_file: "libvulkan.map.txt",
-        export_llndk_headers: [
-            "vulkan_headers",
-        ],
-    },
+cc_defaults {
+    name: "libvulkan_defaults",
+
     sanitize: {
         misc_undefined: ["integer"],
     },
@@ -81,6 +76,34 @@
         "-Wno-global-constructors",
         "-Wno-zero-length-array",
     ],
+}
+
+cc_library {
+    name: "libvulkanallocator",
+    defaults: ["libvulkan_defaults"],
+    cflags: [
+        // This code uses malloc_usable_size(),
+        // and thus can't be built with _FORTIFY_SOURCE=3.
+        "-U_FORTIFY_SOURCE",
+        "-D_FORTIFY_SOURCE=2",
+    ],
+    srcs: [
+        "allocator.cpp",
+    ],
+    header_libs: [
+        "vulkan_headers",
+    ],
+}
+
+cc_library_shared {
+    name: "libvulkan",
+    defaults: ["libvulkan_defaults"],
+    llndk: {
+        symbol_file: "libvulkan.map.txt",
+        export_llndk_headers: [
+            "vulkan_headers",
+        ],
+    },
 
     srcs: [
         "api.cpp",
@@ -124,6 +147,7 @@
     ],
     static_libs: [
         "libgrallocusage",
+        "libvulkanallocator",
         "libvulkanflags",
     ],
 }