-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix Global Variables BNinja 4.0 #401
Conversation
Instructions for reviewer:
I would suggest by starting in pseudo/ and checking if the new types/fields make sense. Afterwards check the frontend and the new globals.py. All tests utilizing Globals needed an updated, because I changed the order of The global regex tests are partially removed as discussed. |
Still to do/discuss:
|
Found a few new things:
|
5fc348b
to
b2e1c5b
Compare
} | ||
self._lifted_globals: dict[int, GlobalVariable] = {} | ||
self._view: Optional[BinaryView] = None | ||
self._callers: list[int] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have the callers list, do we still need the cache?
I think they could interfere in a sense:
What if we have a chain A -> B -> C -> A. When we lift A, each Global will have cache entries with a chain up to Symbol(A). When we then later want to generate code, the output will depend on the lifting order, which is weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_lifted_globals
will have entries when the chain of global variables is already lifted (e.g. it goes from the most recent recursive call to the oldest one). => Can't be used to detect circles. Only needed when the same circle will be lifted twice (or more).
_callers
will have entries when we lift the chain. E.g. When we lift A, we see that the adress of A is already part of the circle and stop there. => Needed to detect the circle in the first place
And yes when we lift A a second time, it will have the same chain as before.
Why would that be a problem for generating the code at the backend?
The backend will collect all variables but strip the ssa labels of them, therefore duplicates will not occur.
Or am I missing your point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know that the cache is just for performance reasons. This should be explicitly noted in a comment.
My Point was, that when we lift A, it's lifted as A -> B -> C ->Symbol(A). When we next lift C, we get C -> Symbol(A) and not C -> A -> B -> Symbol(C). Therefore the length of these chains depends on the lifting order. But I'm not sure if this will negatively impact the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically correct and the down side from _lifted_globals
.
If we wanted to remove the problem completely we would need to step away from these chains of GlobalVariables in the first place.
E.g. only lift each initial_value as a reference and store all referenced GlobalVariables inside a datastructure.
Don't really know if it is worth it for the struggle, because literally no stage looks at the initial_value.
Maybe it's a good discussion point before we implement structs?
I moved a few methods between private and public (or not even part of the object) because other lifter handlers may need them (section functions). |
Co-authored-by: Manuel Blatt <[email protected]>
Restored Branch.