yomaytk / elfconv

An experimental AOT compiler that translates Linux ELF binary to WebAssembly
Apache License 2.0
148 stars 6 forks source link

Core dumped #2

Closed jedisct1 closed 5 months ago

jedisct1 commented 6 months ago

Hi,

I tried to run it, using the container image, but only got core dumps. Here's a transcript:

./elfconv.sh /bin/echo
[INFO] Building libelfconv.a ...
In file included from Entry.cpp:3:
/root/elfconv/bin/..//backend/remill/include/remill/Arch/Runtime/Intrinsics.h:70:44: warning: '__remill_undefined_f80' has C-linkage specified, but returns user-defined type 'float80_t' which is incompatible with C [-Wreturn-type-c-linkage]
   70 | [[gnu::used, gnu::const]] extern float80_t __remill_undefined_f80(void);
      |                                            ^
1 warning generated.
In file included from VmIntrinsics.cpp:5:
/root/elfconv/bin/..//backend/remill/include/remill/Arch/Runtime/Intrinsics.h:70:44: warning: '__remill_undefined_f80' has C-linkage specified, but returns user-defined type 'float80_t' which is incompatible with C [-Wreturn-type-c-linkage]
   70 | [[gnu::used, gnu::const]] extern float80_t __remill_undefined_f80(void);
      |                                            ^
1 warning generated.
[INFO] Generate libelfconv.a.
[INFO] Converting ELF to LLVM bitcode ...
[BUG] GetFuncEntry is called but symbols is empty
./elfconv.sh: line 53: 10235 Aborted                 (core dumped) ./elflift --arch aarch64 --bc_out lift.bc --target_elf "$ELFPATH" --dbg_fun_cfg "$2"
(gdb) bt
#0  __pthread_kill_implementation (threadid=281473331847200, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x0000ffff9ddff254 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  0x0000ffff9ddba67c in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x0000ffff9dda7130 in __GI_abort () at ./stdlib/abort.c:79
#4  0x0000aaaac78959c4 in BinaryLoader::ELFObject::GetFuncEntry (this=0xfffffb34ceb0) at /root/elfconv/front/Binary/Loader.cpp:245
#5  0x0000aaaac78a4e10 in AArch64TraceManager::SetELFData (this=0xfffffb34ce48) at /root/elfconv/front/TraceManager.cpp:81
#6  0x0000aaaac78adba0 in main (argc=1, argv=0xfffffb34d298) at /root/elfconv/front/Lift.cpp:42

Is /bin/echo something that can't be converted to WebAssembly?

jedisct1 commented 6 months ago

With the hello example:

./elfconv.sh ../examples/hello/a.out
[INFO] Building libelfconv.a ...
In file included from Entry.cpp:3:
/root/elfconv/bin/..//backend/remill/include/remill/Arch/Runtime/Intrinsics.h:70:44: warning: '__remill_undefined_f80' has C-linkage specified, but returns user-defined type 'float80_t' which is incompatible with C [-Wreturn-type-c-linkage]
   70 | [[gnu::used, gnu::const]] extern float80_t __remill_undefined_f80(void);
      |                                            ^
1 warning generated.
In file included from VmIntrinsics.cpp:5:
/root/elfconv/bin/..//backend/remill/include/remill/Arch/Runtime/Intrinsics.h:70:44: warning: '__remill_undefined_f80' has C-linkage specified, but returns user-defined type 'float80_t' which is incompatible with C [-Wreturn-type-c-linkage]
   70 | [[gnu::used, gnu::const]] extern float80_t __remill_undefined_f80(void);
      |                                            ^
1 warning generated.
[INFO] Generate libelfconv.a.
[INFO] Converting ELF to LLVM bitcode ...
./elflift --arch aarch64 --bc_out lift.bc --target_elf /root/elfconv/examples/hello/a.out --dbg_fun_cfg
terminate called after throwing an instance of 'std::runtime_error'
  what():  [ERROR] "__libc_start_main@GLIBC_2.34" is included in multiple sections.

./elfconv.sh: line 60: 11199 Aborted                 (core dumped) ./elflift --arch aarch64 --bc_out lift.bc --target_elf "$ELFPATH" --dbg_fun_cfg "$2"
[INFO] Generate lift.bc.
[INFO] Converting LLVM bitcode to WASM binary and glue code (for browser) ...
emcc: error: lift.bc: No such file or directory ("lift.bc" was expected to be an input file, based on the commandline arguments provided)
[INFO] Generate WASM binary.

Did I miss something?

yomaytk commented 6 months ago

@jedisct1 Thank you for trying! First, elfconv cannot compile the dynamically linked or stripped binaries now, so unfortunately, I think you may fail to compile many ELF binaries placed in the directories of Ubuntu from the beginning. However, I will implement them in the future because those functions are important.

Second, to prevent the failing of ./elfconv.sh ../examples/hello/a.out I placed the Makefile in the every examples/* directory, and please try again after pulling the latest commit.

Thanks!

jedisct1 commented 5 months ago

Thank you!