revng / revng

revng: the core repository of the rev.ng project
https://rev.ng/
GNU General Public License v2.0
1.25k stars 101 forks source link

Cannot lift example in tutorial #391

Open hushenwei2000 opened 3 weeks ago

hushenwei2000 commented 3 weeks ago

I followed the tutorial for installation in https://rev.ng/blog/open-sourcing-renvg-decompiler-ui-closed-beta. After installation, in this site has an example that says:

OK, let's now decompile a simple program. Consider example.c:

int main(int argc, char *argv[]) {
  return argc * 3;
}

You can compile and decompile it:

$ gcc example.c -o example -O2
$ revng artifact \
        --analyze \
        --progress \
        decompile-to-single-file \
        example \
        | revng ptml --color \
        | grep -A2 -B1 '[^_]main\b' \
        > decompiled.c

You should obtain:

_ABI(SystemV_x86_64)
generic64_t main(generic64_t _argument0) {
  return _argument0 * 3 & 0xFFFFFFFF;
}

I follow this, and there is no error, but my decompiled.c is:

_ABI(SystemV_x86_64)
generic64_t main(generic64_t _argument0) {
  return _argument0 * 3 & 0xFFFFFFFF;
}
hushenwei2000 commented 3 weeks ago

I'm sorry. I found the problem because I didn't follow the newest tutorial : https://docs.rev.ng/user-manual/analyses/. That works on the new tutorial site.

hushenwei2000 commented 3 weeks ago

But I found another 2 problems. 1) When I use revng translate -o example.gen.out example and ./example.gen.out it has error :

[orchestra] (base) bash-4.2$ ./example.gen.out 
Exception: __libc_start_main ({ 0x0, 0x0, 0x0, 0x0 }
 -> { 0x0, 0x0, 0x0, 0x0 }
)
Aborted (core dumped)

2) Besides, when I try revng lift example example.gen.ll and /llvm-16.0.1/bin/clang example.gen.ll, it has lots of undefined error:

[orchestra] (base) bash-4.2$ llvm-16.0.1/bin/clang example.gen.ll 
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot open Scrt1.o: No such file or directory
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot open crti.o: No such file or directory
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot open crtbeginS.o: No such file or directory
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot open crtendS.o: No such file or directory
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot open crtn.o: No such file or directory
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot find -lgcc
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot find -lgcc_s
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot find -lc
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot find -lgcc
/opt/BinaryTranslation/bt-tools/revng/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/binutils-bin/2.39/ld: error: cannot find -lgcc_s
/tmp/quicksort-6e1460.o:null:function rcu_init: error: undefined reference to 'pthread_atfork'
/tmp/quicksort-6e1460.o:null:function qemu_mutex_init: error: undefined reference to 'pthread_mutex_init'
/tmp/quicksort-6e1460.o:null:function rcu_register_thread: error: undefined reference to '__assert_fail'
/tmp/quicksort-6e1460.o:null:function error_exit: error: undefined reference to 'stderr'
aleclearmind commented 2 weeks ago
  1. When I use revng translate -o example.gen.out example and ./example.gen.out it has error :

    Please attach the binary you're translating. Please consider that we no longer focus that much on static binary translation, but simple examples should work.

  2. Besides, when I try revng lift example example.gen.ll and /llvm-16.0.1/bin/clang example.gen.ll

    You can't directly compile the output of lift. revng translate or revng artifact --analyze recompile is the right workflow.

hushenwei2000 commented 2 weeks ago

For the first problem, I just translated the example from the tutorial. The source code is:

int main(int argc, char *argv[]) {
  return argc * 3;
}

I think the translation result is correct, but I don't know what's wrong with my machine. If you haven't met this problem before, that's fine, I will try to figure it out by myself; thanks a lot.

aleclearmind commented 1 week ago

Bug reports must always attach the binary, explaining how to rebuild the binary is problematic.

Please attach the binary.

hushenwei2000 commented 1 week ago

OK here are the binaries. The example is I compile the source code by gcc example.c and theexample.gen.out is the rev.ng translated result. When I run example.gen.out it will cause Exception.

https://drive.google.com/drive/folders/1dLoAXYtwchly7k3tx18tW9TmRzSH_tXK?usp=sharing