Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

In llvm.asan.globals, allow entries to be non-GlobalVariable and skip over them #133

Merged
merged 1 commit into from
Dec 19, 2018

Conversation

kubamracek
Copy link
Contributor

Swift from master currently crashes when building even very simple programs with -O -whole-module-optimization -sanitize=address. The actual crash happens in the AddressSanitizer instrumentation pass because it finds entries inside the llvm.asan.globals list that are not GlobalVariable objects. In short, what happens is that when IRGen emits type descriptors, we add them to the llvm.asan.globals list to avoid instrumenting them, but in WMO, we emit lazy type descriptors and use forward declarations and when those are later replaced with an actual definition, we use replaceAllUsesWith to replace them with a BitCast object. There are valid reasons why we need the BitCast when replacing the type descriptor, so we should instead allow them in the llvm.asan.globals list.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@adrian-prantl
Copy link
Member

Could you add a .ll test for this that highlights the kind of IR this is supposed to accept?

@rjmccall
Copy link
Member

I'll take your word for it that ignoring them is the right thing to do in this case.

This should be upstreamed, though, right?

@kubamracek
Copy link
Contributor Author

So far, this looks a Swift-only problem, so I want to start here to get a fix out soon.

@rjmccall
Copy link
Member

I'm in no position to lecture anyone about preferring to commit things upstream, but this is easily reproducible from valid inputs:

harza:/tmp$ cat a.ll 
@a = common global i64 0
!llvm.asan.globals = !{!0}
!0 = !{i64* @a, !{!"a.ll", i32 0, i32 0}, !"a", i1 false, i1 false}

harza:/tmp$ cat b.ll 
@a = global [10 x i8] zeroinitializer
!llvm.asan.globals = !{!0}
!0 = !{[10 x i8]* @a, !{!"a.ll", i32 0, i32 0}, !"a", i1 false, i1 false}

harza:/tmp$ llvm-link a.ll b.ll -S > c.ll

harza:/tmp$ opt -S -asan c.ll
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Volumes/Data/swift/llvm/include/llvm/Support/Casting.h, line 255.

@rjmccall
Copy link
Member

(Exercise for the reader on how to produce those inputs from valid C.)

@kubamracek
Copy link
Contributor Author

I see! Moved to https://reviews.llvm.org/D55794 and added a test.

llvm-git-migration pushed a commit to llvm-git-prototype/llvm that referenced this pull request Dec 18, 2018
…nd skip over them

Looks like there are valid reasons why we need to allow bitcasts in llvm.asan.globals, see discussion at apple/swift-llvm#133. Let's look through bitcasts when iterating over entries in the llvm.asan.globals list.

Differential Revision: https://reviews.llvm.org/D55794

llvm-svn=349544
…nd skip over them

Looks like there are valid reasons why we need to allow bitcasts in llvm.asan.globals, see discussion at #133. Let's look through bitcasts when iterating over entries in the llvm.asan.globals list.

Differential Revision: https://reviews.llvm.org/D55794



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349544 91177308-0d34-0410-b5e6-96231b3b80d8
@kubamracek kubamracek force-pushed the skip-invalid-entries-in-asan-globals branch from 163acd6 to bddfc85 Compare December 18, 2018 21:33
@kubamracek
Copy link
Contributor Author

Changes this PR to just be a cherry-pick of r349544. @rjmccall looks good for 5.0?

@rjmccall
Copy link
Member

Yep!

@kubamracek
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@kubamracek
Copy link
Contributor Author

@swift-ci please test

earl pushed a commit to earl/llvm-mirror that referenced this pull request Dec 18, 2018
…nd skip over them

Looks like there are valid reasons why we need to allow bitcasts in llvm.asan.globals, see discussion at apple/swift-llvm#133. Let's look through bitcasts when iterating over entries in the llvm.asan.globals list.

Differential Revision: https://reviews.llvm.org/D55794



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349544 91177308-0d34-0410-b5e6-96231b3b80d8
@kubamracek kubamracek merged commit fe02928 into swift-5.0-branch Dec 19, 2018
@kubamracek kubamracek deleted the skip-invalid-entries-in-asan-globals branch December 19, 2018 03:17
llvm-git-migration pushed a commit to llvm-git-prototype/llvm-legacy-branches that referenced this pull request Jan 4, 2019
…nd skip over them

Looks like there are valid reasons why we need to allow bitcasts in llvm.asan.globals, see discussion at apple/swift-llvm#133. Let's look through bitcasts when iterating over entries in the llvm.asan.globals list.

Differential Revision: https://reviews.llvm.org/D55794

llvm-svn: 349544
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants