eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.28k stars 722 forks source link

Build error: "storing the address of local variable" in runtime/rastrace/trcmain.c #20171

Closed knn-k closed 1 month ago

knn-k commented 1 month ago

Building OpenJ9 Java 17 with GCC 13.2.0 on Ubuntu 24.04.1 generates the following error:

/home/openj9/openj9-openjdk-jdk17/openj9/runtime/rastrace/trcmain.c:1045:14: error: storing the address of local variable 'tempThr' in '*thr' [-Werror=dangling-pointer=]
 1045 |         *thr = &tempThr;
      |         ~~~~~^~~~~~~~~~
/home/openj9/openj9-openjdk-jdk17/openj9/runtime/rastrace/trcmain.c:1033:23: note: 'tempThr' declared here
 1033 |         UtThreadData  tempThr;
      |                       ^~~~~~~
/home/openj9/openj9-openjdk-jdk17/openj9/runtime/rastrace/trcmain.c:1026:32: note: 'thr' declared here
 1026 | initializeTrace(UtThreadData **thr, void **gbl,
      |                 ~~~~~~~~~~~~~~~^~~

https://github.com/eclipse-openj9/openj9/blob/0985ff3f82bfdf1944c81f6242466fcbae2308b5/runtime/rastrace/trcmain.c#L1045

tempThr is a local variable in initializeTrace(). thr is the first argument for initializeTrace(). The address of tempThr is used by J9VMDllMain() in trcengine.c, the caller of initializeTrace(). https://github.com/eclipse-openj9/openj9/blob/0985ff3f82bfdf1944c81f6242466fcbae2308b5/runtime/rastrace/trcengine.c#L363

The memory region for tempThr in the stack can be overwritten by other functions. I think J9VMDllMain() should prepare the memory region for UtThreadData, as J9VMDllMain() seems to be the only caller of initializeTrace().

knn-k commented 1 month ago

Another build error with GCC 13.2.0: #20170

knn-k commented 1 month ago

I opened a draft PR: #20172