JDK-8210836 : Build fails with warn_unused_result in openjdk/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 8,11,12
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-09-17
  • Updated: 2019-07-29
  • Resolved: 2018-09-18
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 JDK 12
11.0.2Fixed 12 b12Fixed
Related Reports
Relates :  
Description
This error

openjdk/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c:798:7: error: ignoring return value of 'pread', declared with attribute warn_unused_result [-Werror=unused-result]
       pread(ph->core->exec_fd, interp_name, exec_php->p_filesz, exec_php->p_offset);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

was seen while trying to build OpenJDK on an Ubuntu 18.04 VM with compiler

* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 7.3.0 (at /usr/bin/gcc)
* C++ Compiler:   Version 7.3.0 (at /usr/bin/g++)

This change fixes the problem:

+++ b/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c
@@ -795,7 +795,9 @@
       if (exec_php->p_filesz > BUF_SIZE) {
         goto err;
       }
-      pread(ph->core->exec_fd, interp_name, exec_php->p_filesz, exec_php->p_offset);
+      if (pread(ph->core->exec_fd, interp_name, exec_php->p_filesz, exec_php->p_offset) != exec_php->p_filesz) {
+        goto err;
+      }
       interp_name[exec_php->p_filesz] = '\0';
       print_debug("ELF interpreter %s\n", interp_name);
       // read interpreter segments as well

Comments
The OpenJDK 8u change applies as-is once the backport of JDK-8140482 got approved.
29-07-2019

Fix Request: Asking for JDK 11u push approval for this, since it fixes a problem discovered by JDK-8210647 (libsaproc optimization). Since JDK-8210647 is being asked for JDK 11u approval, I'd like to push this to 11u too. The risk is minimal as it only improves error handling in SA code. The patch from JDK 12 applies as is.
02-10-2018

For the record, on the mailing lists Thomas pointed out that JDK-8210647 indeed caused the issue: http://mail.openjdk.java.net/pipermail/build-dev/2018-September/023308.html
19-09-2018

Brian Burkhalter: What's the compile command produced by the build? I've got this locally, which has -Wno-unused. It's gcc 8, though. Anyway, if JDK-8210647 really is the culprit, then changing the compile command by removing -O3 and adding -O0 should verify it. The below command does not produce any warning on my system, fwiw. /usr/bin/gcc -I/disk/openjdk/upstream-sources/openjdk-head-2/build/linux-x86_64-normal-server-release/support/modules_include/java.base -I/disk/openjdk/upstream-sources/openjdk-head-2/build/linux-x86_64-normal-server-release/support/modules_include/java.base/linux -I/disk/openjdk/upstream-sources/openjdk-head-2/src/java.base/share/native/libjava -I/disk/openjdk/upstream-sources/openjdk-head-2/src/java.base/unix/native/libjava -I/disk/openjdk/upstream-sources/openjdk-head-2/src/hotspot/share/include -I/disk/openjdk/upstream-sources/openjdk-head-2/src/hotspot/os/posix/include -pipe -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DLINUX -DNDEBUG -Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2 -fno-strict-aliasing -m64 -D_LITTLE_ENDIAN -DARCH='"amd64"' -Damd64 -D_LP64=1 -fno-omit-frame-pointer -fno-delete-null-pointer-checks -fno-lifetime-dse -fPIC -fvisibility=hidden -D_FILE_OFFSET_BITS=64 -I/disk/openjdk/upstream-sources/openjdk-head-2/src/jdk.hotspot.agent/linux/native/libsaproc -I/disk/openjdk/upstream-sources/openjdk-head-2/src/jdk.hotspot.agent/share/native/libsaproc -I/disk/openjdk/upstream-sources/openjdk-head-2/build/linux-x86_64-normal-server-release/support/headers/jdk.hotspot.agent -g -Wno-sign-compare -O3 -DTHIS_FILE='""' -c -MMD -MF /disk/openjdk/upstream-sources/openjdk-head-2/build/linux-x86_64-normal-server-release/support/native/jdk.hotspot.agent/libsaproc/ps_core.d -o /disk/openjdk/upstream-sources/openjdk-head-2/build/linux-x86_64-normal-server-release/support/native/jdk.hotspot.agent/libsaproc/ps_core.o /disk/openjdk/upstream-sources/openjdk-head-2/src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c
18-09-2018

"configure [...] --disable-warnings-as-errors" should be a viable work-around too.
18-09-2018

I bumped the prio to P2 for now since there's a known workaround, but P1 is also a perfectly fine alternative.
18-09-2018

Should be higher than P4, since it may be a build-breaker for some developers
17-09-2018

Most likely cased by JDK-8210647.
17-09-2018