Protect exported symbols from overrides.

While all symbols except for the ones in the version script are hidden,
the exported ones can still be overridden by other libraries which
export the same symbols. Using -fvisibility=protected or the equivalent
attribute fixes this.

Protected visibility used to not work because of
https://bugs.llvm.org//show_bug.cgi?id=30960, but that doesn't appear
to be an issue any more.

Bug chromium:852537
Bug swiftshader:64

Change-Id: Id0b1197b90baa5f5c68bf2aa107d12f8a9856796
Reviewed-on: https://swiftshader-review.googlesource.com/19728
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn
index 6c2d803..bbbd2eb 100644
--- a/src/OpenGL/libEGL/BUILD.gn
+++ b/src/OpenGL/libEGL/BUILD.gn
@@ -33,7 +33,12 @@
       cflags += [ "-Wno-unused-but-set-variable" ]
     }
 
-    defines += [ "EGLAPI=__attribute__((visibility(\"default\"))) __attribute__((no_sanitize(\"function\")))" ]
+    if (is_mac) {
+      cflags += [ "-fvisibility=protected" ]
+      defines += [ "EGLAPI=__attribute__((no_sanitize(\"function\")))" ]
+    } else {
+      defines += [ "EGLAPI=__attribute__((visibility(\"protected\"))) __attribute__((no_sanitize(\"function\")))" ]
+    }
   }
 }
 
diff --git a/src/OpenGL/libGLESv2/BUILD.gn b/src/OpenGL/libGLESv2/BUILD.gn
index 3721fe2..8fb1bad 100644
--- a/src/OpenGL/libGLESv2/BUILD.gn
+++ b/src/OpenGL/libGLESv2/BUILD.gn
@@ -48,9 +48,15 @@
     defines += [
       "__STDC_CONSTANT_MACROS",
       "__STDC_LIMIT_MACROS",
-      "GL_APICALL=__attribute__((visibility(\"default\"))) __attribute__((no_sanitize(\"function\")))",
       "GLAPI=GL_APICALL",
     ]
+
+    if (is_mac) {
+      cflags += [ "-fvisibility=protected" ]
+      defines += [ "GL_APICALL=__attribute__((no_sanitize(\"function\")))" ]
+    } else {
+      defines += [ "GL_APICALL=__attribute__((visibility(\"protected\"))) __attribute__((no_sanitize(\"function\")))" ]
+    }
   }
 }