Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to llvm-to-source a .sliced file that is obtained from a linked bitcode file #429

Closed
TimHe95 opened this issue Mar 3, 2022 · 2 comments

Comments

@TimHe95
Copy link

TimHe95 commented Mar 3, 2022

I want to slice a part of the PostgreSQL source, from fsync function, backward to an entry: RecordTransactionCommit. This anaylsis contains tree .c source files: xact.c xlog.c fd.c. Following the document, I obtain the .bc files repectively:

# get xact.bc
clang-6.0 -c -g -emit-llvm -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -I../../../../src/include -D_GNU_SOURCE -DHAVE_SYNC_FILE_RANGE -o xact.bc xact.c
# get fd.bc
clang-6.0 -c -g -emit-llvm -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -I../../../../src/include -D_GNU_SOURCE -DHAVE_SYNC_FILE_RANGE -o xlog.bc xlog.c
# get fd.bc
clang-6.0 -c -g -emit-llvm -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -I../../../../src/include -D_GNU_SOURCE -DHAVE_SYNC_FILE_RANGE -o fd.bc fd.c

And link them together:

llvm-link fd.bc xlog.bc xact.bc -o xact+xlog+fd.bc

Then, run the slicer.

llvm-slicer -cutoff-diverging=false -pta 'fs' -sc 'fsync' -entry=RecordTransactionCommit -annotate cd,slice,dd xact+xlog+fd.bc

I want to know what code (i.e., for me, variable names) remains after slicing. So I use llvm-to-source

# xact.c is the longest file among the three
llvm-to-source xact+xlog+fd.sliced xact.c

The resulting code is in a mess. It contains some random comments. It seems that llvm-to-source does not distinguish the line numbers of the three files. How can I solve this problem?

Thanks!

@mchalupa
Copy link
Owner

mchalupa commented Mar 3, 2022

llvm-to-source cannot do something like that. It can work only with a single C file. It's just a very simple debugging tool (patches are welcome ;). You may try to compile the code with -g -fno-discard-value-names and use llvm2c or rellic to get C code from the sliced LLVM. The code will not look like the original code, but it will be C...

@TimHe95
Copy link
Author

TimHe95 commented Mar 4, 2022

Works well! Thanks.

@TimHe95 TimHe95 closed this as completed Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants