JDK-6681796 : hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk6
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P3
  • Affected Version: OpenJDK6,7
  • OS: linux,linux_2.6
  • CPU: x86
  • Submit Date: 2008-03-29
  • Updated Date: 2012-10-08
  • Resolved Date: 2008-07-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 Availabitlity Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u10Fixed 7Fixed
Related Reports
Duplicate :  
Relates :  
Description
I tried compiling openjdk6 b08 on ubuntu 8.04.  The default compiler is gcc 4.2.x.  The following
does not occur on ubuntu 7.10 where the default gcc is 4.1.x.

Some hotspot files fail to compile due to warnings.  The default hotspot makefiles use
the -Werror flag, making warnings into errors and the build fails.  The warnings are
about type conversion of strings to constants.

The obvious workaround is to edit the hotspot makefile to not use -Werror.  This works.

I also made the following source changes and had a successful compile.  The idea is to
in some cases change some declarations to use "const char *" instead of "char *"
and in other cases cast string constants to "char *" depending on the context.

--- ./hotspot/src/share/vm/opto/escape-orig.cpp 2008-03-24 14:42:12.000000000 -0700
+++ ./hotspot/src/share/vm/opto/escape.cpp      2008-03-24 14:45:09.000000000 -0700
@@ -54,21 +54,21 @@
 }
 
 #ifndef PRODUCT
-static char *node_type_names[] = {
+static const char *node_type_names[] = {
   "UnknownType",
   "JavaObject",
   "LocalVar",
   "Field"
 };
 
-static char *esc_names[] = {
+static const char *esc_names[] = {
   "UnknownEscape",
   "NoEscape     ",
   "ArgEscape    ",
   "GlobalEscape "
 };
 
-static char *edge_type_suffix[] = {
+static const char *edge_type_suffix[] = {
  "?", // UnknownEdge
  "P", // PointsToEdge
  "D", // DeferredEdge
--- ./hotspot/src/share/vm/ci/ciMethodBlocks-orig.cpp   2008-03-24 14:39:19.000000000 -0700
+++ ./hotspot/src/share/vm/ci/ciMethodBlocks.cpp        2008-03-24 14:40:06.000000000 -0700
@@ -321,7 +321,7 @@
 }
 
 #ifndef PRODUCT
-static char *flagnames[] = {
+static const char *flagnames[] = {
   "Processed",
   "Handler",
   "MayThrow",
--- ./hotspot/src/os/linux/vm/jvm_linux-orig.cpp        2008-03-24 14:01:55.000000000 -0700
+++ ./hotspot/src/os/linux/vm/jvm_linux.cpp     2008-03-24 14:02:07.000000000 -0700
@@ -135,7 +135,7 @@
 */
 
 struct siglabel {
-  char *name;
+  const char *name;
   int   number;
 };
 
--- ./hotspot/src/os/linux/vm/vmError_linux-orig.cpp    2008-03-24 14:25:17.000000000 -0700
+++ ./hotspot/src/os/linux/vm/vmError_linux.cpp 2008-03-24 14:26:01.000000000 -0700
@@ -50,8 +50,8 @@
 // doesn't block SIGINT et al.
 int VMError::fork_and_exec(char* cmd) {
   char * argv[4];
-  argv[0] = "sh";
-  argv[1] = "-c";
+  argv[0] = (char *)"sh";
+  argv[1] = (char *)"-c";
   argv[2] = cmd;
   argv[3] = NULL;

Comments
EVALUATION The fix is to try to use "const char*" to define constant string and apply the cast from "const char*" to "char*" carefully.
2008-06-06

SUGGESTED FIX Here is a patch contributed by Neal Gafter. I think it is similar to Jesse Glick's patch. http://mail.openjdk.java.net/pipermail/build-dev/2008-April/000987.html diff -r 24706b95d959 src/os/linux/vm/jvm_linux.cpp --- a/src/os/linux/vm/jvm_linux.cpp Thu Apr 24 12:12:10 2008 -0700 +++ b/src/os/linux/vm/jvm_linux.cpp Tue May 20 15:18:45 2008 -0700 @@ -132,7 +132,7 @@ JVM_END */ struct siglabel { - char *name; + const char *name; int number; }; diff -r 24706b95d959 src/os/linux/vm/os_linux.cpp --- a/src/os/linux/vm/os_linux.cpp Thu Apr 24 12:12:10 2008 -0700 +++ b/src/os/linux/vm/os_linux.cpp Tue May 20 15:18:45 2008 -0700 @@ -213,7 +213,7 @@ pid_t os::Linux::gettid() { // the system call returns 1. This causes the VM to act as if it is // a single processor and elide locking (see is_MP() call). static bool unsafe_chroot_detected = false; -static char *unstable_chroot_error = "/proc file system not found.\n" +static const char *unstable_chroot_error = "/proc file system not found.\n" "Java may be unstable running multithreaded in a chroot " "environment on Linux when /proc filesystem is not mounted."; @@ -557,13 +557,13 @@ void os::Linux::libpthread_init() { // NPTL: if (sysconf(_SC_THREAD_THREADS_MAX) > 0) { free(str); - str = "linuxthreads"; + str = (char *)"linuxthreads"; } } os::Linux::set_libpthread_version(str); } else { // glibc before 2.3.2 only has LinuxThreads. - os::Linux::set_libpthread_version("linuxthreads"); + os::Linux::set_libpthread_version((char *)"linuxthreads"); } if (strstr(libpthread_version(), "NPTL")) { @@ -4538,7 +4538,7 @@ extern char** environ; // Unlike system(), this function can be called from signal handler. It // doesn't block SIGINT et al. int os::fork_and_exec(char* cmd) { - char * argv[4]; + const char * argv[4]; argv[0] = "sh"; argv[1] = "-c"; argv[2] = cmd;
2008-06-05