symcc icon indicating copy to clipboard operation
symcc copied to clipboard

compiler: add supporting passes

Open adrianherrera opened this issue 4 years ago • 1 comments
trafficstars

The PR introduces a number of LLVM passes into the symbolize process.

The ExpandAsm pass exploits LLVM's target lowering and its ability to expand inline assembly into explicit LLVM code.

Importantly, this expansion includes lifting bswap instructions to the bswap intrinsic, which can be symbolized with symcc. This fixes issue #29 and does away with the hacks made in PR #75 (in an attempt to get the tests to pass).

We also run the LLVM scalarizer and loweratomics passes. The former removes most vector instructions and the latter removes atomic instructions. These instructions are currently unsupported by symcc.

adrianherrera avatar Sep 10 '21 23:09 adrianherrera

Hi @adrianherrera, thanks for the PR! Sorry for the late answer to it... Could you :

  • add support for the new pass manager (see for example https://github.com/banach-space/llvm-tutor#about-pass-managers-in-llvm)
  • add a testcase to test the feature? Thanks !

aurelf avatar Dec 21 '21 14:12 aurelf

@adrianherrera sorry for getting back to this so terribly late. We haven't had a lot of resources to work on SymCC, so I'm only now finding time to go through the open pull requests...

I really like the idea of adding LLVM passes that support SymCC! The first commit, adding the scalarizer and atomics lowering, should be no problem to add; I will cherry-pick it and merge immediately if the tests pass. The second commit, lifting inline assembly, makes a lot of sense too, but I'm a bit worried that it's a lot of code for a small feature: pass registration is really noisy (not your fault at all, it's what LLVM does), lifting is only supported for x86 and ARM, and it only handles byte swapping. If you don't mind, I'll change the code a bit:

  • Use the module's declared target triple instead of LLVM's default target. I'm not aware of anyone cross-compiling with SymCC, but you never know :grin:
  • Run the lifter at the start of our own function pass, so that we can get rid of the pass registration noise. Nobody's going to reuse the pass that we define, so I suppose the transform can as well happen in the SymCC pass...

sebastianpoeplau avatar Feb 15 '23 13:02 sebastianpoeplau

Hi, that's interesting, thanks both for the work on the features. I really like the lifter feature, however, it seem to work for simple inline assembly, are there any drawbacks to it ? If so shall we make this optional provide a warning about it?

aurelf avatar Feb 15 '23 16:02 aurelf

I really like the lifter feature, however, it seem to work for simple inline assembly, are there any drawbacks to it ? If so shall we make this optional provide a warning about it?

I don't see any drawbacks :thinking: It won't work all the time, but when it works the result is better than what we had before.

sebastianpoeplau avatar Feb 16 '23 13:02 sebastianpoeplau

I really like the lifter feature, however, it seem to work for simple inline assembly, are there any drawbacks to it ? If so shall we make this optional provide a warning about it?

I don't see any drawbacks thinking It won't work all the time, but when it works the result is better than what we had before.

OK, great thanks !

aurelf avatar Feb 16 '23 16:02 aurelf

Awesome, thanks for fixing the PR! Recently we have been working with Trail of Bits and their Remvill/Anvill lifting tools to lift more complicated inline assembly code constructs. Hopefully, we'll soon be able to share this if you're interested.

adrianherrera avatar Feb 17 '23 08:02 adrianherrera

Sounds very nice! :blush: I'm definitely interested.

sebastianpoeplau avatar Feb 17 '23 10:02 sebastianpoeplau