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

cmd/go-post: "unresolved: erroneous handling of global variables" #176

Open
mewmew opened this issue May 24, 2016 · 1 comment
Open

cmd/go-post: "unresolved: erroneous handling of global variables" #176

mewmew opened this issue May 24, 2016 · 1 comment

Comments

@mewmew
Copy link
Member

mewmew commented May 24, 2016

From @karlek on May 29, 2015 23:13

// a.go
package main

func main() {
    // go-post wants to change this to:
    // dx := 0
    // which shadows the global variable dx.
    dx = 0
}
// b.go
package main

var dx = 1
diff a.go fixed/a.go
--- /tmp/go-fix673596466    2015-05-30 00:41:51.888890332 +0200
+++ /tmp/go-fix613483497    2015-05-30 00:41:51.888890332 +0200
@@ -4,5 +4,5 @@
    // go-post wants to change this to:
    // dx := 0
    // which shadows the global variable dx.
-   dx = 0
+   dx := 0
 }

Copied from original issue: #2

@mewmew mewmew added the bug label May 24, 2016
@mewmew mewmew changed the title unresolved: erroneous handling of global variables. cmd/go-post: "unresolved: erroneous handling of global variables" May 24, 2016
@mewmew mewmew added this to the v0.2 milestone May 25, 2016
@mewmew
Copy link
Member Author

mewmew commented Sep 10, 2017

This issue will be solved through proper data-flow analysis, taking part in the middle-end module of the decompiler pipeline. The data flow analysis will be developed, similar to the control flow analysis component, as a stand-alone component which analyses the data dependencies between instructions, and outputs these dependencies in JSON format, for the back-end to make use of. As such, the back-end will have all information required to declare variables in their correct scope, and this will make is possible to remove the unresolved source code rewrite rule of go-post.

Several of the go-post rewrite rules are currently there as a poor man's data flow analysis substitute. Once proper data flow analysis is in place, the following rewrite rules will be removed from go-post:

  • deadassign
    • Remove "x = x" assignments
  • localid
    • Replace the use of local variable IDs with their definition.
  • unresolved
    • Replace assignment statements with declare and initialize statements at the first occurance of an unresolved identifier.

More specifically, the following rewrite rules are likely to remain, after both control flow analysis and data flow analysis reach maturity.

  • assignbinop
    • Replace "x = x + z" with "x += z".
  • forloop
    • Add initialization and post-statements to for-loops.
  • mainret
    • Replace return statements with calls to os.Exit in the "main" function.

Proper control flow analysis will remove the need for the deadlabel (i,e. Remove unused labels.) rewrite rule.

Updating the milestone of this issue to 0.5, as that release is intended to focus on data flow analysis. For a rough time frame, the intention is to start looking into data flow analysis for next year (2018). The autumn of 2017 is intended focus on control flow analysis (i.e. release 0.4). Release 0.2 is basically what is in the master branch right now. It will be tagged as such after some more testing (and potentially support for DWARF metadata in llir/llvm). Release 0.3 may be retargetted to happen after 0.5, depending on what is most fun to play with at the moment :)

@mewmew mewmew modified the milestones: v0.5, v0.2 Sep 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant