JDK-8156020 : 8145547 breaks AIX and and uses RTLD_NOLOAD incorrectly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-05-04
  • Updated: 2016-05-26
  • Resolved: 2016-05-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b118Fixed
Related Reports
Duplicate :  
Relates :  
Description
Change 8145547 uses the RTLD_NOLOAD flag when calling dlopen to probe the availability of the GTK libraries.

But unfortunately RTLD_NOLOAD is not Posix and for example not available on AIX and BSD.

I also found out, that the implementation of 8145547 contains a bug. It uses RTLD_NOLOAD in an incorrect way. The man page for dlopen clearly states that one of the two flags RTLD_LAZY or RTLD_NOW has to be included in the flags. But the current implementation uses RTLD_NOLOAD as single flag. Therefor the call to dlopen() currently always returns NULL, no difference if the corresponding library has been loaded already or not.

The following short C program demonstrates the problem:

#include <dlfcn.h>
#include <stdio.h>

int main(int argc, char **argv) {

  void* l = dlopen("libgtk-x11-2.0.so.0", RTLD_LAZY | RTLD_LOCAL);
  fprintf(stderr, "l = %p\n", l);

  dlerror();
  l = dlopen("libgtk-x11-2.0.so.0", RTLD_NOLOAD);
  fprintf(stderr, "l = %p (error = %s)\n", l, dlerror());

  l = dlopen("libgtk-x11-2.0.so.0", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
  fprintf(stderr, "l = %p\n", l);

}

It will print:

l = 0x10033f81c50
l = (nil) (error = libgtk-x11-2.0.so.0: invalid mode for dlopen(): Invalid argument)
l = 0x10033f81c50

Comments
Notice, that the implementation of sun.awt.UNIXToolkit.check_gtk() breaks the contract of its caller UNIXToolkit.isNativeGTKAvailable() which states: /** * Returns true if the native GTK libraries are capable of being * loaded and are expected to work properly, false otherwise. Note * that this method will not leave the native GTK libraries loaded if * they haven't already been loaded. This allows, for example, Swing's * GTK L&F to test for the presence of native GTK support without * leaving the native libraries loaded. To attempt long-term loading * of the native GTK libraries, use the loadGTK() method instead. */ But a call to isNativeGTKAvailable() will definitely load libgtk into the process space (see Java_sun_awt_UNIXToolkit_check_1gtk() -> gtk_check_version() -> check_version() -> gtk2_check()). However this was already true before 8145547 and is probably caused by the fix for 8048289 which simply uncommented the call to dlclose() in gtk2_check().
04-05-2016