xiangzhai / dragonegg

DragonEgg has been migrated to GCC 8 and LLVM 6 but also able to work for GCC 4.8 and LLVM 3.3
https://gcc.gnu.org/ml/gcc/2017-08/msg00245.html
GNU General Public License v2.0
18 stars 6 forks source link

dragonegg.so cannot load plugin somehow #36

Open eminarcissus opened 5 years ago

eminarcissus commented 5 years ago

Hi,

Thanks very much to make this project continued til now :) I'm now trying to compile it on OSX with GCC6.4 and llvm-r311142. I've checkout to the c1b5b35 commit which I believe is the repo which should worlks with GCC6 and llvm this version.

Currently the code is compiling, and successfully linked. But somehow it yields out this error when I tried to do a fplugin compile.

gcc-6 a.c -S -O1 -o - -fplugin=./dragonegg/dragonegg.so -L/usr/local/llvm-6 cc1: error: cannot load plugin ./dragonegg/dragonegg.so dlopen(./dragonegg/dragonegg.so, 10): Symbol not found: _C_alloca Referenced from: ./dragonegg/dragonegg.so Expected in: flat namespace in ./dragonegg/dragonegg.so

Any hints would be real appreciated :) Now I'm trying to compile some fortran codes with dragonegg, so I have to keep a backup system for years ago. It would be really helpful if this does working here :)

Attached is gcc6 compile info.

Using built-in specs. COLLECT_GCC=gcc-6 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc@6/6.4.0/libexec/gcc/x86_64-apple-darwin18/6.4.0/lto-wrapper Target: x86_64-apple-darwin18 Configured with: ../configure --build=x86_64-apple-darwin18 --prefix=/usr/local/Cellar/gcc@6/6.4.0 --libdir=/usr/local/Cellar/gcc@6/6.4.0/lib/gcc/6 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 6.4.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --enable-plugin --enable-lto Thread model: posix gcc version 6.4.0 (Homebrew GCC 6.4.0)

Thx very much.

xiangzhai commented 5 years ago

Hi @eminarcissus

Thanks for your PR!

Already reported https://github.com/xiangzhai/dragonegg/issues/23

Workaround for Linux https://github.com/xiangzhai/dragonegg/commit/2736f2a735244ca3ab029ac06456140c4217e6f5

So you could simply workaround it for __unix__.

Cheers, Leslie Zhai

eminarcissus commented 5 years ago

Wow, thx very much. Sorry didn't noticed that issue That did works out, but some few other issues looks like here. cc1: fatal error: plugin ./dragonegg/dragonegg.so is not licensed under a GPL-compatible license dlsym(0x1439039e0, plugin_is_GPL_compatible): symbol not found

I will check where's the problem here :)

xiangzhai commented 5 years ago

You could try to comment this line https://github.com/xiangzhai/dragonegg/blob/master/src/Backend.cpp#L1970

eminarcissus commented 5 years ago

quite weird, no matter if I define it as 1 or 0, or just comment out this out, all comes up with the same error. looks like is gcc itself trying to check for this value when loading a plugin?

xiangzhai commented 5 years ago

https://github.com/gcc-mirror/gcc/blob/master/gcc/plugin.c#L712

so workaround might be:

int plugin_is_GPL_compatible __attribute__((visibility("default"))) { return 0; }
eminarcissus commented 5 years ago

looks like the problem roots from CPP naming conventions. this is the result after I decompile the so file. symbol plugin_is_GPL_compatible is being compiled to _plugin_is_GPL_compatible as global variable. Didn't confirmed yet.

xiangzhai commented 5 years ago

You could just comment the Check the plugin license https://github.com/gcc-mirror/gcc/blob/master/gcc/plugin.c#L711

And rebuild gcc https://github.com/xiangzhai/dragonegg/wiki/GGC#fedora-25

eminarcissus commented 5 years ago

yeah... that probably works out, will try it now 👍

eminarcissus commented 5 years ago

quite devastating problems here looks like. after comment out this line now GPL check works out but plugin_init not found. dlsym(0x141f05980, plugin_init): symbol not found I've tried to remove the leading underscore but still no help(by adding asm("plugin_init") when defining the function).

Also double checked dragonegg.so compiled with GCC4.8 and llvm3.5. Looks like both GPL license check and plugin_init are pre underscored. So I believe this might be some other problems here. Don't know how to start on debuging this kind of problem...

xiangzhai commented 5 years ago

plugin_init could not be commented :)

What about this commit? https://github.com/xiangzhai/dragonegg/commit/d332eefb270555b2b46919171ab59073d66ea4a3

eminarcissus commented 5 years ago

didn't work out. Also that commit looks like is a fix for GCC 4.9.3? The error itself looks really obscure, 000000000000c3d3 l F TEXT,text __ZL13version_checkP18plugin_gcc_version 000000000000c3f4 l F TEXT,text _plugin_init 000000000000d1a4 lw F TEXT,text __ZN4llvm4castINS_8ConstantEKNS_5ValueEEENS_10cast_rettyIT_PT0_E8rettypeES7

and plugin.c just calling dlsym(handle,"plugin_init"), so it shouldn't be a error telling symbol not found, quite confusing.

xiangzhai commented 5 years ago

You could report the bug to GCC if failed to run testsuite on your Mac:

  1. build your GCC-6.4 https://github.com/xiangzhai/dragonegg/wiki/GGC#fedora-25
  2. install dejagnu https://gcc.gnu.org/install/test.html
  3. run testsuite, I use gcc-7-branch to test:
$ make check-gcc RUNTESTFLAGS="plugin.exp"
make[1]: Entering directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
rm -rf testsuite/gcc-parallel
make[2]: Entering directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
(rootme=`${PWDCMD-pwd}`; export rootme; \
srcdir=`cd ../../gcc; ${PWDCMD-pwd}` ; export srcdir ; \
if [ -n "" ] \
   && [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] \
   && [ -f testsuite/gcc-parallel/finished ]; then \
  rm -rf testsuite/gcc; \
else \
  cd testsuite/gcc; \
  rm -f tmp-site.exp; \
  sed '/set tmpdir/ s|testsuite$|testsuite/gcc|' \
    < ../../site.exp > tmp-site.exp; \
  /bin/bash ${srcdir}/../move-if-change tmp-site.exp site.exp; \
  EXPECT=`if [ -f ${rootme}/../expect/expect ] ; then echo ${rootme}/../expect/expect ; else echo expect ; fi` ; export EXPECT ; \
  if [ -f ${rootme}/../expect/expect ] ; then  \
    TCL_LIBRARY=`cd .. ; cd ${srcdir}/../tcl/library ; ${PWDCMD-pwd}` ; \
    export TCL_LIBRARY ; \
  fi ; \
  `if [ -f ${srcdir}/../dejagnu/runtest ] ; then echo ${srcdir}/../dejagnu/runtest ; else echo runtest; fi` --tool gcc plugin.exp; \
  if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] ; then \
    touch ${rootme}/testsuite/gcc-parallel/finished; \
  fi ; \
fi )
Test run by loongson on Wed Jun 26 17:20:52 2019
Native configuration is x86_64-pc-linux-gnu

        === gcc tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /disk/zhaixiang/gcc-7-branch/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /disk/zhaixiang/gcc-7-branch/gcc/testsuite/gcc.dg/plugin/plugin.exp ...

        === gcc Summary ===

# of expected passes        340
# of expected failures      1
/disk/zhaixiang/gcc-7-branch/build/gcc/xgcc  version 7.4.1 20190620 (GCC) 

make[2]: Leaving directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
rm -rf testsuite/g++-parallel
make[2]: Entering directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
(rootme=`${PWDCMD-pwd}`; export rootme; \
srcdir=`cd ../../gcc; ${PWDCMD-pwd}` ; export srcdir ; \
if [ -n "" ] \
   && [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] \
   && [ -f testsuite/g++-parallel/finished ]; then \
  rm -rf testsuite/g++; \
else \
  cd testsuite/g++; \
  rm -f tmp-site.exp; \
  sed '/set tmpdir/ s|testsuite$|testsuite/g++|' \
    < ../../site.exp > tmp-site.exp; \
  /bin/bash ${srcdir}/../move-if-change tmp-site.exp site.exp; \
  EXPECT=`if [ -f ${rootme}/../expect/expect ] ; then echo ${rootme}/../expect/expect ; else echo expect ; fi` ; export EXPECT ; \
  if [ -f ${rootme}/../expect/expect ] ; then  \
    TCL_LIBRARY=`cd .. ; cd ${srcdir}/../tcl/library ; ${PWDCMD-pwd}` ; \
    export TCL_LIBRARY ; \
  fi ; \
  `if [ -f ${srcdir}/../dejagnu/runtest ] ; then echo ${srcdir}/../dejagnu/runtest ; else echo runtest; fi` --tool g++ plugin.exp; \
  if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] ; then \
    touch ${rootme}/testsuite/g++-parallel/finished; \
  fi ; \
fi )
Test run by loongson on Wed Jun 26 17:20:57 2019
Native configuration is x86_64-pc-linux-gnu

        === g++ tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /disk/zhaixiang/gcc-7-branch/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /disk/zhaixiang/gcc-7-branch/gcc/testsuite/g++.dg/plugin/plugin.exp ...

        === g++ Summary ===

# of expected passes        268
# of expected failures      2
/disk/zhaixiang/gcc-7-branch/build/gcc/xg++  version 7.4.1 20190620 (GCC) 

make[2]: Leaving directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
rm -rf testsuite/gfortran-parallel
make[2]: Entering directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
(rootme=`${PWDCMD-pwd}`; export rootme; \
srcdir=`cd ../../gcc; ${PWDCMD-pwd}` ; export srcdir ; \
if [ -n "" ] \
   && [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] \
   && [ -f testsuite/gfortran-parallel/finished ]; then \
  rm -rf testsuite/gfortran; \
else \
  cd testsuite/gfortran; \
  rm -f tmp-site.exp; \
  sed '/set tmpdir/ s|testsuite$|testsuite/gfortran|' \
    < ../../site.exp > tmp-site.exp; \
  /bin/bash ${srcdir}/../move-if-change tmp-site.exp site.exp; \
  EXPECT=`if [ -f ${rootme}/../expect/expect ] ; then echo ${rootme}/../expect/expect ; else echo expect ; fi` ; export EXPECT ; \
  if [ -f ${rootme}/../expect/expect ] ; then  \
    TCL_LIBRARY=`cd .. ; cd ${srcdir}/../tcl/library ; ${PWDCMD-pwd}` ; \
    export TCL_LIBRARY ; \
  fi ; \
  `if [ -f ${srcdir}/../dejagnu/runtest ] ; then echo ${srcdir}/../dejagnu/runtest ; else echo runtest; fi` --tool gfortran plugin.exp; \
  if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] ; then \
    touch ${rootme}/testsuite/gfortran-parallel/finished; \
  fi ; \
fi )
Test run by loongson on Wed Jun 26 17:21:00 2019
Native configuration is x86_64-pc-linux-gnu

        === gfortran tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /disk/zhaixiang/gcc-7-branch/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.

        === gfortran Summary ===

/disk/zhaixiang/gcc-7-branch/build/gcc/gfortran  version 7.4.1 20190620 (GCC) 

make[2]: Leaving directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
rm -rf testsuite/go-parallel
make[2]: Entering directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
(rootme=`${PWDCMD-pwd}`; export rootme; \
srcdir=`cd ../../gcc; ${PWDCMD-pwd}` ; export srcdir ; \
if [ -n "" ] \
   && [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] \
   && [ -f testsuite/go-parallel/finished ]; then \
  rm -rf testsuite/go; \
else \
  cd testsuite/go; \
  rm -f tmp-site.exp; \
  sed '/set tmpdir/ s|testsuite$|testsuite/go|' \
    < ../../site.exp > tmp-site.exp; \
  /bin/bash ${srcdir}/../move-if-change tmp-site.exp site.exp; \
  EXPECT=`if [ -f ${rootme}/../expect/expect ] ; then echo ${rootme}/../expect/expect ; else echo expect ; fi` ; export EXPECT ; \
  if [ -f ${rootme}/../expect/expect ] ; then  \
    TCL_LIBRARY=`cd .. ; cd ${srcdir}/../tcl/library ; ${PWDCMD-pwd}` ; \
    export TCL_LIBRARY ; \
  fi ; \
  `if [ -f ${srcdir}/../dejagnu/runtest ] ; then echo ${srcdir}/../dejagnu/runtest ; else echo runtest; fi` --tool go plugin.exp; \
  if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] ; then \
    touch ${rootme}/testsuite/go-parallel/finished; \
  fi ; \
fi )
Test run by loongson on Wed Jun 26 17:21:00 2019
Native configuration is x86_64-pc-linux-gnu

        === go tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /disk/zhaixiang/gcc-7-branch/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.

        === go Summary ===

/disk/zhaixiang/gcc-7-branch/build/gcc/gccgo  version 7.4.1 20190620 (GCC) 

make[2]: Leaving directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
rm -rf testsuite/objc-parallel
make[2]: Entering directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
(rootme=`${PWDCMD-pwd}`; export rootme; \
srcdir=`cd ../../gcc; ${PWDCMD-pwd}` ; export srcdir ; \
if [ -n "" ] \
   && [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] \
   && [ -f testsuite/objc-parallel/finished ]; then \
  rm -rf testsuite/objc; \
else \
  cd testsuite/objc; \
  rm -f tmp-site.exp; \
  sed '/set tmpdir/ s|testsuite$|testsuite/objc|' \
    < ../../site.exp > tmp-site.exp; \
  /bin/bash ${srcdir}/../move-if-change tmp-site.exp site.exp; \
  EXPECT=`if [ -f ${rootme}/../expect/expect ] ; then echo ${rootme}/../expect/expect ; else echo expect ; fi` ; export EXPECT ; \
  if [ -f ${rootme}/../expect/expect ] ; then  \
    TCL_LIBRARY=`cd .. ; cd ${srcdir}/../tcl/library ; ${PWDCMD-pwd}` ; \
    export TCL_LIBRARY ; \
  fi ; \
  `if [ -f ${srcdir}/../dejagnu/runtest ] ; then echo ${srcdir}/../dejagnu/runtest ; else echo runtest; fi` --tool objc plugin.exp; \
  if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ] ; then \
    touch ${rootme}/testsuite/objc-parallel/finished; \
  fi ; \
fi )
Test run by loongson on Wed Jun 26 17:21:01 2019
Native configuration is x86_64-pc-linux-gnu

        === objc tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /disk/zhaixiang/gcc-7-branch/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /disk/zhaixiang/gcc-7-branch/gcc/testsuite/objc.dg/plugin/plugin.exp ...

        === objc Summary ===

# of expected passes        16
/disk/zhaixiang/gcc-7-branch/build/gcc/xgcc  version 7.4.1 20190620 (GCC) 

make[2]: Leaving directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
test -d plugin || mkdir plugin
test -d testsuite || mkdir testsuite
test -d testsuite/obj-c++ || mkdir testsuite/obj-c++
(rootme=`${PWDCMD-pwd}`; export rootme; \
srcdir=`cd ../../gcc; ${PWDCMD-pwd}` ; export srcdir ; \
cd testsuite/obj-c++; \
rm -f tmp-site.exp; \
sed '/set tmpdir/ s|testsuite$|testsuite/obj-c++|' \
    < ../../site.exp > tmp-site.exp; \
/bin/bash ${srcdir}/../move-if-change tmp-site.exp site.exp; \
EXPECT=expect ; export EXPECT ; \
if [ -f ${rootme}/../expect/expect ] ; then  \
   TCL_LIBRARY=`cd .. ; cd ${srcdir}/../tcl/library ; ${PWDCMD-pwd}` ; \
    export TCL_LIBRARY ; fi ; \
runtest --tool obj-c++ plugin.exp)
Test run by loongson on Wed Jun 26 17:21:01 2019
Native configuration is x86_64-pc-linux-gnu

        === obj-c++ tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /disk/zhaixiang/gcc-7-branch/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /disk/zhaixiang/gcc-7-branch/gcc/testsuite/obj-c++.dg/plugin/plugin.exp ...

        === obj-c++ Summary ===

# of expected passes        16
/disk/zhaixiang/gcc-7-branch/build/gcc/xg++  version 7.4.1 20190620 (GCC) 

make[1]: Leaving directory '/disk/zhaixiang/gcc-7-branch/build/gcc'
eminarcissus commented 5 years ago

Will try that, currently I'm retreating back to old version dragonegg to get the job done first :(

xiangzhai commented 5 years ago

Hi @eminarcissus

You could try @my-HenryS `s workaround https://github.com/my-HenryS/dragonegg/commit/3252c914c2741147fc52002bbda78d6f432bcfc2#diff-b67911656ef5d18c4ae36cb6741b7965

Cheers, Leslie Zhai

eminarcissus commented 5 years ago

Thx, gotta give it a shot, being stucked at gcc test for a while lol :)

eminarcissus commented 5 years ago

Quite weird, after patch Henry's version it is not even building, I saw some header files change which like Target -> CodeGen which is not exists with llvm-6.0, Also some errors like this

In function 'void CreateTargetMachine(const string&)': /Users/misuzi/developing/c/mod_dragonegg/dragonegg/src/Backend.cpp:695:36: error: base operand of '->' has non-pointer type 'const llvm::DataLayout' assert(TheModule->getDataLayout()->isBigEndian() == BYTES_BIG_ENDIAN);

xiangzhai commented 5 years ago

just apply his patch for Makefile https://github.com/my-HenryS/dragonegg/commit/3252c914c2741147fc52002bbda78d6f432bcfc2#diff-b67911656ef5d18c4ae36cb6741b7965 but do not change other source files.

eminarcissus commented 5 years ago

Quite interesting, now it builds, but testing the plugin emits a crash like this.

Event | Plugins PLUGIN_FINISH_UNIT | dragonegg PLUGIN_FINISH | dragonegg PLUGIN_START_UNIT | dragonegg PLUGIN_ALL_IPA_PASSES_END | dragonegg wc.c:8:5: internal compiler error: Segmentation fault: 11 int main(int argc, char** argv) { ^~~~

WARNING there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins. Event | Plugins PLUGIN_FINISH_UNIT | dragonegg PLUGIN_FINISH | dragonegg PLUGIN_START_UNIT | dragonegg PLUGIN_ALL_IPA_PASSES_END | dragonegg wc.c:8:5: internal compiler error: Abort trap: 6 gcc-6: internal compiler error: Abort trap: 6 (program cc1)

xiangzhai commented 5 years ago

Could you show me the command line? And then it is able to see what gdb say like this https://github.com/xiangzhai/dragonegg/issues/37

eminarcissus commented 5 years ago

gcc-6 wc.c -S -O1 -o - -fplugin=$PWD/dragonegg/dragonegg.so wc.c: In function 'main': wc.c:22:17: warning: implicit declaration of function 'read' [-Wimplicit-function-declaration] while ((r = read(fd, BUFFER, BUFFER_SIZE)) > 0) { ^~~~ wc.c:30:5: warning: implicit declaration of function 'close' [-Wimplicit-function-declaration] close(fd); ^~~~~ WARNING there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins. Event | Plugins PLUGIN_FINISH_UNIT | dragonegg PLUGIN_FINISH | dragonegg PLUGIN_START_UNIT | dragonegg PLUGIN_ALL_IPA_PASSES_END | dragonegg wc.c:8:5: internal compiler error: Segmentation fault: 11 int main(int argc, char** argv) { ^~~~

WARNING there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins. Event | Plugins PLUGIN_FINISH_UNIT | dragonegg PLUGIN_FINISH | dragonegg PLUGIN_START_UNIT | dragonegg PLUGIN_ALL_IPA_PASSES_END | dragonegg wc.c:8:5: internal compiler error: Abort trap: 6 gcc-6: internal compiler error: Abort trap: 6 (program cc1) Please submit a full bug report, with preprocessed source if appropriate. See https://github.com/Homebrew/homebrew-core/issues for instructions.

wc.c is a snip of quite simple test c codes.

xiangzhai commented 5 years ago
gcc-6 -fplugin=$PWD/dragonegg/dragonegg.so \
          -fplugin-arg-dragonegg-debug-pass-arguments \
          -ftime-report \
          -fplugin-arg-dragonegg-enable-gcc-optzns \
          -fplugin-arg-dragonegg-emit-ir \
          -O1  \
          -S \
          wc.c \
          -o $PWD/wc.c.ll \
          -wrapper gdb,--args

And see what gdb say.

eminarcissus commented 5 years ago

misuzi@TimnoMBP-2 ~/developing/c $ gcc-6 -fplugin=$PWD/dragonegg/dragonegg.so \ -fplugin-arg-dragonegg-debug-pass-arguments \ -ftime-report \ -fplugin-arg-dragonegg-enable-gcc-optzns \ -fplugin-arg-dragonegg-emit-ir \ -O1 \ -S \ wc.c \ -o $PWD/wc.c.ll \ -wrapper gdb,--args GNU gdb (GDB) 8.2.1 Copyright (C) 2018 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-apple-darwin18.2.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/.

For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /usr/local/Cellar/gcc@6/6.4.0/libexec/gcc/x86_64-apple-darwin18/6.4.0/cc1...done. gdb$

quite weird, nothing output looks like

eminarcissus commented 5 years ago

(gdb) r Starting program: /usr/local/Cellar/gcc@6/6.4.0/libexec/gcc/x86_64-apple-darwin18/6.4.0/cc1 -quiet -iplugindir=/usr/local/Cellar/gcc@6/6.4.0/lib/gcc/6/gcc/x86_64-apple-darwin18/6.4.0/plugin -DDYNAMIC wc.c -iplugindir=/usr/local/Cellar/gcc@6/6.4.0/lib/gcc/6/gcc/x86_64-apple-darwin18/6.4.0/plugin -fPIC -quiet -dumpbase wc.c -mmacosx-version-min=10.14.6 -mtune=core2 -auxbase-strip /Users/misuzi/developing/c/wc.c.ll -O1 -fplugin=/Users/misuzi/developing/c/dragonegg/dragonegg.so -fplugin-arg-dragonegg-debug-pass-arguments -ftime-report -fplugin-arg-dragonegg-enable-gcc-optzns -fplugin-arg-dragonegg-emit-ir -o /Users/misuzi/developing/c/wc.c.ll [New Thread 0xd03 of process 5688] During startup program terminated with signal ?, Unknown signal.

Running again with roots permission, I've seen some error outputs somehow

Assertion failed: (getValPtr() && getValPtr()->HasValueHandle && "Pointer doesn't have a use list!"), function RemoveFromUseList, file /Users/misuzi/developing/c/llvm/lib/IR/Value.cpp, line 800.

xiangzhai commented 5 years ago

Then bt

eminarcissus commented 5 years ago

Seems like gdb have some problem, will sort out that first, apple have switched. to lldb, since 3 years ago gdb have being somewhat quite unstable here.

eminarcissus commented 5 years ago

successfully get a traceback here.

Assertion failed: (getValPtr() && getValPtr()->HasValueHandle && "Pointer doesn't have a use list!"), function RemoveFromUseList, file /Users/misuzi/developing/c/llvm/lib/IR/Value.cpp, line 800.

Thread 2 received signal SIGABRT, Aborted. --------------------------------------------------------------------------[regs] EAX: 0x00000000 EBX: 0x41D265C0 ECX: 0xEFBFDB78 EDX: 0x00000000 o d I t s z a P c ESI: 0x00000006 EDI: 0x00000307 EBP: 0xEFBFDBB0 ESP: 0xEFBFDB78 EIP: 0xError while running hook_stop: Value can't be converted to integer. 0x00007fff632cf2c6 in ?? () from /usr/lib/system/libsystem_kernel.dylib gdb$ gdb$ bt

0 0x00007fff632cf2c6 in ?? () from /usr/lib/system/libsystem_kernel.dylib

1 0x00007fff6338abf1 in pthread_kill () from /usr/lib/system/libsystem_pthread.dylib

2 0x00007fff632396a6 in abort () from /usr/lib/system/libsystem_c.dylib

3 0x00007ffeefbfdbe0 in ?? ()

4 0x00007fffffffffdf in ?? ()

5 0xffffffffefbfdbf0 in ?? ()

6 0x00000001463fc560 in llvm::DenseMapIterator<llvm::Value, llvm::ValueHandleBase, llvm::DenseMapInfo<llvm::Value>, llvm::detail::DenseMapPair<llvm::Value, llvm::ValueHandleBase*>, false>::operator++()::func () from /Users/misuzi/developing/c/dragonegg/dragonegg.so

7 0x00007ffeefbfdc20 in ?? ()

8 0x00007fff6320220d in __assert_rtn () from /usr/lib/system/libsystem_c.dylib

Backtrace stopped: frame did not save the PC

eminarcissus commented 5 years ago

A changed file to compile, different error though

Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file /Users/misuzi/developing/c/llvm/include/llvm/Support/Casting.h, line 92.

Thread 2 received signal SIGABRT, Aborted. --------------------------------------------------------------------------[regs] EAX: 0x00000000 EBX: 0x41D265C0 ECX: 0xEFBFDBB8 EDX: 0x00000000 o d I t s z a P c ESI: 0x00000006 EDI: 0x00000307 EBP: 0xEFBFDBF0 ESP: 0xEFBFDBB8 EIP: 0xError while running hook_stop: Value can't be converted to integer. 0x00007fff632cf2c6 in ?? () from /usr/lib/system/libsystem_kernel.dylib gdb$ bt

0 0x00007fff632cf2c6 in ?? () from /usr/lib/system/libsystem_kernel.dylib

1 0x00007fff6338abf1 in pthread_kill () from /usr/lib/system/libsystem_pthread.dylib

2 0x00007fff632396a6 in abort () from /usr/lib/system/libsystem_c.dylib

3 0x00007ffeefbfdc20 in ?? ()

4 0x00007fffffffffdf in ?? ()

5 0xffffffff00000000 in ?? ()

6 0x00000001453a0d5a in llvm::TrackingVH::getValPtr() const::func () from /Users/misuzi/developing/c/dragonegg/dragonegg.so

7 0x00007ffeefbfdc60 in ?? ()

8 0x00007fff6320220d in __assert_rtn () from /usr/lib/system/libsystem_c.dylib

Backtrace stopped: frame did not save the PC

xiangzhai commented 5 years ago

please recompile dragonegg.so:

$ make clean
$ make DRAGONEGG_DEBUG=1

The backtrace information is not detailed.

eminarcissus commented 5 years ago

test.c:6:1: warning: return type defaults to 'int' [-Wimplicit-int] main() ^~~~ DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2246: llvm_emit_globals DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 826: InitializeBackend: x86_64-apple-darwin18 DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 691: CreateTargetMachine: triple: x86_64-apple-darwin18 cpu: x86-64 feature: +64bit,-3dnow,-3dnowa,-aes,-avx,-cx16,-fma,-fma4,+mmx,-popcnt,-rdrnd,+sse,+sse2,+sse3,-sse4.1,-sse4.2,-sse4a,-ssse3 DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 754: CreateModule: e-m:o-i64:64-f80:128-n8:16:32:64-S128 DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2181: emit_file_scope_asms DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2206: emit_cgraph_weakrefs DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2221: emit_varpool_weakrefs

Thread 2 received signal SIGSEGV, Segmentation fault. --------------------------------------------------------------------------[regs] EAX: 0x00000001 EBX: 0x42825020 ECX: 0x00000010 EDX: 0x4202CDE8 o d I t s Z a P c ESI: 0x4202CDE8 EDI: 0x42835258 EBP: 0xEFBFDA60 ESP: 0xEFBFDA30 EIP: 0xError while running hook_stop: Value can't be converted to integer. 0x0000000144f47ee6 in llvm::ValueHandleBase::RemoveFromUseList (this=0x142835258) at /Users/misuzi/developing/c/llvm/lib/IR/Value.cpp:799 799 assert(getValPtr() && getValPtr()->HasValueHandle && gdb$ bt

0 0x0000000144f47ee6 in llvm::ValueHandleBase::RemoveFromUseList (this=0x142835258) at /Users/misuzi/developing/c/llvm/lib/IR/Value.cpp:799

1 0x0000000143826645 in llvm::ValueHandleBase::operator= (this=<error reading variable: Could not find the frame base for "llvm::ValueHandleBase::operator=(llvm::Value)".>, RHS=<error reading variable: Could not find the frame base for "llvm::ValueHandleBase::operator=(llvm::Value)".>) at /usr/local/llvm-6/include/llvm/IR/ValueHandle.h:74

2 0x0000000144680f37 in llvm::AssertingVH::setRawValPtr (this=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setRawValPtr(llvm::Value)".>, P=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setRawValPtr(llvm::Value)".>) at /Users/misuzi/developing/c/llvm/include/llvm/IR/ValueHandle.h:247

3 0x000000014461c13a in llvm::AssertingVH::setValPtr (this=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setValPtr(llvm::Value)".>, P=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setValPtr(llvm::Value)".>) at /Users/misuzi/developing/c/llvm/include/llvm/IR/ValueHandle.h:258

4 0x0000000143850e25 in llvm::AssertingVH::operator= (this=<error reading variable: Could not find the frame base for "llvm::AssertingVH::operator=(llvm::Value)".>, RHS=<error reading variable: Could not find the frame base for "llvm::AssertingVH::operator=(llvm::Value)".>) at /usr/local/llvm-6/include/llvm/IR/ValueHandle.h:275

5 0x000000014382a55b in TreeToLLVM::set_decl_local (this=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node, llvm::Value)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node, llvm::Value)".>, V=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node, llvm::Value)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:742

6 0x0000000143831d9b in TreeToLLVM::EmitAutomaticVariableDecl (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitAutomaticVariableDecl(tree_node)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitAutomaticVariableDecl(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:2723

7 0x000000014382a71f in TreeToLLVM::make_decl_local (this=<error reading variable: Could not find the frame base for "TreeToLLVM::make_decl_local(tree_node)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::make_decl_local(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:774

8 0x000000014382c975 in TreeToLLVM::EmitVariablesInScope (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>, scope=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1348

9 0x000000014382c8f6 in TreeToLLVM::StartFunctionBody (this=<error reading variable: Could not find the frame base for "TreeToLLVM::StartFunctionBody()".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1337

10 0x000000014382ebf9 in TreeToLLVM::EmitFunction (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitFunction()".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1878

11 0x000000014380b9a1 in emit_current_function () at /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:2069

12 0x000000014380ba9e in rtl_emit_function () at /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:2104

13 0x000000014380bbdb in pass_rtl_emit_function::execute (this=<error reading variable: Could not find the frame base for "pass_rtl_emit_function::execute(function*)".>) at /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:2173

14 0x000000010085240f in execute_one_pass (pass=) at ../../gcc/timevar.h:209

15 0x00000001008529c8 in execute_pass_list_1 (pass=) at ../../gcc/passes.c:2412

16 0x0000000100852a2d in execute_pass_list (fn=, pass=) at ../../gcc/passes.c:2430

17 0x00000001004f3f73 in cgraph_node::expand (this=) at ../../gcc/cgraphunit.c:1994

18 0x00000001004f56ef in symbol_table::compile (this=) at ../../gcc/cgraphunit.c:2128

19 0x00000001004f755b in analyze_functions (first_time=) at ../../gcc/cgraphunit.c:883

20 0x00007ffeefbfecf0 in ?? ()

21 0x0000000000000000 in ?? ()

eminarcissus commented 5 years ago

wc.c: In function 'main': wc.c:22:17: warning: implicit declaration of function 'read' [-Wimplicit-function-declaration] while ((r = read(fd, BUFFER, BUFFER_SIZE)) > 0) { ^~~~ wc.c:30:5: warning: implicit declaration of function 'close' [-Wimplicit-function-declaration] close(fd); ^~~~~ DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2246: llvm_emit_globals DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 826: InitializeBackend: x86_64-apple-darwin18 DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 691: CreateTargetMachine: triple: x86_64-apple-darwin18 cpu: x86-64 feature: +64bit,-3dnow,-3dnowa,-aes,-avx,-cx16,-fma,-fma4,+mmx,-popcnt,-rdrnd,+sse,+sse2,+sse3,-sse4.1,-sse4.2,-sse4a,-ssse3 DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 754: CreateModule: e-m:o-i64:64-f80:128-n8:16:32:64-S128 DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2181: emit_file_scope_asms DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2287: llvm_emit_globals: vnode DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 1383: emit_global DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2206: emit_cgraph_weakrefs DEBUG: /Users/misuzi/developing/c/dragonegg/src/Backend.cpp, line 2221: emit_varpool_weakrefs

Thread 2 received signal SIGSEGV, Segmentation fault. --------------------------------------------------------------------------[regs] EAX: 0x00000000 EBX: 0x43024820 ECX: 0x0000001C EDX: 0x01D0EF68 o d I t s Z a P c ESI: 0x01D0EF68 EDI: 0x00000000 EBP: 0xEFBFDA10 ESP: 0xEFBFD9E0 EIP: 0xError while running hook_stop: Value can't be converted to integer. 0x0000000144f47f3d in llvm::ValueHandleBase::RemoveFromUseList (this=0x102802668) at /Users/misuzi/developing/c/llvm/lib/IR/Value.cpp:804 804 assert(*PrevPtr == this && "List invariant broken"); gdb$ bt

0 0x0000000144f47f3d in llvm::ValueHandleBase::RemoveFromUseList (this=0x102802668) at /Users/misuzi/developing/c/llvm/lib/IR/Value.cpp:804

1 0x0000000143826645 in llvm::ValueHandleBase::operator= (this=<error reading variable: Could not find the frame base for "llvm::ValueHandleBase::operator=(llvm::Value)".>, RHS=<error reading variable: Could not find the frame base for "llvm::ValueHandleBase::operator=(llvm::Value)".>) at /usr/local/llvm-6/include/llvm/IR/ValueHandle.h:74

2 0x0000000144680f37 in llvm::AssertingVH::setRawValPtr (this=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setRawValPtr(llvm::Value)".>, P=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setRawValPtr(llvm::Value)".>) at /Users/misuzi/developing/c/llvm/include/llvm/IR/ValueHandle.h:247

3 0x000000014461c13a in llvm::AssertingVH::setValPtr (this=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setValPtr(llvm::Value)".>, P=<error reading variable: Could not find the frame base for "llvm::AssertingVH::setValPtr(llvm::Value)".>) at /Users/misuzi/developing/c/llvm/include/llvm/IR/ValueHandle.h:258

4 0x0000000143850e25 in llvm::AssertingVH::operator= (this=<error reading variable: Could not find the frame base for "llvm::AssertingVH::operator=(llvm::Value)".>, RHS=<error reading variable: Could not find the frame base for "llvm::AssertingVH::operator=(llvm::Value)".>) at /usr/local/llvm-6/include/llvm/IR/ValueHandle.h:275

5 0x000000014382a55b in TreeToLLVM::set_decl_local (this=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node, llvm::Value)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node, llvm::Value)".>, V=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node, llvm::Value)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:742

6 0x0000000143831d9b in TreeToLLVM::EmitAutomaticVariableDecl (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitAutomaticVariableDecl(tree_node)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitAutomaticVariableDecl(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:2723

7 0x000000014382a71f in TreeToLLVM::make_decl_local (this=<error reading variable: Could not find the frame base for "TreeToLLVM::make_decl_local(tree_node)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::make_decl_local(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:774

8 0x000000014382c975 in TreeToLLVM::EmitVariablesInScope (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>, scope=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1348

9 0x000000014382c9a9 in TreeToLLVM::EmitVariablesInScope (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>, scope=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1351

10 0x000000014382c9a9 in TreeToLLVM::EmitVariablesInScope (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>, scope=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitVariablesInScope(tree_node)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1351

11 0x000000014382c8f6 in TreeToLLVM::StartFunctionBody (this=<error reading variable: Could not find the frame base for "TreeToLLVM::StartFunctionBody()".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1337

12 0x000000014382ebf9 in TreeToLLVM::EmitFunction (this=<error reading variable: Could not find the frame base for "TreeToLLVM::EmitFunction()".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:1878

13 0x000000014380b9a1 in emit_current_function () at /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:2069

14 0x000000014380ba9e in rtl_emit_function () at /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:2104

15 0x000000014380bbdb in pass_rtl_emit_function::execute (this=<error reading variable: Could not find the frame base for "pass_rtl_emit_function::execute(function*)".>) at /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:2173

16 0x000000010085240f in execute_one_pass (pass=) at ../../gcc/timevar.h:209

17 0x00000001008529c8 in execute_pass_list_1 (pass=) at ../../gcc/passes.c:2412

18 0x0000000100852a2d in execute_pass_list (fn=, pass=) at ../../gcc/passes.c:2430

19 0x00000001004f3f73 in cgraph_node::expand (this=) at ../../gcc/cgraphunit.c:1994

20 0x00000001004f56ef in symbol_table::compile (this=) at ../../gcc/cgraphunit.c:2128

21 0x00000001004f755b in analyze_functions (first_time=) at ../../gcc/cgraphunit.c:883

22 0x00007ffeefbfed00 in ?? ()

23 0x0000000000000000 in ?? ()

gdb$

xiangzhai commented 5 years ago

What is the version of dragonegg you are using? I can not locate:

#5 0x000000014382a55b in TreeToLLVM::set_decl_local (this=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node*, llvm::Value*)".>, decl=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node*, llvm::Value*)".>, V=<error reading variable: Could not find the frame base for "TreeToLLVM::set_decl_local(tree_node*, llvm::Value*)".>) at /Users/misuzi/developing/c/dragonegg/src/Convert.cpp:742

In the latest commit https://github.com/xiangzhai/dragonegg/commit/e93723b7e328e05b868fca6e67ef203f8e010232

eminarcissus commented 5 years ago

I'm using c1b5b35 this commit with gcc6 and llvm 6.0. Afterwards it starts to accommodates for later version LLVM which cannot create a working builds.

eminarcissus commented 5 years ago

master latest commit I'm frequently seeing this error during compiling /Users/misuzi/developing/c/dragonegg/src/Backend.cpp: In function 'llvm::Value* make_decl_llvm(tree)': /Users/misuzi/developing/c/dragonegg/src/Backend.cpp:1634:20: error: 'debug_tree' was not declared in this scope debug_tree(decl); ^

xiangzhai commented 5 years ago

debug_tree https://github.com/xiangzhai/dragonegg/issues/33

eminarcissus commented 5 years ago

I don't know if it is really a gcc compiling problem or not, because I did have gcc compiled with plugin and the compiling dragonegg versions don't have too structural difference in code(the latest master the 2017 latest version). They both contains debug_tree in the same function at a first glance. More changes were taken in header files, which I guess is accommodates different version of llvm and gcc, but older one works but not the latest one. Except for debug tree(I tried to comment out that line first for a compile), there are also some other problems as well, I'm considering to build a llvm-9 to give it a try as well.

For the debug_tree problem, the same thing happening when I compile the old version dragonegg with different version of llvm(especially for the latest working version between llvm3.2 and dragonegg3.2, a small version bump might create quite a lot similar problems).

xiangzhai commented 5 years ago

Migrate to llvm-9 https://github.com/xiangzhai/dragonegg/issues/35

eminarcissus commented 5 years ago

hmmm,llvm-9 is not officially released yet?