Also fix libGLESv2.

BUG=chromium:686980

Change-Id: I5f22f57288246c262a0fdb0ca1b0b321e4a58c1b
Reviewed-on: https://swiftshader-review.googlesource.com/9310
Tested-by: Ivan Krasin <krasin@chromium.org>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/BUILD.gn b/src/OpenGL/libGLESv2/BUILD.gn
index 1460180..46a9bfe 100644
--- a/src/OpenGL/libGLESv2/BUILD.gn
+++ b/src/OpenGL/libGLESv2/BUILD.gn
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build/toolchain/toolchain.gni")
+
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_libGLESv2_private_config") {
   defines = [
@@ -102,6 +104,18 @@
         [ "-Wl,--version-script=" + rebase_path("exports.map", root_build_dir) ]
   }
 
+  if (use_thin_lto) {
+    # https://crbug.com/686980
+    # This target relies on the linker to be smart and garbage collect unused symbols.
+    # It is not the case for LLD + ThinLTO, so we have to use this ugly workaround.
+    cflags = [
+      "-Xclang",
+      "-fno-lto-unit",
+      "-fno-whole-program-vtables",
+      "-fno-sanitize=cfi",
+    ]
+  }
+
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [
     "//build/config/compiler:no_chromium_code",