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

dynamic-cc instrumented prints nothing #62

Closed
YuuuuuuuuY opened this issue Mar 11, 2022 · 8 comments · Fixed by #65
Closed

dynamic-cc instrumented prints nothing #62

YuuuuuuuuY opened this issue Mar 11, 2022 · 8 comments · Fixed by #65

Comments

@YuuuuuuuuY
Copy link
Contributor

I'm using llvm 13.0.1
After being instrumented by dynamic-cc, running the program in lli prints nothing.
But when I run the same program in lli 15.0.0, it prints as expected.

Anybody experienced same issue?

@banach-space
Copy link
Owner

Hey, thanks for posting this!

Could you copy and paste all your commands so that I can reproduce this?

Thanks,
-Andrzej

@YuuuuuuuuY
Copy link
Contributor Author

Thanks for replying!
Here are the commands I used:

$ clang-13 -O1 -emit-llvm -c ../../inputs/input_for_cc.c -o input_for_cc.bc
$ opt-13 -enable-new-pm=0 -load ./libDynamicCallCounter.so -legacy-dynamic-cc input_for_cc.bc -o instrumented_bin

# running it on lli-13 prints nothing
$ lli-13 ./instrumented_bin

# running it on lli 15.0.0, which is built from source code, prints the following:
$ LLVM_PROJECT_DIR/build/bin/lli ./instrumented_bin
=================================================
LLVM-TUTOR: dynamic analysis results
=================================================
NAME                 #N DIRECT CALLS
-------------------------------------------------
foo                  0         
bar                  0         
fez                  0         
main                 1

@banach-space
Copy link
Owner

Thanks for sending this! Please try this for your first step (replace -O1 with -O0 -Xclang -disable-O0-optnone):

$ clang-13 -O0 -Xclang -disable-O0-optnone -emit-llvm -c ../../inputs/input_for_cc.c -o input_for_cc.bc

You should get a good idea of what is happening by comparing the generate file before and after the change (you will want to add -S too to get a textual form of the test file, too).

That's my bad - I need to update the README file. Sorry about it - I really appreciate you reporting this, thank you!

-Andrzej

@YuuuuuuuuY
Copy link
Contributor Author

I tried the change and it only makes lli 15 to print something different:

=================================================
LLVM-TUTOR: dynamic analysis results
=================================================
NAME                 #N DIRECT CALLS
-------------------------------------------------
foo                  13        
bar                  2         
fez                  1         
main                 1

But lli 13 still prints nothing.

This seems to be caused by JIT. According to the release note, the default JIT engine is changed from -jit-kind=mcjit to -jit-kind=orc.

Using -jit-kind=mcjit on lli 13 prints as expected, but -jit-kind=orc prints nothing. On lli 15, both options work well. So, this is probably a bug in the ORC engine in llvm 13 which is fixed in later releases.

@banach-space
Copy link
Owner

Ah, now I see! Great find :) Annoyingly, I did encounter this myself when bumping to LLVM 13: b2f4d7b.

So, the README needs updating :) Would you fancy creating a PR? And perhaps an end-to-end test?

Thanks for digging into this and seeing it through - that's greatly appreciated!

-Andrzej

@YuuuuuuuuY
Copy link
Contributor Author

Oh, that's right! I didn't even think about checking the tests.

I created a PR updating the README. But DynamicCallCounterTest1.ll does the testing already. Is that the end-to-end test you're talking about?

@banach-space
Copy link
Owner

Thanks for creating that PR!

By "end-to-end" I meant a test that consumes a C file (instead of an LLVM file), so that it needs to run clang first and only then runs a pass on the generated output. Something similar to MergeBB_exec.ll). Such test would verify both:

  • clang invocation
  • opt invocation

This would be "end-to-end" in the sense that it wouldn't skip the Clang invocation. Perhaps not the best name!

I guess that you could just update DynamicCallCounterTest1.ll to contain this run line:

; RUN: %clang -S -emit-llvm %S/../inputs/input_for_cc.c -o - \
; RUN:   | opt -load-pass-plugin %shlibdir/libDynamicCallCounter%shlibext -passes="dynamic-cc,verify" -o %t.bin
; RUN: lli --jit-kind=mcjit %t.bin | FileCheck %s

That should just work ™️ 🤞🏻 :)

I'm suggesting this as next time we will be able to use this test as a reference for people (i.e. something that definitely works as it's regularly being tested in the CI).

-Andrzej

@YuuuuuuuuY
Copy link
Contributor Author

Thanks for the detailed explanation! I've updated the test.

Also, thanks for creating this awesome tutorial!

-Yu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants