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

challenge: Decompile the c4 compiler, recompile it, and run them next to one another #185

Open
mewmew opened this issue Mar 23, 2017 · 1 comment
Milestone

Comments

@mewmew
Copy link
Member

mewmew commented Mar 23, 2017

The idea of the challenge issue series is to stress test the decompiler pipeline using semi-real world software.

First up in this series is the c4 compiler, a self-hosting C compiler written in four functions.

  1. Compile the c4 compiler using a binary produced from the original C source code of c4. Let the output file be called c4_by_c4.
  2. Recompile the original C source code of c4 using c4_by_c4 and validate that the output is byte identical with the first version of c4_by_c4.
  3. Use Clang to emit LLVM IR assembly for the C source code of c4.
  4. Decompile the LLVM IR assembly of the c4 compiler into Go source code.
  5. Compile the recovered Go source code of the c4 compiler, and let the output file be called c4_go.
  6. Compile the original C source code of the c4 compiler using c4_go. Let the output file be called c4_by_decomp.
  7. Validate that the binaries c4_by_c4 and c4_by_decomp are byte identical.
  8. ...
  9. profit :)

This challenge may not end up being feasible, if c4 does not produce byte identical output when recompiled with itself. In this case, see if there are only a few bytes at known offsets that differ (e.g. date timestamps).

@mewmew mewmew added this to the v0.3 milestone Mar 23, 2017
@mewmew
Copy link
Member Author

mewmew commented Mar 23, 2017

After having taken an initial look at c4, it seems as it is a C interpreter rather than a C compiler. As such, we may only compare the output from c4 and c4_go against each other. There are no c4_by_c4 and c4_by_decomp binaries to speak of, so we can't compare those for byte equality.

Still, may be a good initial challenge. Only have to adjust it so that c4 is invoked with C source files that produce interesting output.

@mewmew mewmew changed the title challenge: Decompile the c4 compiler, and recompile it producing byte identical output challenge: Decompile the c4 compiler, recompile it, and run them next to one another Mar 23, 2017
mewmew referenced this issue in cznic/ir May 6, 2017
* Add Switch operation.

* Finish switch branch.

Squashed commit of the following:

commit 49d5280dab8a4dbd13419360bc0bf992da444b4e
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 16:07:46 2017  0200

    WIPS

commit 127b35dd82c0980c591848280619ef6f6de5dd3f
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 15:31:35 2017  0200

    WIPS

commit 0205c8b377ff506fce92e1c128ede521b3d63d8e
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 15:19:27 2017  0200

    WIPS

commit 3acb0a215a1c61adc715d8b275f264756891cb83
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 15:14:38 2017  0200

    WIPS

commit 98f520c9c30ad150affecda390e52e13c906e344
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 03:04:06 2017  0200

    WIPS

commit 09a19e92dbc2142a94c3dd5a5ea491d410990260
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 02:37:28 2017  0200

    WIPS

commit 7ed7ce62f9f0381673b75e766ac4e96c109e6029
Author: Jan Mercl <[email protected]>
Date:   Sat Apr 29 00:20:55 2017  0200

    Try to fix "..\cc\testdata\tcc-0.9.26\tests\tests2\40_stdio.c:5:14: undefined fopen" on Windows.

commit 401ecab6670c777da18610f170a0621d4638a6b7
Author: Jan Mercl <[email protected]>
Date:   Fri Apr 28 22:27:25 2017  0200

    WIPS

commit f409c2dadc61ffef89d13f2c81ea6bdb17b6335c
Author: Jan Mercl <[email protected]>
Date:   Fri Apr 28 22:05:38 2017  0200

    WIPS
@mewmew mewmew modified the milestones: v0.3, v0.4 Jan 30, 2018
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