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

LLVM 4 #18

Closed
wants to merge 17 commits into from
Closed

LLVM 4 #18

wants to merge 17 commits into from

Conversation

jcarlson23
Copy link

This should be relatively easy to integrate - although I would put this into a separate (a staging or local) branch and then merge back into the GitHub master from there. The WPAPass no longer inheriting from AliasAnalysis is probably the place I would suggest to be looked at the most. The "SVF Alterations.rtf" gives a summary of the changes, etc...

Let me know what else I can do to help. I've gotta move on to a few other things the rest of the week but next week I'm going to start outline a few pivots I'm hoping to expand on :-)

jcarlson23 and others added 17 commits March 28, 2017 17:30
… like so far it's line and file information, i.e diagnostic so..
…ysisUtil looks more like I might miss some diagnostic info
…vs X* in the node references, but let me take a look at this before rushing right in (I can do that this afternoon)
…arification of pointers or double pointers in WPASolver
…ngRef, inserting a few NodeRef, etc, and now compiling a fair amount of the project, but still more to go...
…e some new virtual methods in 4.0 aren't implemented...
…ing the LLVMGetGlobalContext rather than getGlobalContext
@yuleisui
Copy link
Collaborator

Jared,

Thanks for your help!

I am pretty busy these few days, and will start looking into your pull request from next week :)

@nix7965
Copy link

nix7965 commented Apr 22, 2017

Hi, Jared.

In overall, I think your code works well.
However, one thing that I found is that
When I execute "wpa -ander -svfg -dump-svfg c++.opt", it couldn't recognize "-svfg" which is the valid option. (https://github.com/unsw-corg/SVF/wiki/Analyze-a-Simple-C-Program)

wpa: Unknown command line argument '-svfg'. Try: 'wpa -help'
wpa: Did you mean '-ci-svfg'?

Since I am not sure whether who will fix it, I leave my comment here.

PS. nix7965 referenced this pull request 5 days ago -> Did I make a mistake something? Why that appears...

@yuleisui
Copy link
Collaborator

I believe you need to apply Jared's patch on the most recent version of SVF. Try "git pull" before merging his patch.

@jcarlson23
Copy link
Author

Let me know if you need anything. I don't recall changing an argument for wpa, but it might need a change with the AliasAnalysis change (requiring TargetLibraryInfo in any constructor call).

@nix7965
Copy link

nix7965 commented Apr 23, 2017

From my experience, I applied "only" Jared's patch to the recent SVF. Then, it works.

Also, there is some minor issue. I don't know why but SVF with @jcarlson23 's patch can be compiled only with "cmake -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true".

@@ -6,7 +6,7 @@
// Copyright (C) <2013-2016> <Jingling Xue>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// it under the terms of the GNU Gg12eneral Public License as published by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this snuck in!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, sorry, I can update that if need be.. obviously just a typo... :(

@dtzWill
Copy link
Contributor

dtzWill commented Apr 25, 2017

Merging this with current SVF master yields: dtzWill@ee5aead

Which seems to work pretty well overall, haven't stressed it too much yet :).

I'll note that #17 happens 100% of the time for me with these changes, please see my comment on that issue for a suggest workaround (or a discussion of why a workaround is not needed and I'm doing something wrong! ;)). Either way, probably worth being aware of.

Thanks for the LLVM 4 port and of course thanks for SVF! 👍

@dtzWill
Copy link
Contributor

dtzWill commented Apr 25, 2017 via email

@jcarlson23
Copy link
Author

I think #17 probably happens because the fix in master was after when I started the port to llvm-4, so I think that'll be solved with a proper merge... At least I hope so, but I'm not surprised by it, fwiw...

@dtzWill
Copy link
Contributor

dtzWill commented Apr 25, 2017

@jcarlson23

That was my initial guess as well but AFAICT the issue happens on latest master (without your changes) but happens to not crash. As I mentioned on #17 running under valgrind shows it's doing the same invalid memory accesses but apparently they're not a problem for whatever reason.

We'll see what the SVF folks say though, and regardless it'd be good to have some of this confirmed by others :).

@yuleisui
Copy link
Collaborator

Hopefully, I will start testing Jared's patch from tomorrow:)

@@ -51,6 +51,12 @@ set(SOURCES
add_llvm_loadable_module(Svf ${SOURCES})
add_llvm_Library(LLVMSvf ${SOURCES})

# It seems that the Svf library needs to explictly require the CUDD alloc/init/etc so LLVMCudd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added part causes an error when linking "Svf.so" in my ubuntu machine (completely ok on mac), see below:

/usr/bin/ld: CUDD/libLLVMCudd.a(cuddInit.c.o): relocation R_X86_64_32S against `Cudd_OutOfMem' can not be used when making a shared object; recompile with -fPIC
CUDD/libLLVMCudd.a: error adding symbols: Bad value

If I delete those five lines, it will be all good on ubuntu, but causing a linking error on mac os ;(

If possible, could you please take a look at it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this ought to be straightforward I think. I just moved computers but let me create a VM to test in and put in a architecture check and I think this can be resolved... (I'll try to update tonight).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have a fix but have been in VM purgatory today so but basically just used CMAKE_SYSTEM_NAME and a little if-else.. so just will test again, today got away from me but this is the easy part...

Copy link
Author

@jcarlson23 jcarlson23 May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, this built for me on Ubuntu16.04 LT with the following changes:

Diff for CMakeLists.txt

I can reissue the pull request if that's easier but this is trivial so I'm going to focus on the iterator issue below.

@@ -189,7 +189,7 @@ bool SymbolTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) {
// Handling array types, skipe array handling here
// We treat whole array as one, then we can distinguish different field of an array of struct
// e.g. s[1].f1 is differet from s[0].f2
if(isa<ArrayType>(*gi))
if(isa<ArrayType>(gi.getIndexedType()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We found that the change made from "*gi" to "gi.getIndexedType" causes quite a few of our test cases failed.

The llvm-4.0.0 says "gi.getIndexedType" is the same as "operator*() " (see below in llvm-4.0.0/include/llvm/IR/GetElementPtrTypeItertor.h)

// FIXME: Make this the iterator's operator*() after the 4.0 release.
// operator*() had a different meaning in earlier releases, so we're
// temporarily not giving this iterator an operator*() to avoid a subtle
// semantics break.

However, I found the semantic of get_type_iterator was actually changed in LLVM-4.0 against LLVM-3.8.0. They are not semantic equivalent anymore.

Suppose we have a LLVM Value V
%arrayidx3 = getelementptr inbounds [2 x %struct.MyStruct], [2 x %struct.MyStruct]* %s, i64 0, i64 %idxprom, !dbg !67

if we use gep_type_iterator to iterate the types of the above value

for (gep_type_iterator gi = gep_type_begin(*V), ge = gep_type_end(*V); gi != ge; ++gi) {
  (*gi)->dump()                 // in llvm-3.8  
  gi.getIndexedType()->dump()   // in llvm 4.0  
  gi.getOperand()->dump()  
}

We will get two elements (two types), but different results with respect to different llvm versions, as follows:

llvm-3.8.0

[2 x %struct.MyStruct]*
i64 0

[2 x %struct.MyStruct]
%idxprom = sext i32 %0 to i64, !dbg !67

llvm-4.0.0

[2 x %struct.MyStruct]
i64 0

%struct.MyStruct = type { i32*, i32* }
%idxprom = sext i32 %0 to i64, !dbg !32

@jcarlson23
@dtzWill
Any idea on how to get the type of an operand instead of its container type using type iterator (or using some other ways)?

I don't prefer to change the code in the memoryModel.

Thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... A bit trickier than I had hoped :(

So just to make sure I understand the issue is the Operand's type? So in your code example
(*gi)->dump() is equivalent to gi.getIndexedType()->dump() from 3.8 to 4.0, but in the iterator the getOperand() in 4.0 is now pointing to the container's type rather than directly to the operand's type?

From what I saw in the code, I agree that changing the memory model would be very low in my preferences... Let me dig in a bit later tonight... See if we can't find a better solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(*gi)->dump() are not equivalent to gi.getIndexedType()->dump() in 4.0 now.

Yes, it needs to be the operand's type rather than its container's

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, darn. For what it's worth, here's a bit of discussion about the commit that caused this functionality change:

https://reviews.llvm.org/D26594

Maybe the information there will help understand the changes and how to accommodate them properly.

I've run into this while migrating another project to 4.0 but haven't had time to sort out the changes sorry :(.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, thanks @dtzWill ! I was offline for a while today so I didn't get a chance to look at the commit/discussion log.

I'll dig in a bit more here.. If I get stuck I'll ask around or post to the mailing list in a day or so...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtzWill Yeah, thanks, I did that and still had some serious issues... Some of it, I think, is just the mess of Xcode and multiple llvm builds. Also I think some of the expected directories coming out of the build I had renamed... eh.. it's a new machine, I kind of dumped some of the old apps/tools in and added some new and haven't quite had time to sort the cruft, but I'll get there.

I'm curious what you mean regarding your last paragraph. Are you referring to building a CFG based model to dynamically check pointers? Something akin to CFI (Control Flow Integrity) but with more analytical depth? Do you care how the source might be altered/appended to, something like Seahorn or Pagai? Anyway, just genuinely curious as to what you're after there...

As this is starting to get off tangent, perhaps email is best, but whatever works... Thanks again.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have said, I'll give the NIX stuff a crack as that help me clean up what I've got going, thanks for sharing!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jared,

Alternatively, I've also attached my scripts to build and setup SVF (llvm-4.0). Hopefully, it will be helpful for your to test bridgedGepIterator against PTABen.

buid.sh
setup.sh

You PR is behind the master repo. For a clean merge, could you please give a new PR after passing all the micro-benchmarks using your bridgedGepIteraor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rockysui BridgedGepIterator it is! I'm going to close this PR out then and work locally for a few days and get you a new one. I'll aim for Monday, using your scripts or the NIX setup from Will to right my testing setup...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Jared!

dtzWill added a commit to dtzWill/SVF that referenced this pull request May 4, 2017
See ongoing discussion for context:

SVF-tools#18

Mostly I'm just curious what this does to results on our programs,
this is likely not the right thing to do.
@jcarlson23 jcarlson23 closed this May 5, 2017
yuleisui added a commit that referenced this pull request Aug 30, 2019
Optimise node retrieval in CHG.
yuleisui added a commit that referenced this pull request Nov 23, 2022
Refactor boilerplate code of disjunctive predicates of "isa()"
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.

4 participants