eclipse-cyclonedds / cyclonedds

Eclipse Cyclone DDS project
https://projects.eclipse.org/projects/iot.cyclonedds
Other
819 stars 350 forks source link

Segmentation fault during idlc generating #808

Closed homalozoa closed 3 years ago

homalozoa commented 3 years ago

Hi. I got this error when building CyclongDDS with 'Release' build type. Both master branch and iceoryx branch.But it is OK with 'Debug' build type. BTW, The GCC version is 11.1.

I don't have a clue.

[ 80%] Building C object src/tools/idlpp/CMakeFiles/idlpp.dir/src/system.c.o [ 80%] Linking C static library ../../../lib/libidlpp.a [ 80%] Built target idlpp [ 80%] [BISON][parser] Building parser with bison 3.7.6 [ 80%] Building C object src/idl/CMakeFiles/idl.dir/src/symbol.c.o [ 81%] Building C object src/idl/CMakeFiles/idl.dir/src/directive.c.o [ 81%] Building C object src/idl/CMakeFiles/idl.dir/src/expression.c.o [ 82%] Building C object src/idl/CMakeFiles/idl.dir/src/file.c.o [ 82%] Building C object src/idl/CMakeFiles/idl.dir/src/processor.c.o [ 82%] Building C object src/idl/CMakeFiles/idl.dir/src/scanner.c.o [ 83%] Building C object src/idl/CMakeFiles/idl.dir/src/string.c.o [ 83%] Building C object src/idl/CMakeFiles/idl.dir/src/annotation.c.o [ 83%] Building C object src/idl/CMakeFiles/idl.dir/src/scope.c.o [ 84%] Building C object src/idl/CMakeFiles/idl.dir/src/tree.c.o [ 84%] Building C object src/idl/CMakeFiles/idl.dir/src/visit.c.o [ 85%] Building C object src/idl/CMakeFiles/idl.dir/src/thread.c.o [ 85%] Building C object src/idl/CMakeFiles/idl.dir/src/print.c.o [ 85%] Building C object src/idl/CMakeFiles/idl.dir/hashid.c.o [ 86%] Building C object src/idl/CMakeFiles/idl.dir/parser.c.o [ 86%] Linking C shared library ../../lib/libidl.so [ 86%] Built target idl [ 87%] Building C object src/tools/idlc/CMakeFiles/idlc.dir/src/idlc.c.o [ 87%] Building C object src/tools/idlc/CMakeFiles/idlc.dir/src/plugin.c.o [ 87%] Building C object src/tools/idlc/CMakeFiles/idlc.dir/src/options.c.o [ 88%] Building C object src/tools/idlc/CMakeFiles/idlc.dir/src/generator.c.o [ 88%] Building C object src/tools/idlc/CMakeFiles/idlc.dir/src/descriptor.c.o [ 89%] Building C object src/tools/idlc/CMakeFiles/idlc.dir/src/types.c.o [ 89%] Linking C executable ../../../bin/idlc [ 89%] Built target idlc [ 90%] Generating ddsperf_types.c, ddsperf_types.h make[2]: *** [src/tools/ddsperf/CMakeFiles/ddsperf_types_generate.dir/build.make:75: src/tools/ddsperf/ddsperf_types.c] Segmentation fault (core dumped) make[1]: *** [CMakeFiles/Makefile2:544: src/tools/ddsperf/CMakeFiles/ddsperf_types_generate.dir/all] Error 2

homalozoa commented 3 years ago

I find a temp solution. Just remove static from here : https://github.com/eclipse-cyclonedds/cyclonedds/blob/master/src/idl/src/tree.c#L258 . Then everything will be OK. It seems if declare this function as static, the compiler would optimize the pointer nodep to NULL.

k0ekk0ek commented 3 years ago

Hi @paeunt. Thanks for the report! I actually upgraded my workstation so I have GCC 11 too, but like you stated the problem isn't there with a Debug build. Since create_node is only every called from within tree.c it seems weird that making that non-static solves the problem. I'll look into what's going on.

k0ekk0ek commented 3 years ago

This is reproducible when using RelWithDebugInfo and that shows NULL is passed to idl_declare. And that's with parsing of builtin annotations, so before it's even parsing the given .idl file. Why it occurs is still a riddle.

k0ekk0ek commented 3 years ago

Disabling strict aliasing ensures the problem does not occur. Of course, that's but a temporary work around until the problem is actually fixed.

homalozoa commented 3 years ago

Thanks to reply, @k0ekk0ek. Another solution is change the argument void *nodep to voide **nodep, and change *((idl_node_t **)nodep) = node; to *nodep = node;. Like this : https://github.com/paeunt/cyclonedds/commit/a5b1ce9f311c6dd4fc0b6b8260cdab88b42e13c7

homalozoa commented 3 years ago

But it would cause other warnings like

`/home/nut/git_local/cyclonedds/src/idl/src/tree.c: In function ‘idl_finalize_annotation_appl’: /home/nut/git_local/cyclonedds/src/idl/src/tree.c:2695:61: warning: passing argument 6 of ‘create_node’ from incompatible pointer type [-Wincompatible-pointer-types] 2695 if (create_node(pstate, size, mask, location, &methods, &parameter)) { ^~~~~~
idl_annotation_appl_param_t {aka struct idl_annotation_appl_param }
/home/nut/git_local/cyclonedds/src/idl/src/tree.c:265:10: note: expected ‘void ’ but argument is of type ‘idl_annotation_appl_param_t ’ {aka ‘struct idl_annotation_appl_param **’} 265 void **nodep) ~^~~ /home/nut/git_local/cyclonedds/src/idl/src/tree.c: In function ‘idl_create_annotation_appl’: /home/nut/git_local/cyclonedds/src/idl/src/tree.c:2728:65: warning: passing argument 6 of ‘create_node’ from incompatible pointer type [-Wincompatible-pointer-types] 2728 if ((ret = create_node(state, size, mask, location, &methods, &node))) ^~~~~
idl_annotation_appl_t {aka struct idl_annotation_appl }

`