Explicitly preload libgomp

libgomp has a long lasting TLS bug
(https://bugzilla.redhat.com/show_bug.cgi?id=1722181). Preload the
library in gst-plugin-scanner to resolve the TLS memory issue while
launching gstreamer.

b/165530393

Change-Id: Ibdde0b7e460567af07a3cc13088126b007919f10
diff --git a/debian/patches/0002-explicitly-load-libgomp.patch b/debian/patches/0002-explicitly-load-libgomp.patch
new file mode 100644
index 0000000..8d35e41
--- /dev/null
+++ b/debian/patches/0002-explicitly-load-libgomp.patch
@@ -0,0 +1,71 @@
+From 63aa2e3ac630dcad758b446fc56136e58058fffd Mon Sep 17 00:00:00 2001
+From: Cindy Liu <hcindyl@google.com>
+Date: Wed, 19 Aug 2020 17:22:29 -0700
+Subject: [PATCH] Explicitly load libgomp.so.1 in gst-plugin-scanner
+
+libgomp has a long lasting TLS bug
+(https://bugzilla.redhat.com/show_bug.cgi?id=1722181). Preload the
+library in gst-plugin-scanner to resolve the TLS memory issue while
+launching gstreamer.
+
+Change-Id: I8ebedaf320a6b4253e8804946e4ff79bbde48ad7
+---
+ libs/gst/helpers/Makefile.am          | 4 +++-
+ libs/gst/helpers/gst-plugin-scanner.c | 6 +++++-
+ 2 files changed, 8 insertions(+), 2 deletions(-)
+
+diff --git a/libs/gst/helpers/Makefile.am b/libs/gst/helpers/Makefile.am
+index d72a6527..a7c6d6ce 100644
+--- a/libs/gst/helpers/Makefile.am
++++ b/libs/gst/helpers/Makefile.am
+@@ -3,7 +3,9 @@ helpersdir=$(libexecdir)/gstreamer-$(GST_API_VERSION)
+ 
+ gst_plugin_scanner_SOURCES = gst-plugin-scanner.c
+ gst_plugin_scanner_CFLAGS = $(GST_OBJ_CFLAGS)
+-gst_plugin_scanner_LDADD = $(GST_OBJ_LIBS)
++gst_plugin_scanner_LDADD = \
++	$(GST_OBJ_LIBS) \
++	-lgomp
+ 
+ if ENABLE_BASH_COMPLETION
+ helpers_PROGRAMS += gst-completion-helper
+diff --git a/libs/gst/helpers/gst-plugin-scanner.c b/libs/gst/helpers/gst-plugin-scanner.c
+index cbefb29e..0ad0480c 100644
+--- a/libs/gst/helpers/gst-plugin-scanner.c
++++ b/libs/gst/helpers/gst-plugin-scanner.c
+@@ -30,6 +30,7 @@
+ #include <gst/gst.h>
+ 
+ #include <string.h>
++#include <dlfcn.h>
+ 
+ int
+ main (int argc, char *argv[])
+@@ -37,6 +38,7 @@ main (int argc, char *argv[])
+   gboolean res;
+   char **my_argv;
+   int my_argc;
++  void *handle;
+ 
+   /* We may or may not have an executable path */
+   if (argc != 2 && argc != 3)
+@@ -50,6 +52,8 @@ main (int argc, char *argv[])
+   my_argv[0] = argv[0];
+   my_argv[1] = (char *) "--gst-disable-registry-update";
+ 
++  handle = dlopen("libgomp.so.1", RTLD_LAZY);
++
+ #ifndef GST_DISABLE_REGISTRY
+   _gst_disable_registry_cache = TRUE;
+ #endif
+@@ -66,6 +70,6 @@ main (int argc, char *argv[])
+   /* Create registry scanner listener and run */
+   if (!_gst_plugin_loader_client_run ())
+     return 1;
+-
++  dlclose(handle);
+   return 0;
+ }
+-- 
+2.28.0.220.ged08abb693-goog
+
diff --git a/debian/patches/series b/debian/patches/series
index 9339fe1..20c5429 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 0001-registrybinary-Update-magic-version-string.patch
 0002-gstconfig.h.in-initial-RISC-V-support.patch
 0001-mtk.patch
+0002-explicitly-load-libgomp.patch