MacOS: Use exported_symbols_list to filter exported symbols for .gn build files

GN follow up to the corresponding CMake change:
https://swiftshader-review.googlesource.com/c/SwiftShader/+/32568

Bug b/134929443

Change-Id: Ic1eabafaef8e2eda92199434359456c1ba10e875
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34110
Tested-by: Alexis Hétu <sugoi@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/OpenGL/libEGL/BUILD.gn b/src/OpenGL/libEGL/BUILD.gn
index 993ca6a..a17a3a7 100644
--- a/src/OpenGL/libEGL/BUILD.gn
+++ b/src/OpenGL/libEGL/BUILD.gn
@@ -73,7 +73,11 @@
       "CoreFoundation.framework",
       "IOSurface.framework",
     ]
-    ldflags = [ "-Wl,-install_name,@rpath/libswiftshader_libEGL.dylib" ]
+    ldflags = [
+      "-Wl,-install_name,@rpath/libswiftshader_libEGL.dylib",
+      "-Wl,-exported_symbols_list," +
+          rebase_path("libEGL.exports", root_build_dir),
+    ]
   } else if (is_linux) {
     if (use_x11) {
       sources += [ "../../Main/libX11.cpp" ]
diff --git a/src/OpenGL/libGLESv2/BUILD.gn b/src/OpenGL/libGLESv2/BUILD.gn
index d7037ca..6fa7dff 100644
--- a/src/OpenGL/libGLESv2/BUILD.gn
+++ b/src/OpenGL/libGLESv2/BUILD.gn
@@ -125,7 +125,11 @@
   ]
 
   if (is_mac) {
-    ldflags = [ "-Wl,-install_name,@rpath/libswiftshader_libGLESv2.dylib" ]
+    ldflags = [
+      "-Wl,-install_name,@rpath/libswiftshader_libGLESv2.dylib",
+      "-Wl,-exported_symbols_list," +
+          rebase_path("libGLESv2.exports", root_build_dir),
+    ]
   } else if (is_linux) {
     inputs = [
       "libGLESv2.lds",
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn
index 6aeaec8..3fd343f 100644
--- a/src/Vulkan/BUILD.gn
+++ b/src/Vulkan/BUILD.gn
@@ -108,7 +108,13 @@
   output_name = "libvulkan"
   output_dir = "$root_out_dir/swiftshader"
 
-  if (is_linux) {
+  if (is_mac) {
+    ldflags = [
+      "-Wl,-install_name,@rpath/libvk_swiftshader.dylib",
+      "-Wl,-exported_symbols_list," +
+          rebase_path("libvk_swiftshader.exports", root_build_dir),
+    ]
+  } else if (is_linux) {
     inputs = [
       "libvk_swiftshader.lds",
     ]