Help using RetDec with Hello World
- Dominant language
- C++
- Stars
- 8.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to get a feel for how retdec works but am unable to successfully de-compile a GCC compiled shared object file and re-compile the object file with Clang.
I'm using Debian and the retdec-v3.3 pre-built debian binary.
Here is `test.c`:
```c
#include
void print_hello(void);
int main()
{
print_hello();
}
```
Here is `shared.c`:
```c
#include
void print_hello(void) {
printf("\n\nShared Hello World!\n\n");
}
```
Here is what I am doing:
```bash
# Compile `test.c` to LLVM bitcode
clang test.c -emit-llvm -c -o test.bc
# Compile `shared.c` to x86-64 ELF file
gcc -shared shared.c -o shared
# De-compiles `shared` to `shared.bc`
/opt/retdec/bin/retdec-decompiler.py shared
```
Everything above seems to work great. Now I try to produce a final output binary using the bitcode files:
```bash
clang-10 test.bc shared.bc -o test
```
This fails with:
```
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
/usr/bin/ld: /tmp/shared-e43926.o: in function `_fini':
test:(.text+0x140): multiple definition of `_fini'; /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
/usr/bin/ld: /tmp/shared-e43926.o: in function `_init':
test:(.text+0x0): multiple definition of `_init'; /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o: in function `_init':
(.init+0x7): undefined reference to `__gmon_start__'
/usr/bin/ld: /tmp/shared-e43926.o: in function `_init':
test:(.text+0x19): undefined reference to `__gmon_start__'
/usr/bin/ld: test:(.text+0x1f): undefined reference to `__unnamed_1'
/usr/bin/ld: /tmp/shared-e43926.o: in function `__do_global_dtors_aux':
test:(.text+0xcc): undefined reference to `__unnamed_1'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
```
Am I doing something wrong? What could I do to make this simple example work?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with test.c and shared.c, then reproduce the commands using retdec-decompiler.py and clang-10. Inspect the generated shared.bc around the reported _init, _fini, __gmon_start__, and __unnamed_1 linker symbols. Done means the Hello World example links and runs successfully from the produced bitcode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, cpp, debian
- Domain
- compilers, operating-systems, reverse-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100