JDK-8179887 : Build failure with glibc >= 2.24: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: OpenJDK6,openjdk7u,8u171,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-05-08
  • Updated: 2019-06-20
  • Resolved: 2018-05-02
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 11
11 b12Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
It seems that OpenJDK build fails on Linux systems with newer glibc (>= 2.24), because readdir_r got deprecated, see https://lwn.net/Articles/696469/. 

/home/xbmc/shenandoah-jdk9/hotspot/src/os/linux/vm/os_linux.inline.hpp: In static member function 'static dirent* os::readdir(DIR*, dirent*)':
/home/xbmc/shenandoah-jdk9/hotspot/src/os/linux/vm/os_linux.inline.hpp:109:18: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated [-Werror=deprecated-declarations]
   if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
                  ^~~~~~~~~
In file included from /home/xbmc/shenandoah-jdk9/hotspot/src/os/linux/vm/jvm_linux.h:44:0,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/prims/jvm.h:31,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/utilities/debug.hpp:29,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/runtime/globals.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/memory/allocation.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/memory/memRegion.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/gc/shared/barrierSet.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/runtime/handles.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/memory/universe.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/code/oopRecorder.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/asm/codeBuffer.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/asm/assembler.hpp:28,
                 from /home/xbmc/shenandoah-jdk9/hotspot/src/share/vm/precompiled/precompiled.hpp:29:

Initially assigning to hotspot/runtime, seems the closest one. This might be the important thing to get into 9 or 9u.
Comments
Fix is broken - see JDK-8202835.
09-05-2018

Also see: http://mail.openjdk.java.net/pipermail/build-dev/2018-April/021530.html maybe there will be a real fix for readdir by the time they actually remove readdir_r.
22-04-2018

8187667 is not a duplicate, but a workaround.
21-04-2018

Re-opening as just hiding the warning is not a fix: http://mail.openjdk.java.net/pipermail/hotspot-dev/2018-March/030847.html
21-04-2018

This wasn't fixed by JDK-8187667, but worked around by turning off the warning. To fix it would be to remove readdir_r usage, as mentioned above.
14-03-2018

This was fixed by JDK-8187667.
12-03-2018

Taking this one as I've encountered it on building OpenJDK 7 & 8 too, where the build is broken due to the default use of -Werror. For existing releases (7,8, 9), I think the right thing is to just disable the deprecation warning. For 10, we can look at switching to readdir. My examination of the call sites (src/os/linux/vm/perfMemory_linux.cpp, src/share/vm/runtime/arguments.cpp) so far shows that the DIR* used is local to the function calling readdir_r in each case. The calling code also uses it as if it was a readdir(DIR*, dirent*) call, with the redirection to readdir_r and its additional argument being contained in os_linux.inline.hpp: if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { errno = status; return NULL; } else return p; As glibc is multi-thread safe on different directory streams, this could be potentially be simplified to just 'return readdir(dirp)'. Indeed, src/os/linux/vm/os_linux.cpp already uses ::readdir(dir) and the allocated buffer is never used by the calling code; it uses the return value of readdir.
26-07-2017

Unless there is a runtime failure on platforms with glibc 2.24 this seems not essential for 9. Build failures are annoying but can be worked around in general and we are too late in the 9 release to make changes in 9 - unless the change is simply to ignore the deprecation warning ie a simple build change? But then the developer can do that locally themselves. The actual functional change needs more in-depth analysis. See discussion: https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html
09-05-2017