Add PA and BTI to SwiftShader

Adds compilation flags to enable Pointer Authentication and Branch
Target Identification for SwiftShader when built in Chromium.

BUILD.gn of Marl library nows adds source-file by target cpu.

Necessary changes to assembly files are added via upstream project.

Bug: chromium:1145581
Change-Id: I5ad6c62a677b2da308908507d3f9c3f73cb517d2
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/56248
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Commit-Queue: Nicolas Capens <nicolascapens@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index ba6f21f..413c977 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -17,6 +17,7 @@
 config("swiftshader_config") {
   cflags = []
   defines = []
+  asmflags = []
 
   if (!is_debug) {
     defines += [ "ANGLE_DISABLE_TRACE" ]
@@ -51,6 +52,22 @@
       cflags += [ "-Os" ]
     }
   }
+
+  if (build_with_chromium) {
+    if (is_clang) {
+      if (current_cpu == "arm64") {
+        import("//build/config/arm.gni")
+
+        if (arm_control_flow_integrity == "standard") {
+          cflags += [ "-mbranch-protection=standard" ]
+          asmflags += [ "-mbranch-protection=standard" ]
+        } else {
+          assert(arm_control_flow_integrity == "none",
+                 "Invalid branch protection option!")
+        }
+      }
+    }
+  }
 }
 
 source_set("vertex_routine_fuzzer") {
diff --git a/third_party/marl/BUILD.gn b/third_party/marl/BUILD.gn
index fd23721..e1e29b1 100644
--- a/third_party/marl/BUILD.gn
+++ b/third_party/marl/BUILD.gn
@@ -43,9 +43,7 @@
     "include/marl/waitgroup.h",
   ]
 
-  public_configs = [
-    ":marl_config",
-  ]
+  public_configs = [ ":marl_config" ]
 }
 
 swiftshader_source_set("Marl") {
@@ -58,23 +56,46 @@
   ]
 
   if (!is_win) {
-    sources += [
-      "src/osfiber_aarch64.c",
-      "src/osfiber_arm.c",
-      "src/osfiber_asm_aarch64.S",
-      "src/osfiber_asm_arm.S",
-      "src/osfiber_asm_mips64.S",
-      "src/osfiber_asm_ppc64.S",
-      "src/osfiber_asm_x64.S",
-      "src/osfiber_asm_x86.S",
-      "src/osfiber_mips64.c",
-      "src/osfiber_ppc64.c",
-      "src/osfiber_x64.c",
-      "src/osfiber_x86.c",
-    ]
+    if (current_cpu == "arm64") {
+      sources += [
+        "src/osfiber_aarch64.c",
+        "src/osfiber_asm_aarch64.h",
+        "src/osfiber_asm_aarch64.S",
+      ]
+    } else if (current_cpu == "arm") {
+      sources += [
+        "src/osfiber_arm.c",
+        "src/osfiber_asm_arm.h",
+        "src/osfiber_asm_arm.S",
+      ]
+    } else if (current_cpu == "mips64") {
+      sources += [
+        "src/osfiber_mips64.c",
+        "src/osfiber_asm_mips64.h",
+        "src/osfiber_asm_mips64.S",
+      ]
+    } else if (current_cpu == "ppc64") {
+      sources += [
+        "src/osfiber_ppc64.c",
+        "src/osfiber_asm_ppc64.h",
+        "src/osfiber_asm_ppc64.S",
+      ]
+    } else if (current_cpu == "x64") {
+      sources += [
+        "src/osfiber_x64.c",
+        "src/osfiber_asm_x64.h",
+        "src/osfiber_asm_x64.S",
+      ]
+    } else if (current_cpu == "x86") {
+      sources += [
+        "src/osfiber_x86.c",
+        "src/osfiber_asm_x86.h",
+        "src/osfiber_asm_x86.S",
+      ]
+    } else {
+      assert(false, "Unhandled value for current-cpu=" + current_cpu)
+    }
   }
 
-  public_deps = [
-    ":Marl_headers",
-  ]
+  public_deps = [ ":Marl_headers" ]
 }