rose-compiler / rose

Developed at Lawrence Livermore National Laboratory (LLNL), ROSE is an open source compiler infrastructure to build source-to-source program transformation and analysis tools for large-scale C (C89 and C98), C++ (C++98 and C++11), UPC, Fortran (77/95/2003), OpenMP, Java, Python and PHP applications.
http://rosecompiler.org
Other
606 stars 131 forks source link

calling frontend() throws SIGSEGV for C++ code (but not C code) #33

Closed qralston closed 5 years ago

qralston commented 5 years ago

We have a program that uses ROSE to analyze C/C++ source for coding errors. The core of the program is simply:

int main( int argc, char* argv[]) {
  SgProject* project = frontend(argc,argv);
  ROSE_ASSERT( project );
  AstSimpleProcessing* visitorTraversal;
  if (project->get_C_only())
    visitorTraversal = new CVisitorTraversal();
  else
    visitorTraversal = new CPPVisitorTraversal();
  visitorTraversal->traverseInputFiles( project, preorder);
  delete visitorTraversal;
  return 0;
}

We are compiling/linking against ROSE 0.9.10.54, which we built for RHEL7 (x86_64). Since we built and packaged ROSE as an rpm package, Red Hat's standard C flags were used to build both ROSE and our program, which are:

-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches

If we run our program against a C source file, it runs normally:

$ cat hello.c
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
int main (int argc, char *argv[]) {
  fprintf (stdout, "Hello, world!\n");
  return (0);
}

$ rosecheckers hello.c 
hello.c:6:27: warning: DCL13-C: Declare function parameters that are pointers to values not changed by the function as const: argv

But if we run it against a C++ source file, the call to frontend() segfaults:

$ cat hello.C
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}

$ rosecheckers hello.C
Segmentation fault (core dumped)

Here's the stack backtrace:

Reading symbols from /usr/bin/rosecheckers...done.
Reading symbols from /usr/lib/debug/usr/bin/rosecheckers.debug...done.
[New LWP 32739]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `rosecheckers hello.C'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000000001 in ?? ()
Missing separate debuginfos, use: debuginfo-install boost-chrono-1.53.0-27.el7.x86_64 boost-date-time-1.53.0-27.el7.x86_64 boost-filesystem-1.53.0-27.el7.x86_64 boost-iostreams-1.53.0-27.el7.x86_64 boost-program-options-1.53.0-27.el7.x86_64 boost-regex-1.53.0-27.el7.x86_64 boost-serialization-1.53.0-27.el7.x86_64 boost-system-1.53.0-27.el7.x86_64 boost-thread-1.53.0-27.el7.x86_64 boost-wave-1.53.0-27.el7.x86_64 bzip2-libs-1.0.6-13.el7.x86_64 glibc-2.17-260.el7.x86_64 libgcc-4.8.5-36.el7.x86_64 libicu-50.1.2-17.el7.x86_64 libstdc++-4.8.5-36.el7.x86_64 zlib-1.2.7-18.el7.x86_64
(gdb) bt
#0  0x0000000000000001 in ?? ()
#1  0x00007f97d5a0b39f in isSgSymbol (inputDerivedClassPointer=0x1401f10) at Cxx_Grammar.C:271859
#2  0x00007f97d6f239ad in EDG_ROSE_Translation::setupDeclarationScope (decl=0x7f97cd234ef8) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:19315
#3  0x00007f97d6f27f96 in EDG_ROSE_Translation::convert_template_struct_primary (p=0x14023f0, t=SgClassDeclaration::e_class, nonDefiningDecl=0x0, edg_template=0x1401cc0) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:20245
#4  0x00007f97d6f35faf in EDG_ROSE_Translation::parse_structlike (sse=..., p=0x14023f0, t=SgClassDeclaration::e_class, forceTemplateClassDeclaration=true, edg_template=0x1401cc0) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:22942
#5  0x00007f97d6faa0c2 in EDG_ROSE_Translation::parse_template (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:57588
#6  0x00007f97d6fc46f1 in EDG_ROSE_Translation::parse_global_or_namespace_scope_entity (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:63773
#7  0x00007f97d6fb6685 in EDG_ROSE_Translation::convert_namespace (p=0xfafb80, sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:61052
#8  0x00007f97d6ee757a in EDG_ROSE_Translation::parse_secondary_declaration (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:3267
#9  0x00007f97d6fc4031 in EDG_ROSE_Translation::parse_global_or_namespace_scope_entity (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:63594
#10 0x00007f97d6fc752b in EDG_ROSE_Translation::parse_global_scope (inputGlobalScope=0x7f97d93f8120, sse=..., skip_ast_translation=false) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:64447
#11 0x00007f97d6fc8f69 in sage_back_end (sageFile=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:65307
#12 0x00007f97d6fc9dac in cfe_main (argc=37, argv=0xf88fc0, sageFile=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:65520
#13 0x00007f97d6fc9f09 in edg_main (argc=37, argv=0xf88fc0, sageFile=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:65622
#14 0x00007f97d58d38a7 in SgSourceFile::build_C_and_Cxx_AST (this=this@entry=0x7f97ce258010, argv=std::vector of length 2, capacity 2 = {...}, inputCommandLine=std::vector of length 37, capacity 37 = {...}) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:5310
#15 0x00007f97d58d47e8 in SgSourceFile::buildAST (this=this@entry=0x7f97ce258010, argv=std::vector of length 2, capacity 2 = {...}, inputCommandLine=std::vector of length 37, capacity 37 = {...}) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:5858
#16 0x00007f97d58dc1f7 in SgFile::callFrontEnd (this=this@entry=0x7f97ce258010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:3024
#17 0x00007f97d58dc3be in SgSourceFile::callFrontEnd (this=0x7f97ce258010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2150
#18 0x00007f97d58d0a0c in SgFile::runFrontend (this=0x7f97ce258010, nextErrorCode=@0x7ffcd9880aac: 0) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:1620
#19 0x00007f97d58d49e8 in Rose::Frontend::RunSerial (project=project@entry=0x7f97ce38a010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:4493
#20 0x00007f97d58d4c8f in Rose::Frontend::Run (project=project@entry=0x7f97ce38a010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:4386
#21 0x00007f97d58d9816 in SgProject::RunFrontend (this=this@entry=0x7f97ce38a010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2222
#22 0x00007f97d58de2f3 in SgProject::parse (this=this@entry=0x7f97ce38a010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2347
#23 0x00007f97d58df39a in SgProject::parse (this=this@entry=0x7f97ce38a010, argv=std::vector of length 2, capacity 2 = {...}) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2043
#24 0x00007f97d5af6740 in SgProject::SgProject (this=0x7f97ce38a010, argv=std::vector of length 2, capacity 2 = {...}, frontendConstantFolding=<optimized out>) at Cxx_Grammar.C:28001
#25 0x00007f97d7a165f7 in frontend (argv=std::vector of length 2, capacity 2 = {...}, frontendConstantFolding=frontendConstantFolding@entry=false) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/roseSupport/utility_functions.C:484
#26 0x00007f97d7a168a5 in frontend (argc=argc@entry=2, argv=argv@entry=0x7ffcd9881288, frontendConstantFolding=frontendConstantFolding@entry=false) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/roseSupport/utility_functions.C:446
#27 0x000000000041372d in main (argc=2, argv=0x7ffcd9881288) at rosecheckers.C:155
(gdb) quit

The SIGSEGV is thrown within the EDG code (via the edg_main() call).

We don't have the slightest idea how to debug this. Any suggestions?

chunhualiao commented 5 years ago

Hi, the first step is to make sure your installed version of identityTranslator can parse the same input file.

qralston commented 5 years ago

Thanks for the tip.

identityTranslator throws SIGSEGV on the same input file, with a similar backtrace:

$ identityTranslator hello.C
Segmentation fault (core dumped)

$ gdb /usr/bin/identityTranslator core.29031
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/identityTranslator...Reading symbols from /usr/lib/debug/usr/bin/identityTranslator.debug...done.
done.

warning: core file may not match specified executable file.
[New LWP 29031]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `identityTranslator hello.C'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000000001 in ?? ()
Missing separate debuginfos, use: debuginfo-install boost-chrono-1.53.0-27.el7.x86_64 boost-date-time-1.53.0-27.el7.x86_64 boost-filesystem-1.53.0-27.el7.x86_64 boost-iostreams-1.53.0-27.el7.x86_64 boost-program-options-1.53.0-27.el7.x86_64 boost-random-1.53.0-27.el7.x86_64 boost-regex-1.53.0-27.el7.x86_64 boost-serialization-1.53.0-27.el7.x86_64 boost-system-1.53.0-27.el7.x86_64 boost-thread-1.53.0-27.el7.x86_64 boost-wave-1.53.0-27.el7.x86_64 bzip2-libs-1.0.6-13.el7.x86_64 glibc-2.17-260.el7.x86_64 libgcc-4.8.5-36.el7.x86_64 libicu-50.1.2-17.el7.x86_64 libstdc++-4.8.5-36.el7.x86_64 zlib-1.2.7-18.el7.x86_64
(gdb) bt
#0  0x0000000000000001 in ?? ()
#1  0x00007f45d8a2539f in isSgSymbol (inputDerivedClassPointer=0x28af480) at Cxx_Grammar.C:271859
#2  0x00007f45d9f3d9ad in EDG_ROSE_Translation::setupDeclarationScope (decl=0x7f45d004aef8) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:19315
#3  0x00007f45d9f41f96 in EDG_ROSE_Translation::convert_template_struct_primary (p=0x28af960, t=SgClassDeclaration::e_class, nonDefiningDecl=0x0, edg_template=0x28af230) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:20245
#4  0x00007f45d9f4ffaf in EDG_ROSE_Translation::parse_structlike (sse=..., p=0x28af960, t=SgClassDeclaration::e_class, forceTemplateClassDeclaration=true, edg_template=0x28af230) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:22942
#5  0x00007f45d9fc40c2 in EDG_ROSE_Translation::parse_template (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:57588
#6  0x00007f45d9fde6f1 in EDG_ROSE_Translation::parse_global_or_namespace_scope_entity (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:63773
#7  0x00007f45d9fd0685 in EDG_ROSE_Translation::convert_namespace (p=0x245d0f0, sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:61052
#8  0x00007f45d9f0157a in EDG_ROSE_Translation::parse_secondary_declaration (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:3267
#9  0x00007f45d9fde031 in EDG_ROSE_Translation::parse_global_or_namespace_scope_entity (sse=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:63594
#10 0x00007f45d9fe152b in EDG_ROSE_Translation::parse_global_scope (inputGlobalScope=0x7f45dc411120, sse=..., skip_ast_translation=false) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:64447
#11 0x00007f45d9fe2f69 in sage_back_end (sageFile=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:65307
#12 0x00007f45d9fe3dac in cfe_main (argc=37, argv=0x2436950, sageFile=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:65520
#13 0x00007f45d9fe3f09 in edg_main (argc=37, argv=0x2436950, sageFile=...) at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:65622
#14 0x00007f45d88ed8a7 in SgSourceFile::build_C_and_Cxx_AST (this=this@entry=0x7f45d106e010, argv=std::vector of length 2, capacity 2 = {...}, inputCommandLine=std::vector of length 37, capacity 37 = {...}) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:5310
#15 0x00007f45d88ee7e8 in SgSourceFile::buildAST (this=this@entry=0x7f45d106e010, argv=std::vector of length 2, capacity 2 = {...}, inputCommandLine=std::vector of length 37, capacity 37 = {...}) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:5858
#16 0x00007f45d88f61f7 in SgFile::callFrontEnd (this=this@entry=0x7f45d106e010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:3024
#17 0x00007f45d88f63be in SgSourceFile::callFrontEnd (this=0x7f45d106e010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2150
#18 0x00007f45d88eaa0c in SgFile::runFrontend (this=0x7f45d106e010, nextErrorCode=@0x7ffd5128e99c: 0) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:1620
#19 0x00007f45d88ee9e8 in Rose::Frontend::RunSerial (project=project@entry=0x7f45d11a0010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:4493
#20 0x00007f45d88eec8f in Rose::Frontend::Run (project=project@entry=0x7f45d11a0010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:4386
#21 0x00007f45d88f3816 in SgProject::RunFrontend (this=this@entry=0x7f45d11a0010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2222
#22 0x00007f45d88f82f3 in SgProject::parse (this=this@entry=0x7f45d11a0010) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2347
#23 0x00007f45d88f939a in SgProject::parse (this=this@entry=0x7f45d11a0010, argv=std::vector of length 2, capacity 2 = {...}) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/frontend/SageIII/sage_support/sage_support.cpp:2043
#24 0x00007f45d8b10740 in SgProject::SgProject (this=0x7f45d11a0010, argv=std::vector of length 2, capacity 2 = {...}, frontendConstantFolding=<optimized out>) at Cxx_Grammar.C:28001
#25 0x00007f45daa305f7 in frontend (argv=std::vector of length 2, capacity 2 = {...}, frontendConstantFolding=frontendConstantFolding@entry=false) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/roseSupport/utility_functions.C:484
#26 0x00007f45daa308a5 in frontend (argc=argc@entry=2, argv=argv@entry=0x7ffd5128f148, frontendConstantFolding=frontendConstantFolding@entry=false) at /usr/src/debug/rose-0.9.10.54/SOURCE/src/roseSupport/utility_functions.C:446
#27 0x0000000000405811 in main (argc=2, argv=0x7ffd5128f148) at /usr/src/debug/rose-0.9.10.54/SOURCE/exampleTranslators/documentedExamples/simpleTranslatorExamples/identityTranslator.C:12

I'm going to try recompiling ROSE with the RPM %optflags set to just:

-pipe -fexceptions -grecord-gcc-switches

When building with autoconf, ROSE adds these flags, no matter what I do:

-g -O2 -Wall

…so I can't easily test a build with no optimization enabled whatsoever.

chunhualiao commented 5 years ago

It seems like your build of ROSE has some problems. We have a cloud based daily build to quickly test things http://demo.rosecompiler.org . Your input file can be parsed correctly using identityTranslator there.

chunhualiao commented 5 years ago

I would suggest you to install ROSE using the official instructions instead of using rpm. Your customized installation method is not tested through our Jenkins regression test farm so it is uncertain if it will work.

qralston commented 5 years ago

Pruning the Red Hat specific options from %optflags did not help; identityTranslator still throws SIGSEGV on our example C++ program.

I am following the official build instructions closely (but not completely) within the rpm build process. If parts of ROSE are somehow being miscompiled, it's not obvious how that is occurring.

http://demo.rosecompiler.org is using ROSE 0.9.10.129, which differs from 0.9.10.54 by 761 commits (and more than half a million lines of diffs).

I will attempt to build 0.9.10.129 and see if the SIGSEGV problem is still present.

qralston commented 5 years ago

In attempting to build rose-develop (which is version 0.9.10.135 as of this morning), the EDG binary I need is:

http://edg-binaries.rosecompiler.org/roseBinaryEDG-4-9-x86_64-pc-linux-gnu-gnu-4.8-4.081db070cded12e24b672e0e91184583b2467d05.tar.gz

This binary distribution is not available. Which binary target should I download instead?

justintoo commented 5 years ago

It appears you are using GCC 4.8. Unfortunately, we no longer generate EDG binaries for this compiler. Please upgrade to one of the following GCC versions: 4.9, 5.1, 5.2, 5.3, 5.4, 6.1, or 6.3.

qralston commented 5 years ago

I've rebuilt ROSE 0.9.10.54, using the build instructions to the letter:

$ cd /tmp/SOURCE
$ ./build
$ cd /tmp/BUILD
$ /tmp/SOURCE/configure \
  --prefix=/tmp/rose \
  --enable-java=no \
  --enable-languages=c,c++ \
  --with-boost-libdir=/usr/lib64 \
  --with-boost=/usr \
  --without-java
$ make --jobs=8 install-core

…but the resulting defaultTranslator binary still throws SIGSEGV on C++ code:

$ /tmp/rose/bin/defaultTranslator hello.cpp 
Segmentation fault (core dumped)

If I use gdb to generate the stack backtrace, the SIGSEGV occurs in the exact same place:

#0  0x000000000238f940 in ?? ()
#1  0x00007f33285f355f in isSgSymbol (inputDerivedClassPointer=0x23aa200) at Cxx_Grammar.C:271859

I am using completely stock Red Hat Enterprise Linux 7 packages to perform the build:

autoconf-2.69-11.el7.noarch
automake-1.13.4-3.el7.noarch
bison-3.0.4-2.el7.x86_64
boost-1.53.0-27.el7.x86_64
byacc-1.9.20130304-3.el7.x86_64
doxygen-1.8.5-3.el7.x86_64
elfutils-libelf-devel-0.172-2.el7.x86_64
file-devel-5.11-35.el7.x86_64
flex-2.5.37-6.el7.x86_64
gcc-4.8.5-36.el7.x86_64
graphviz-2.30.1-21.el7.x86_64
libdwarf-devel-20130207-4.el7.x86_64
libgcrypt-devel-1.5.3-14.el7.x86_64
libtool-2.4.2-22.el7_3.x86_64
libxml2-devel-2.9.1-6.el7_2.3.x86_64
openssl-devel-1.0.2k-16.el7.x86_64
qt-devel-4.8.7-2.el7.x86_64
readline-devel-6.2-10.el7.x86_64
redhat-lsb-core-4.1-27.el7.x86_64
sqlite-devel-3.7.17-8.el7.x86_64
texlive-pdftex-bin-svn27321.0-43.20130427_r30134.el7.x86_64

Unfortunately, the most likely explanation at this point is that the current production version of ROSE (0.9.10.54) no longer builds correctly on RHEL7 using stock RHEL7-provided packages.

@justintoo, in terms of using a more recent version of gcc, Red Hat provides these additional gcc versions via Red Hat Software Collections (RHSCL):

devtoolset-3-gcc (gcc version 4.9.2)
devtoolset-4-gcc (gcc version 5.3.1)
devtoolset-6-gcc (gcc version 6.3.1)

All of these match your version suggestions (4.9, 5.1, 5.2, 5.3, 5.4, 6.1, or 6.3). Should I prefer one version over the rest? How many does the ROSE team routinely test? Have you specifically tested the RHSCL gcc packages, or have you tested more recent gcc versions on RHEL7 by manually downloading and building different gcc versions, outside of RHSCL?

Finally, should I stick with attempting to build production ROSE (version 0.9.10.54), or should I be building from the rosel-develop repository instead?

Thanks.

qralston commented 5 years ago

The more I look at this, the more I suspect the problem is that ROSE simply does not build correctly on stock RHEL7.

The rest of this comment is a recipe for building ROSE within a mock chroot() jail, using only stock RHEL7 packages. This will ensure that artifacts of your build system do not effect the build. If my guess is correct, the resulting build will fail in exactly the same way as I am seeing.

Would you be willing to test this?

You will need a RHEL7 host with Internet connectivity, configured to use the EPEL7 repository. It should be capable of building ROSE in terms of memory and CPU power. It will need about 20GiB of free disk space in the filesystem that contains /var/lib, and about 6GiB of free disk space in the filesystem that contains /var/cache.

Here's the recipe.

As root, install the mock package from the EPEL7 repository:

$ yum install mock

Add the username of the account you will use to perform the build (which should not be the root user) to the mock group. If you are currently logged in as that user, logout and back in, or else login with a new session.

As your regular user, set your umask appropriately, then clone the ROSE Git repository:

$ umask 022
$ git clone https://github.com/rose-compiler/rose.git

Download the binary EDG distribution you will need:

$ wget http://www.rosecompiler.org/edg_binaries/roseBinaryEDG-4-9-x86_64-pc-linux-gnu-gnu-4.8-4.82daf656b47602afa41dc38d5a30fa107fbc1e7b.tar.gz

Now, initialize the mock chroot:

$ mock -r epel-7-x86_64 --init

Install the additional packages that ROSE needs in order to build:

$ mock -r epel-7-x86_64 --install wget git gcc gcc-c++ automake autoconf libtool libtool-ltdl-devel byacc bison bison-devel flex boost-devel ghostscript

Copy the ROSE git repository and the EDG binary distribution into the chroot:

$ mock -r epel-7-x86_64 --copyin rose builddir
$ mock -r epel-7-x86_64 --copyin roseBinaryEDG-4-9-x86_64-pc-linux-gnu-gnu-4.8-4.82daf656b47602afa41dc38d5a30fa107fbc1e7b.tar.gz builddir

Now, initialize a shell inside of the mock chroot:

$ mock -r epel-7-x86_64 --shell

From this point forward, we will be running all commands within the mock chroot.

First, su to the mockbuild user:

$ su mockbuild

Then cd to the /builddir directory:

$ cd builddir

We can see that the files/trees we copied into the chroot are here:

$ ls
build  rose  roseBinaryEDG-4-9-x86_64-pc-linux-gnu-gnu-4.8-4.82daf656b47602afa41dc38d5a30fa107fbc1e7b.tar.gz

Change directory to the rose directory (the Git repository) and prepare for building with the GNU toolchain:

$ cd rose
$ ( ./build 1>../build.log 2>&1; echo return code was $? )
return code was 0

Return to the builddir directory, create the BUILD directory, cd into it, and run configure:

$ cd ..
$ mkdir BUILD
$ cd BUILD
$ ( /builddir/rose/configure --prefix=/tmp/rose --enable-java=no --enable-languages=c,c++ --with-boost-libdir=/usr/lib64 --with-boost=/usr --without-java 1>../configure.log 2>&1; echo return code was $? )
return code was 0

Mock deliberately blocks the chroot from opening network connections, to ensure that the build process does not download things from the Internet as part of its build, which would make the build not strictly reproducible. Since this is exactly what ROSE wants to do, we need to copy the EDG binary distribution that we already downloaded and installed into the chroot to the correct spot:

$ cp -p ../roseBinaryEDG-4-9-x86_64-pc-linux-gnu-gnu-4.8-4.82daf656b47602afa41dc38d5a30fa107fbc1e7b.tar.gz src/frontend/CxxFrontend/

Now, build the install-rose-library target:

$ ( make install-rose-library 1>../make-install-rose-library.log 2>&1; echo return code was $? )
return code was 0

If you want to watch the progress, suspend the make command, place it into the background, and "tail -f" the ../make-install-rose-library.log file.

After the build and install of librose completes, we need to build defaultTranslator:

$ cd exampleTranslators/defaultTranslator
$ ( make defaultTranslator; echo return code was $? )
  CXX      defaultTranslator.o
  CXXLD    defaultTranslator
return code was 0

Create the sample C and C++ programs:

$ cat >hello.c <<EOF
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64

#include <stdio.h>

int main (int argc, char *argv[]) {
  fprintf (stdout, "Hello, world!\n");
  return (0);
}
EOF

$ cat >hello.cpp <<EOF
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
EOF

Translating hello.c will work:

$ ( ./defaultTranslator hello.c; echo return code was $? )
return code was 0

$ cat rose_hello.c; echo EOF
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>

int main(int argc,char *argv[])
{
  fprintf(stdout,"Hello, world!\n");
  return 0;
}
EOF

But translating hello.cpp will fail:

$ rm rose_hello.c hello.o a.out
$ ./defaultTranslator hello.cpp 
Segmentation fault (core dumped)

The backtrace will show that the SIGSEGV occurred in the EDG code:

$ echo bt | gdb .libs/defaultTranslator core.*
#0  0x00000000015c7c40 in ?? ()
#1  0x00007f67660444ff in isSgSymbol (inputDerivedClassPointer=0x15e2500) at Cxx_Grammar.C:271859
#2  0x00007f67674cf09f in EDG_ROSE_Translation::setupDeclarationScope (decl=0x7f675eef9ef8)
    at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:19315
#3  0x00007f67674d3688 in EDG_ROSE_Translation::convert_template_struct_primary (p=0x15e29e0, t=SgClassDeclaration::e_class, 
    nonDefiningDecl=0x0, edg_template=0x15e22b0)
    at /export/tmp.rose-mgr/jenkins/edg4x/workspace/development-edg-binary-RMC/COMPILER/gcc-4.8.4-default/EDGVERSION/4.9/src/frontend/CxxFrontend/EDG/edgRose/edgRose.C:20245

You can exit out of the su shell and then the mock chroot shell. You can then reenter the chroot if you wish:

$ mock -r epel-7-x86_64 --shell

Or you can simply remove the chroot:

$ mock -r epel-7-x86_64 --clean

If you --clean the chroot, you will need to use --init to recreate it.

tristanvdb commented 5 years ago

The original segfault is probably fixed (it was located in frontend work that was going on at the begining of the year). When it comes to the support of stock RHEL 7, it is not possible as ROSE requires GCC 4.9 (RHEL7 comes with 4.8). We actually recommend to use GCC 6+.