Bug 1377445 - Use dlsym for atk_bridge_adaptor_init. r=eeejay
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 20 Apr 2021 01:57:02 +0000
changeset 576696 44d676a26d1a8c6514eca25ef4310e7f2a9df873
parent 576695 30af8f80e2754783f1981485dd911a2e341d9afd
child 576697 0ce69d9f596b3910876f4838c5b04250a553b9c4
push id38390
push userimoraru@mozilla.com
push dateTue, 20 Apr 2021 09:51:22 +0000
treeherdermozilla-central@a916ade0ae29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseeejay
bugs1377445, 1368363
milestone89.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1377445 - Use dlsym for atk_bridge_adaptor_init. r=eeejay Currently, we use a weak symbol to call atk_bridge_adaptor_init, but for some reason, this stops working when removing the mozgtk stub library (which we can do now that we don't need gtk+2 support at all), in a way similar to bug 1368363. We've been using a weak symbol because atk-bridge 2.0 was not guaranteed to be enabled in gtk+3 back when this was added, but things have changed since then, and gtk+3 always requires atk-bridge 2.0... ... on X11. Unfortunately, that's not the case on Wayland, and a gtk+3 built with Wayland support only will not depend on atk-bridge 2.0. So all in all, we're back to square one, and because this fails to build, we need another approach. It turns out that other approach was in place for gtk+2, in the form of dlopen/dlsym, the code for which somehow survived the years despite Firefox not actually using gtk+2 for accessibility. So we repurpose that code to load atk-bridge 2.0, which also happens to not be a gtk+3 module, so we can remove the whole code path that tries to load it from the gtk-3.0/modules path. Differential Revision: https://phabricator.services.mozilla.com/D111996
accessible/atk/Platform.cpp
--- a/accessible/atk/Platform.cpp
+++ b/accessible/atk/Platform.cpp
@@ -14,103 +14,61 @@
 #include "prenv.h"
 #include "prlink.h"
 
 #ifdef MOZ_ENABLE_DBUS
 #  include <dbus/dbus.h>
 #endif
 #include <gtk/gtk.h>
 
-#ifdef MOZ_WIDGET_GTK
-extern "C" __attribute__((weak, visibility("default"))) int
-atk_bridge_adaptor_init(int*, char**[]);
-#endif
-
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 int atkMajorVersion = 1, atkMinorVersion = 12, atkMicroVersion = 0;
 
 GType (*gAtkTableCellGetTypeFunc)();
 
 extern "C" {
 typedef GType (*AtkGetTypeType)(void);
-typedef void (*GnomeAccessibilityInit)(void);
-typedef void (*GnomeAccessibilityShutdown)(void);
+typedef void (*AtkBridgeAdaptorInit)(int*, char**[]);
 }
 
 static PRLibrary* sATKLib = nullptr;
 static const char sATKLibName[] = "libatk-1.0.so.0";
 static const char sATKHyperlinkImplGetTypeSymbol[] =
     "atk_hyperlink_impl_get_type";
 
 gboolean toplevel_event_watcher(GSignalInvocationHint*, guint, const GValue*,
                                 gpointer);
 static bool sToplevel_event_hook_added = false;
 static gulong sToplevel_show_hook = 0;
 static gulong sToplevel_hide_hook = 0;
 
 GType g_atk_hyperlink_impl_type = G_TYPE_INVALID;
 
-struct GnomeAccessibilityModule {
+struct AtkBridgeModule {
   const char* libName;
   PRLibrary* lib;
   const char* initName;
-  GnomeAccessibilityInit init;
-  const char* shutdownName;
-  GnomeAccessibilityShutdown shutdown;
+  AtkBridgeAdaptorInit init;
 };
 
-static GnomeAccessibilityModule sAtkBridge = {
-#ifdef AIX
-    "libatk-bridge.a(libatk-bridge.so.0)", nullptr,
-#else
-    "libatk-bridge.so", nullptr,
-#endif
-    "gnome_accessibility_module_init",     nullptr,
-    "gnome_accessibility_module_shutdown", nullptr};
+static AtkBridgeModule sAtkBridge = {"libatk-bridge-2.0.so.0", nullptr,
+                                     "atk_bridge_adaptor_init", nullptr};
 
-static nsresult LoadGtkModule(GnomeAccessibilityModule& aModule) {
+static nsresult LoadGtkModule(AtkBridgeModule& aModule) {
   NS_ENSURE_ARG(aModule.libName);
 
   if (!(aModule.lib = PR_LoadLibrary(aModule.libName))) {
-    // try to load the module with "gtk-2.0/modules" appended
-    char* curLibPath = PR_GetLibraryPath();
-    nsAutoCString libPath(curLibPath);
-#if defined(LINUX) && defined(__x86_64__)
-    libPath.AppendLiteral(":/usr/lib64:/usr/lib");
-#else
-    libPath.AppendLiteral(":/usr/lib");
-#endif
-    PR_FreeLibraryName(curLibPath);
-
-    int16_t loc1 = 0, loc2 = 0;
-    int16_t subLen = 0;
-    while (loc2 >= 0) {
-      loc2 = libPath.FindChar(':', loc1);
-      if (loc2 < 0) {
-        subLen = libPath.Length() - loc1;
-      } else {
-        subLen = loc2 - loc1;
-      }
-      nsAutoCString sub(Substring(libPath, loc1, subLen));
-      sub.AppendLiteral("/gtk-3.0/modules/");
-      sub.Append(aModule.libName);
-      aModule.lib = PR_LoadLibrary(sub.get());
-      if (aModule.lib) break;
-
-      loc1 = loc2 + 1;
-    }
-    if (!aModule.lib) return NS_ERROR_FAILURE;
+    return NS_ERROR_FAILURE;
   }
 
   // we have loaded the library, try to get the function ptrs
-  if (!(aModule.init = PR_FindFunctionSymbol(aModule.lib, aModule.initName)) ||
-      !(aModule.shutdown =
-            PR_FindFunctionSymbol(aModule.lib, aModule.shutdownName))) {
+  if (!(aModule.init = (AtkBridgeAdaptorInit)PR_FindFunctionSymbol(
+            aModule.lib, aModule.initName))) {
     // fail, :(
     PR_UnloadLibrary(aModule.lib);
     aModule.lib = nullptr;
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
@@ -159,26 +117,19 @@ void a11y::PlatformInit() {
     }
   }
 
   // Initialize the MAI Utility class, it will overwrite gail_util.
   g_type_class_unref(g_type_class_ref(mai_util_get_type()));
 
   // Init atk-bridge now
   PR_SetEnv("NO_AT_BRIDGE=0");
-#ifdef MOZ_WIDGET_GTK
-  if (atk_bridge_adaptor_init) {
-    atk_bridge_adaptor_init(nullptr, nullptr);
-  } else
-#endif
-  {
-    nsresult rv = LoadGtkModule(sAtkBridge);
-    if (NS_SUCCEEDED(rv)) {
-      (*sAtkBridge.init)();
-    }
+  nsresult rv = LoadGtkModule(sAtkBridge);
+  if (NS_SUCCEEDED(rv)) {
+    (*sAtkBridge.init)(nullptr, nullptr);
   }
 
   if (!sToplevel_event_hook_added) {
     sToplevel_event_hook_added = true;
     sToplevel_show_hook = g_signal_add_emission_hook(
         g_signal_lookup("show", GTK_TYPE_WINDOW), 0, toplevel_event_watcher,
         reinterpret_cast<gpointer>(nsIAccessibleEvent::EVENT_SHOW), nullptr);
     sToplevel_hide_hook = g_signal_add_emission_hook(
@@ -194,22 +145,19 @@ void a11y::PlatformShutdown() {
                                   sToplevel_show_hook);
     g_signal_remove_emission_hook(g_signal_lookup("hide", GTK_TYPE_WINDOW),
                                   sToplevel_hide_hook);
   }
 
   if (sAtkBridge.lib) {
     // Do not shutdown/unload atk-bridge,
     // an exit function registered will take care of it
-    // if (sAtkBridge.shutdown)
-    //     (*sAtkBridge.shutdown)();
     // PR_UnloadLibrary(sAtkBridge.lib);
     sAtkBridge.lib = nullptr;
     sAtkBridge.init = nullptr;
-    sAtkBridge.shutdown = nullptr;
   }
   // if (sATKLib) {
   //     PR_UnloadLibrary(sATKLib);
   //     sATKLib = nullptr;
   // }
 }
 
 static const char sAccEnv[] = "GNOME_ACCESSIBILITY";