-
Bug
-
Resolution: Not an Issue
-
P3
-
21, 23
-
x86_64
-
linux
ADDITIONAL SYSTEM INFORMATION :
Gentoo Linux
GCC 13
A DESCRIPTION OF THE PROBLEM :
I tried to build with the following {C,CXX,FC,LD}FLAGS to optimize the build: `-flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing`
Link-Time Optimization is a massively global compiler optimization pass which is pretty handy for producing faster executables. It also has the interesting property that because the compiler does whole-program analysis using bytecode, it can save type information and perform error checks that it normally doesn’t have enough insight for. In particular, checking for ODR issues and checking function type signature mismatches.
Note that *all* the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.
I got an error. I git blamed it to this openjdk commit: https://github.com/openjdk/jdk21u/commit/c199b8c761c14542953a01c1efd6ccec95179234
REGRESSION : Last worked in version 17.0.12
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile with --with-jvm-features=link-time-opt. Use these CFLAGS / CXXFLAGS / LDFLAGS to safety-check the result:
CFLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"
CXXFLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"
LDFLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A successful compile.
ACTUAL -
```
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.hpp:128:14: error: 'jfr_abort' violates the C++ One Definition Rule [-Werror=odr]
128 | void JNICALL jfr_abort(JNIEnv* env, jclass jvm, jstring errorMsg);
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: type mismatch in parameter 2
339 | JVM_ENTRY_NO_ENV(void, jfr_abort(JNIEnv* env, jobject jvm, jstring errorMsg))
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: type 'struct _jobject *' should match type 'struct _jclass *'
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: 'jfr_abort' was previously declared here
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: code may be misoptimized unless '-fno-strict-aliasing' is used
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.hpp:126:14: error: 'jfr_flush' violates the C++ One Definition Rule [-Werror=odr]
126 | void JNICALL jfr_flush(JNIEnv* env, jclass jvm);
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: type mismatch in parameter 2
313 | JVM_ENTRY_NO_ENV(void, jfr_flush(JNIEnv* env, jobject jvm))
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: type 'struct _jobject *' should match type 'struct _jclass *'
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: 'jfr_flush' was previously declared here
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: code may be misoptimized unless '-fno-strict-aliasing' is used
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.hpp:122:18: error: 'jfr_event_writer_flush' violates the C++ One Definition Rule [-Werror=odr]
122 | jboolean JNICALL jfr_event_writer_flush(JNIEnv* env, jclass cls, jobject writer, jint used_size, jint requested_size);
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:305:1: note: return value type mismatch
305 | NO_TRANSITION(void, jfr_event_writer_flush(JNIEnv* env, jclass jvm, jobject writer, jint used_size, jint requested_size))
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:305:1: note: type 'void' should match type 'jboolean'
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:305:1: note: 'jfr_event_writer_flush' was previously declared here
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/libexec/gcc/x86_64-pc-linux-gnu/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
```
CUSTOMER SUBMITTED WORKAROUND :
Disable link time optimization.
FREQUENCY : always
Gentoo Linux
GCC 13
A DESCRIPTION OF THE PROBLEM :
I tried to build with the following {C,CXX,FC,LD}FLAGS to optimize the build: `-flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing`
Link-Time Optimization is a massively global compiler optimization pass which is pretty handy for producing faster executables. It also has the interesting property that because the compiler does whole-program analysis using bytecode, it can save type information and perform error checks that it normally doesn’t have enough insight for. In particular, checking for ODR issues and checking function type signature mismatches.
Note that *all* the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.
I got an error. I git blamed it to this openjdk commit: https://github.com/openjdk/jdk21u/commit/c199b8c761c14542953a01c1efd6ccec95179234
REGRESSION : Last worked in version 17.0.12
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile with --with-jvm-features=link-time-opt. Use these CFLAGS / CXXFLAGS / LDFLAGS to safety-check the result:
CFLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"
CXXFLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"
LDFLAGS="-Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A successful compile.
ACTUAL -
```
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.hpp:128:14: error: 'jfr_abort' violates the C++ One Definition Rule [-Werror=odr]
128 | void JNICALL jfr_abort(JNIEnv* env, jclass jvm, jstring errorMsg);
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: type mismatch in parameter 2
339 | JVM_ENTRY_NO_ENV(void, jfr_abort(JNIEnv* env, jobject jvm, jstring errorMsg))
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: type 'struct _jobject *' should match type 'struct _jclass *'
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: 'jfr_abort' was previously declared here
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:339:1: note: code may be misoptimized unless '-fno-strict-aliasing' is used
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.hpp:126:14: error: 'jfr_flush' violates the C++ One Definition Rule [-Werror=odr]
126 | void JNICALL jfr_flush(JNIEnv* env, jclass jvm);
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: type mismatch in parameter 2
313 | JVM_ENTRY_NO_ENV(void, jfr_flush(JNIEnv* env, jobject jvm))
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: type 'struct _jobject *' should match type 'struct _jclass *'
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: 'jfr_flush' was previously declared here
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:313:1: note: code may be misoptimized unless '-fno-strict-aliasing' is used
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.hpp:122:18: error: 'jfr_event_writer_flush' violates the C++ One Definition Rule [-Werror=odr]
122 | jboolean JNICALL jfr_event_writer_flush(JNIEnv* env, jclass cls, jobject writer, jint used_size, jint requested_size);
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:305:1: note: return value type mismatch
305 | NO_TRANSITION(void, jfr_event_writer_flush(JNIEnv* env, jclass jvm, jobject writer, jint used_size, jint requested_size))
| ^
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:305:1: note: type 'void' should match type 'jboolean'
<jdk21u-jdk-21.0.4-ga>/src/hotspot/share/jfr/jni/jfrJniMethod.cpp:305:1: note: 'jfr_event_writer_flush' was previously declared here
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/libexec/gcc/x86_64-pc-linux-gnu/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
```
CUSTOMER SUBMITTED WORKAROUND :
Disable link time optimization.
FREQUENCY : always
- blocks
-
JDK-8348848 Link time optimization support [umbrella]
-
- Open
-
- relates to
-
JDK-8339149 jfr_flush_event_writer - return value type mismatch
-
- Resolved
-
-
JDK-8344080 Return type mismatch for jfr_unregister_stack_filter
-
- Resolved
-
-
JDK-8344161 Argument type mismatch for jfr_type_id
-
- Resolved
-