JDK-8046408 : Build failure from multiple ptrace.h
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • Submitted: 2014-06-09
  • Updated: 2015-12-16
  • Resolved: 2014-06-16
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 8 JDK 9
8u20Fixed 9 b22Fixed
Related Reports
Relates :  
Description
"I" in the following is kim.barrett@oracle.com.  I don't have a JIRA account yet.

Attempting to build jdk9/dev on SuSE 13.1, I encountered the following build error:

In file included from /home/kab/sandboxes/kab-test/hotspot/agent/src/os/linux/libproc.h:37:0,
                 from /home/kab/sandboxes/kab-test/hotspot/agent/src/os/linux/libproc_impl.h:30,
                 from /home/kab/sandboxes/kab-test/hotspot/agent/src/os/linux/ps_proc.c:33:
/usr/include/linux/ptrace.h:58:8: error: redefinition of ���struct ptrace_peeksiginfo_args���
 struct ptrace_peeksiginfo_args {
        ^
In file included from /home/kab/sandboxes/kab-test/hotspot/agent/src/os/linux/ps_proc.c:32:0:
/usr/include/sys/ptrace.h:191:8: note: originally defined here
 struct ptrace_peeksiginfo_args
        ^

The problem is that ps_proc.c is directly including <sys/ptrace.h> and indirect including <linux/ptrace.h> (via "libproc.h"), and they appear to be incompatible on the system in question.  A bit of web searches would seem to indicate that including both is generally not a good idea.  For example, linux/ptrace.h defines as macros some names that sys/ptrace.h defines as enum constants.  An include order of linux/ptrace.h first then sys/ptrace.h likely results in lots of syntax errors.

The include of <linux/ptrace.h> was added here:
  mikael c884ec3ea87f Tue Apr 29 22:05:10 2014 -0700: #include <linux/ptrace.h>

I'm not sure why I'm getting a compiler error here but presumably most other folks are not.  It may have something to do with the combination of compiler version (g++4.8.1).

Changing hotspot/agent/src/os/linux/libproc.h to include <sys/ptrace.h> rather than <linux/ptrace.h> eliminated the error for me, and allowed my build to run.

Comments
There are two ptrace.h headers available for linux, <sys/ptrace.h> and <linux/ptrace.h>. A new struct (ptrace_peeksiginfo_args) was recently added to each, but the addition in <sys/ptrace.h> didn't follow the convention there of using a double-underscore prefix for type names declared in that file. As a result, if both headers are included (as is occurring in our code), there are multiple definitions of that struct. It appears to be a "well known" problem that already has a fix [1], but glibc 2.18 was released with this problem. The inclusion of both variants is due to a file (ps_proc.c) directly including <sys/ptrace.h> and indirectly including <linux/ptrace.h>, where the indirectly including header is used in other places that don't include <sys/ptrace.h>. Our code can presently use either of the headers. The number of affected system configurations is likely small, but this is easy to fix. Proposed change is to prefer <sys/ptrace.h> rather than <linux/ptrace.h>. I've submitted a patch. [1] https://www.sourceware.org/ml/libc-alpha/2014-01/msg00078.html
13-06-2014