-
Notifications
You must be signed in to change notification settings - Fork 820
Make imported functions inexact #7993
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
base: main
Are you sure you want to change the base?
Changes from 60 commits
0967b41
7cbdfea
82ef0e0
d857e7d
d1d2ed8
e26f676
7fda8cf
5ce973b
4b167eb
7927749
160123e
b8bb97a
89103b9
24dea81
d4aabd2
a4fe585
76eac4c
020f119
21588c7
fdd7253
7a58395
4616380
46826b0
73024ea
4de7694
d03376d
82061c8
1859cf0
1791066
7278c6a
31573ac
b099733
34837c3
616b23a
46b9d70
8b5f7dd
c541380
982af15
e2de806
73bffc8
8931d56
c2f9d15
44faf20
719bf2c
c24956c
aea5996
e2d9c70
d360f0b
2d25b8d
bc122d5
5de1db0
61e0b66
8341afd
7d40a94
457b0e5
848151a
a6ff39a
e5081e3
b99dd75
87e1094
de14c6a
2802d94
33189d5
aab3067
aa7290d
89cf0c0
0a93101
03f7970
b77d0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| #include "ir/module-utils.h" | ||
| #include "ir/possible-contents.h" | ||
| #include "support/insert_ordered.h" | ||
| #include "wasm-type.h" | ||
| #include "wasm.h" | ||
|
|
||
| namespace std { | ||
|
|
@@ -641,9 +642,15 @@ struct InfoCollector | |
| addRoot(curr); | ||
| } | ||
| void visitRefFunc(RefFunc* curr) { | ||
| addRoot(curr, | ||
| PossibleContents::literal( | ||
| Literal::makeFunc(curr->func, curr->type.getHeapType()))); | ||
| if (!getModule()->getFunction(curr->func)->imported()) { | ||
| // This is not imported, so we know the exact function literal. | ||
| addRoot( | ||
| curr, | ||
| PossibleContents::literal(Literal::makeFunc(curr->func, *getModule()))); | ||
| } else { | ||
| // This is imported, so it might be anything of the proper type. | ||
| addRoot(curr); | ||
|
Comment on lines
+651
to
+652
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we still want to track that this is a reference to the imported function? It would just have an inexact type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But without knowing the identity, I think we can misoptimize? Imagine we have equality for a second, then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But functions references cannot be compared for equality, so there is nothing to misoptimize, unless I'm missing something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did say "imagine" 😆 But, while we don't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see how optimizations might see that two references are the same and e.g. merge two equivalent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, agreed. I'm not opposed to being conservative here to be on the safe side. But we should keep the less-conservative status quo in this PR to make sure we're not unexpectedly regressing optimizations due to just the introduction of inexact imported functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping the status quo does mean keeping the known cases of invalid optimization we have today, including the new (module
(type $func (sub (func)))
(type $sub (sub $func (func)))
(import "" "" (func $f (type $func)))
(func $test (export "test") (result i32)
(ref.test (ref $sub)
(ref.func $f)
)
)
)We misoptimize that to 0 before the fix, because we think imported function literals are actual concrete functions. Given such an actual function, we don't need exactness to know that it will fail that test. The fuzzer can find this after this PR - perhaps because of the new testcases? Or perhaps because of the companion fuzzing PR #7963, which should really land as it increases coverage enough to find those recent vulnerabilities. So while I see your point, our options seem to be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if GUFA has a function literal, but its type isn't exact? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still a literal. The code assumes that a literal is an actual identifiable thing, like 42 or the function "foo", and unlike a global "bar" (whose value we don't know). We could special-case the code to make it treat an inexact funcref as "a literal, but not really; more like a global." But that won't work once we have exact function imports - the same problem would happen with exact ones. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the problem. Once we have exact imports, then the Literal for the imported function would have an exact type iff the import is exact. GUFA would then look at the literal type to see whether casts would succeed or fail, for example. The changes to support inexact function literals are already in this PR. |
||
| } | ||
|
|
||
| // The presence of a RefFunc indicates the function may be called | ||
| // indirectly, so add the relevant connections for this particular function. | ||
|
|
@@ -1861,8 +1868,7 @@ void TNHOracle::infer() { | |
| // lot of other optimizations become possible anyhow. | ||
| auto target = possibleTargets[0]->name; | ||
| info.inferences[call->target] = | ||
| PossibleContents::literal(Literal::makeFunc( | ||
| target, wasm.getFunction(target)->type.getHeapType())); | ||
| PossibleContents::literal(Literal::makeFunc(target, wasm)); | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.