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

CMPLOG llvm pass: use CreateIntCast to cast to the right integer type #746

Merged
merged 2 commits into from
Feb 16, 2021

Conversation

f0rki
Copy link
Contributor

@f0rki f0rki commented Feb 15, 2021

In the current dev branch I get errors while compiling a target with cmplog (afl-clang-lto++). My target uses bigints, which leads to trouble for the cmplog instrumentation. This PR fixes the issues (at least for me). Currently I get the following error:

Invalid bitcast
  %10 = bitcast i80 %9 to i128, !dbg !29860
in function _ZSt7signbite
LLVM ERROR: Broken function found, compilation aborted!

I think bitcast i80 to i128 doesn't work since bitcast only works with types of the exact same bit size. So we need to use zext instead to extend to i128 in the case above. I believe that CreateIntCast on the IRBuilder is the right function for this job (except we need a bitcast to an integer type first in case we are dealing with floating point values).

I think that previously 128 bit integer types were also implicitly truncated due to the use of uint64_t val = cint->getZExtValue(); to create a new constant integer. I haven't tested this, but this should be fixed now too.

@vanhauser-thc
Copy link
Member

are you using afl-clang-lto?
because I implemented a fix for this like 4 hours ago :)

@f0rki
Copy link
Contributor Author

f0rki commented Feb 15, 2021

lol. apparently afl++ dev speed is too fast for me. yes I am using clang LTO. yes it seems fixed in current dev.

But I am wondering whether I would loose instrumentation of some compare instructions with the current workaround in dev?

I think that previously 128 bit integer types were also implicitly truncated due to the use of uint64_t val = cint->getZExtValue(); to create a new constant integer.

Does this part still apply?

@vanhauser-thc
Copy link
Member

I like your solution better than mine, in LTO I just skip this crashing bitcast. can you rework your PR to fit to the changed dev state?

@f0rki
Copy link
Contributor Author

f0rki commented Feb 15, 2021

sure. I'll rebase and revert your workaround (edit: but probably tomorrow morning). Do you have another project where this issue comes up that I can use for testing?

@vanhauser-thc
Copy link
Member

I think that previously 128 bit integer types were also implicitly truncated due to the use of uint64_t val = cint->getZExtValue(); to create a new constant integer.

Does this part still apply?

yes:
https://llvm.org/doxygen/classllvm_1_1ConstantInt.html#ac09a21c371a9c535cbc13e8f82503aec

@f0rki
Copy link
Contributor Author

f0rki commented Feb 16, 2021

@vanhauser-thc done. rebased and reverted workaround.

@vanhauser-thc
Copy link
Member

thank you!

@vanhauser-thc vanhauser-thc merged commit 686719c into AFLplusplus:dev Feb 16, 2021
abertschi pushed a commit to mattweingarten/AFLplusplus that referenced this pull request Apr 21, 2022
@f0rki f0rki deleted the cmplog-intcast-fix branch July 11, 2023 14:19
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

Successfully merging this pull request may close these issues.

None yet

2 participants