├── .gitattributes ├── .github └── workflows │ └── ci.yaml ├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── README.md ├── annotations ├── .gitignore ├── LICENSE ├── reopt-vcg-ann.cabal └── src │ └── Reopt │ └── VCG │ ├── Annotations.hs │ └── SMTParser.hs ├── cabal.project ├── cabal.project.freeze.ghc.8.10.7 ├── cabal.project.freeze.ghc.9.2.8 ├── cabal.project.freeze.ghc.9.4.8 ├── cabal.project.freeze.ghc.9.6.4 ├── cabal.project.freeze.ghc.9.8.2 ├── cabal.project.werror ├── cabal.project.werror-all ├── containers ├── dev-with-builds │ ├── Dockerfile │ └── README.md ├── dev │ └── Dockerfile ├── eval-with-examples │ ├── Dockerfile │ └── README.md ├── eval │ ├── .gitignore │ └── Dockerfile ├── occam │ └── Dockerfile └── vcg-dev │ └── Dockerfile ├── documentation ├── ArgumentAnalysis.md ├── DESIGN.md ├── Discovery.md ├── FunctionRecovery.md ├── HeaderResolution.md ├── LLVMBitcodeCompilation.md ├── ModuleConstraintsGeneration.md └── Recovery.md ├── examples ├── Makefile ├── division_by_zero ├── division_by_zero.c ├── empty_main │ ├── Makefile │ ├── README.md │ ├── artifacts │ │ ├── make.out │ │ └── reopt_tmp │ │ │ ├── empty_main_args_diet_clang.reopt │ │ │ ├── empty_main_args_diet_gcc.reopt │ │ │ ├── empty_main_no_args_diet_clang.reopt │ │ │ └── empty_main_no_args_diet_gcc.reopt │ ├── empty_main_args.c │ └── empty_main_no_args.c ├── hello_world │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── diet_redir.yaml │ ├── goodbye_world.c │ ├── goodbye_world_ubuntu_64_lts_12_05_diet.o │ ├── hello_world.c │ ├── hello_world_example.sh │ ├── hello_world_ubuntu_64_lts_12_04_diet │ ├── hello_world_ubuntu_64_lts_12_04_diet.o │ ├── hello_world_ubuntu_64_lts_12_04_glibc │ ├── hello_world_ubuntu_64_lts_12_04_musl │ ├── hello_world_ubuntu_64_lts_12_04_musl.o │ ├── redir_diet_goodbye_world.sh │ └── test-binaries │ │ ├── test-diet-bad-elf.x86_64-exe │ │ ├── test-diet-good-elf.x86_64-exe │ │ ├── test-diet-reopt.x86_64-exe │ │ └── test-diet-return-0.x86_64-exe ├── libnewt.so.0.52 ├── ls_ubuntu_64 ├── nweb23_static_freebsd ├── picoc │ ├── picoc-clang │ ├── picoc-diet-c99 │ ├── picoc-gcc │ └── picoc.md ├── simple ├── simple.cpp ├── test_1_a ├── test_1_b ├── test_add ├── test_mul ├── tests │ ├── README.md │ ├── fib_test.1234 │ ├── fib_test.123456 │ ├── fib_test.1234_123456.gpr_map │ ├── fib_test.1234_123456.rip_map │ ├── fib_test.c │ ├── identity.gpr_map │ ├── xor-nof.bc_map │ ├── xor-nof.c │ ├── xor-nof.rip_map │ ├── xor-nof1 │ ├── xor-nof2 │ ├── xorshift.1234 │ ├── xorshift.123456 │ ├── xorshift.1234_123456.gpr_map │ ├── xorshift.1234_123456.rip_map │ └── xorshift.c └── thttpd ├── fourmolu.yaml ├── hie.yaml ├── llvm-merge-example-ubuntu ├── Makefile ├── README.md ├── data.c ├── data.h ├── example │ ├── latest.txt │ ├── llvm-latest │ │ ├── _Exit_40268f.ll │ │ ├── _Exit_40268f.s │ │ ├── _IO_feof_unlocked_401d23.ll │ │ ├── _IO_feof_unlocked_401d23.s │ │ ├── __aio_close_402b2f.ll │ │ ├── __aio_close_402b2f.s │ │ ├── __copy_tls_4024e2.ll │ │ ├── __copy_tls_4024e2.s │ │ ├── __do_global_dtors_aux_400210.ll │ │ ├── __do_global_dtors_aux_400210.s │ │ ├── __errno_location_402681.ll │ │ ├── __errno_location_402681.s │ │ ├── __expand_heap_4026e0.ll │ │ ├── __expand_heap_4026e0.s │ │ ├── __fdopen_40284f.ll │ │ ├── __fdopen_40284f.s │ │ ├── __fmodeflags_4029ad.ll │ │ ├── __fmodeflags_4029ad.s │ │ ├── __funcs_on_exit_40083c.ll │ │ ├── __funcs_on_exit_40083c.s │ │ ├── __fwritex_402058.ll │ │ ├── __fwritex_402058.s │ │ ├── __init_libc_40068c.ll │ │ ├── __init_libc_40068c.s │ │ ├── __init_ssp_40068b.ll │ │ ├── __init_ssp_40068b.s │ │ ├── __init_tls_40255b.ll │ │ ├── __init_tls_40255b.s │ │ ├── __init_tp_402496.ll │ │ ├── __init_tp_402496.s │ │ ├── __libc_exit_fini_40083d.ll │ │ ├── __libc_exit_fini_40083d.s │ │ ├── __libc_start_init_4007e2.ll │ │ ├── __libc_start_init_4007e2.s │ │ ├── __libc_start_main_400802.ll │ │ ├── __libc_start_main_400802.s │ │ ├── __lock_4023a7.ll │ │ ├── __lock_4023a7.s │ │ ├── __lockfile_402a2c.ll │ │ ├── __lockfile_402a2c.s │ │ ├── __madvise_401b0a.ll │ │ ├── __madvise_401b0a.s │ │ ├── __malloc0_401860.ll │ │ ├── __malloc0_401860.s │ │ ├── __mremap_401bb6.ll │ │ ├── __mremap_401bb6.s │ │ ├── __munmap_401c4a.ll │ │ ├── __munmap_401c4a.s │ │ ├── __ofl_add_402d6a.ll │ │ ├── __ofl_add_402d6a.s │ │ ├── __ofl_lock_40217e.ll │ │ ├── __ofl_lock_40217e.s │ │ ├── __ofl_unlock_402190.ll │ │ ├── __ofl_unlock_402190.s │ │ ├── __overflow_402ac5.ll │ │ ├── __overflow_402ac5.s │ │ ├── __set_thread_area_402e57.ll │ │ ├── __set_thread_area_402e57.s │ │ ├── __simple_malloc_400860.ll │ │ ├── __simple_malloc_400860.s │ │ ├── __stdio_close_402b32.ll │ │ ├── __stdio_close_402b32.s │ │ ├── __stdio_exit_needed_402eb4.ll │ │ ├── __stdio_exit_needed_402eb4.s │ │ ├── __stdio_read_402b4f.ll │ │ ├── __stdio_read_402b4f.s │ │ ├── __stdio_seek_402bf3.ll │ │ ├── __stdio_seek_402bf3.s │ │ ├── __stdio_write_402c09.ll │ │ ├── __stdio_write_402c09.s │ │ ├── __syscall_ret_4026b0.ll │ │ ├── __syscall_ret_4026b0.s │ │ ├── __toread_402ee9.ll │ │ ├── __toread_402ee9.s │ │ ├── __toread_needs_stdio_exit_402f4f.ll │ │ ├── __toread_needs_stdio_exit_402f4f.s │ │ ├── __towrite_402ce8.ll │ │ ├── __towrite_402ce8.s │ │ ├── __towrite_needs_stdio_exit_402d2f.ll │ │ ├── __towrite_needs_stdio_exit_402d2f.s │ │ ├── __uflow_402d34.ll │ │ ├── __uflow_402d34.s │ │ ├── __unlist_locked_file_401c79.ll │ │ ├── __unlist_locked_file_401c79.s │ │ ├── __unlock_4023e2.ll │ │ ├── __unlock_4023e2.s │ │ ├── __unlockfile_402a80.ll │ │ ├── __unlockfile_402a80.s │ │ ├── __vm_wait_401b1f.ll │ │ ├── __vm_wait_401b1f.s │ │ ├── __wait_40241c.ll │ │ ├── __wait_40241c.s │ │ ├── _start_c_40016a.ll │ │ ├── _start_c_40016a.s │ │ ├── alloc_fwd_4009a0.ll │ │ ├── alloc_fwd_4009a0.ll.out │ │ ├── alloc_rev_400bf0.ll │ │ ├── alloc_rev_400bf0.ll.out │ │ ├── close_file_402e67.ll │ │ ├── close_file_402e67.s │ │ ├── deregister_tm_clones_400190.ll │ │ ├── deregister_tm_clones_400190.s │ │ ├── dummy_40068a.ll │ │ ├── dummy_40068a.s │ │ ├── dummy_401bb5.ll │ │ ├── dummy_401bb5.s │ │ ├── dummy_401c49.ll │ │ ├── dummy_401c49.s │ │ ├── exit_400130.ll │ │ ├── exit_400130.s │ │ ├── fclose_401c7a.ll │ │ ├── fclose_401c7a.s │ │ ├── fflush_401dbf.ll │ │ ├── fflush_401dbf.s │ │ ├── fflush_unlocked_401d55.ll │ │ ├── fflush_unlocked_401d55.s │ │ ├── fgetc_401e7c.ll │ │ ├── fgetc_401e7c.s │ │ ├── fopen64_401ee8.ll │ │ ├── fopen64_401ee8.s │ │ ├── fputc_401f8a.ll │ │ ├── fputc_401f8a.s │ │ ├── fputs_402023.ll │ │ ├── fputs_402023.s │ │ ├── frame_dummy_400230.ll │ │ ├── frame_dummy_400230.s │ │ ├── free_400e40.ll │ │ ├── free_400e40.ll.out │ │ ├── fwrite_402101.ll │ │ ├── fwrite_402101.s │ │ ├── log.txt │ │ ├── main_400603.ll │ │ ├── main_400603.s │ │ ├── malloc_401280.ll │ │ ├── malloc_401280.ll.out │ │ ├── memcpy_402375.ll │ │ ├── memcpy_402375.s │ │ ├── memset_402d93.ll │ │ ├── memset_402d93.s │ │ ├── mmap64_401b20.ll │ │ ├── mmap64_401b20.s │ │ ├── print_tree_400256.ll │ │ ├── print_tree_400256.s │ │ ├── read_tree_4005aa.ll │ │ ├── read_tree_4005aa.s │ │ ├── read_tree_payload_40041e.ll │ │ ├── read_tree_payload_40041e.s │ │ ├── realloc_4018b0.ll │ │ ├── realloc_4018b0.s │ │ ├── really_read_tree_400522.ll │ │ ├── really_read_tree_400522.s │ │ ├── really_write_tree_400335.ll │ │ ├── really_write_tree_400335.s │ │ ├── register_tm_clones_4001d0.ll │ │ ├── register_tm_clones_4001d0.s │ │ ├── strchr_4021a0.ll │ │ ├── strchr_4021a0.s │ │ ├── strchrnul_4021c0.ll │ │ ├── strchrnul_4021c0.s │ │ ├── strcmp_4022c0.ll │ │ ├── strcmp_4022c0.s │ │ ├── strlen_402300.ll │ │ ├── strlen_402300.s │ │ ├── tree_equal_4002a0.ll │ │ ├── tree_equal_4002a0.s │ │ ├── unknown_400120.ll │ │ ├── unknown_400120.s │ │ ├── unknown_400154.ll │ │ ├── unknown_400154.s │ │ ├── unknown_402f54.ll │ │ ├── unknown_402f54.s │ │ ├── write_tree_4003c1.ll │ │ └── write_tree_4003c1.s │ └── tmp │ │ ├── frankentree │ │ ├── original-tree │ │ ├── redirect_F40016a_to__start_c.s │ │ ├── redirect_F400603_to_main.s │ │ ├── redirect_F400802_to___libc_start_main.s │ │ ├── redirect_F40083d_to___libc_exit_fini.s │ │ ├── redirect_F400e40_to_free.s │ │ ├── redirect_F401280_to_malloc.s │ │ └── redirect_F4018b0_to_realloc.s ├── mk.sh └── tree.c ├── llvm-merge-example ├── .gitignore ├── Assembler.hs ├── Makefile ├── README.md ├── data.c ├── data.h ├── mk.sh ├── original-tree ├── original-tree.ll ├── tree.c └── tree.ll ├── llvm-testbed ├── README.md ├── memcmp │ ├── Makefile │ ├── main.c │ └── memcmp_4004ec.ll └── memcpy-and-strlen │ ├── Makefile │ ├── README.md │ ├── generator.c │ ├── main.c │ ├── memcpy_400645.ll │ ├── memcpy_400a28.ll │ ├── reopted-files-from-generator │ ├── memcpy_400645.ll │ └── strlen_4005d0.ll │ ├── reopted-files-from-hello-world │ ├── memcpy_400a28.ll │ └── strlen_4009b0.ll │ ├── strlen_4005d0.ll │ └── strlen_4009b0.ll ├── reopt-explore ├── CommandLine.hs ├── Common.hs ├── LLVM.hs ├── Main_explore.hs ├── Residual.hs └── Residual │ └── Recognizers.hs ├── reopt-relink └── Main_relink.hs ├── reopt.cabal ├── reopt └── Main_reopt.hs ├── reopt_test ├── Main_reopt.hs └── SignalUtils.hs ├── scratch └── shed.h ├── scripts ├── linux_binutils.sh ├── run_graphmod.sh ├── run_reopt.sh ├── run_residuals.sh ├── test_reopt.sh ├── test_reopt_explore.sh ├── test_reopt_with_relink.sh └── unpack_benchmarks.sh ├── src ├── Reopt.hs └── Reopt │ ├── Analysis │ └── Domains │ │ └── DiffEquations.hs │ ├── ArgResolver.hs │ ├── CFG │ ├── FnRep.hs │ ├── FnRep │ │ └── X86.hs │ ├── FunctionCheck.hs │ ├── LLVM.hs │ ├── LLVM │ │ └── X86.hs │ ├── Recovery.hs │ └── StackDepth.hs │ ├── Concrete │ └── BitVector.hs │ ├── ELFArchInfo.hs │ ├── EncodeInvariants.hs │ ├── Events.hs │ ├── Events │ └── Export.hs │ ├── ExternalTools.hs │ ├── FunUseMap.hs │ ├── Hints.hs │ ├── Occam.hs │ ├── PLTParser.hs │ ├── Relinker.hs │ ├── Relinker │ ├── Binary.hs │ ├── Constants.hs │ ├── NewBinary.hs │ ├── NewLayout.hs │ ├── NewSymtab.hs │ ├── Redirection.hs │ ├── Relations.hs │ └── Relocations.hs │ ├── Server.hs │ ├── TypeInference │ ├── ConstraintGen.hs │ ├── DebugTypes.hs │ ├── FunTypeMaps.hs │ ├── Header.hs │ ├── HeaderTypes.hs │ ├── Pretty.hs │ ├── Solver.hs │ └── Solver │ │ ├── Constraints.hs │ │ ├── Finalize.hs │ │ ├── Monad.hs │ │ ├── RowVariables.hs │ │ ├── Solver.hs │ │ ├── TypeVariables.hs │ │ ├── Types.hs │ │ └── UnionFindMap.hs │ ├── Utils │ ├── Dir.hs │ ├── Exit.hs │ ├── Flags.hs │ ├── Folds.hs │ ├── Hex.hs │ └── Printf.hs │ └── X86.hs ├── stats ├── .gitignore ├── README.rst ├── poetry.lock ├── pyproject.toml ├── stats │ ├── __init__.py │ ├── grammatech.py │ ├── main.py │ └── sheets.py └── tests │ ├── __init__.py │ └── test_stats.py ├── support ├── .gitignore ├── Makefile ├── README ├── abi_test.c ├── avx_intrin.512.c ├── llvm_return_test.ll ├── print_csize_info.c ├── print_stackheap_addrs.c ├── print_startup_info │ ├── Makefile │ ├── README │ ├── print_startup_info │ ├── print_startup_info.c │ ├── reopt_print_startup_info.sh │ ├── start.s │ └── write.s ├── test_except │ ├── .gitignore │ ├── Makefile │ └── test_except.cpp └── x86_llvm_asm_examples │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── test_movsd.c │ └── test_repstos.c ├── tests ├── Main.hs ├── README.rst ├── ReoptTests.hs ├── TyConstraintTests.hs ├── plan.org └── x64 │ ├── .gitignore │ ├── Makefile │ ├── test-conditional.c │ ├── test-conditional.exe │ ├── test-conditional.s │ ├── test-direct-calls.c │ ├── test-direct-calls.exe │ ├── test-direct-calls.s │ ├── test-indirect-call.c │ ├── test-indirect-call.exe │ ├── test-indirect-call.s │ ├── test-just-exit.c │ ├── test-just-exit.exe │ ├── test-just-exit.s │ ├── test-tail-call.c │ ├── test-tail-call.exe │ ├── test-tail-call.s │ └── util.h ├── tools ├── README.md ├── dump_debug_data │ └── Main.hs ├── dump_vtables │ └── Main.hs ├── reopt-checker │ ├── LICENSE │ ├── README.md │ ├── reopt-checker.cabal │ └── src │ │ └── Main.hs ├── reopt-tools.cabal └── utils │ ├── ConcreteDumpInstr.hs │ ├── cleaner.py │ ├── compare.sh │ ├── concrete-dump.sh │ ├── diffcleaner.py │ ├── dump_bytes.sh │ ├── dump_instr.sh │ ├── llvm-dump.sh │ └── mkbin.sh ├── typegen-test-programs ├── Makefile ├── README.md ├── byte_loop.c ├── make_in_docker.sh ├── mixed_struct_pointer.c ├── nested_mutual_rec_types.c ├── nested_struct_ptr.c ├── nested_struct_ptr.o ├── nested_struct_ptr2.c ├── simple_pointer.c ├── test.h ├── union_argument.c └── union_in_struct.c ├── vcg-test-programs ├── .gitignore ├── Makefile ├── README ├── diet │ ├── libc.a │ └── start.o ├── glibc │ ├── crt1.o │ ├── crti.o │ ├── libc.a │ ├── libgcc.a │ ├── libgcc_eh.a │ └── placeholder_initfini.c ├── nweb │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── content │ │ ├── index.html │ │ └── nweb.log │ ├── integration_test.sh │ ├── nweb.h │ ├── nweb23.c │ ├── nweb23.exe │ └── nweb23.manifest ├── test_add.bc ├── test_add.c ├── test_add.manifest ├── test_add_diet_ld.exe ├── test_add_diet_lld.ann ├── test_add_diet_lld.exe ├── test_add_glibc_lld.exe ├── test_add_protos.h ├── test_fib.c ├── test_fib.manifest ├── test_fib_diet_ld.exe ├── test_fib_diet_lld.ann ├── test_fib_diet_lld.exe ├── test_fib_protos.h ├── test_fpadd.c └── test_fpadd_protos.h └── vscode-plugin ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── README.md ├── assets ├── codicon-list-tree.png ├── reopt-diagnostics.png ├── reopt-full-window-annotated.png ├── reopt-full-window-project-file.png ├── reopt-full-window-vcg-diagnostics.png ├── reopt-full-window.png ├── reopt-generate-buttons.png ├── reopt-project-buttons.png └── reopt-vcg-diagnostics.png ├── example ├── .gitignore └── test_add_diet_lld.exe ├── package-lock.json ├── package.json ├── reopt-0.0.1.vsix ├── schemas └── rpj-schema.json ├── src ├── activity-webview │ ├── entry-point.tsx │ ├── tsconfig.json │ └── webview.tsx ├── extension │ ├── activity-message-handler.ts │ ├── activity-view-provider.ts │ ├── check-magic-number.ts │ ├── create-reopt-project.ts │ ├── main.ts │ ├── nonce.ts │ ├── open-reopt-project.ts │ ├── reopt-vcg-view-provider.ts │ ├── reopt-vcg.ts │ ├── reopt.ts │ ├── symbol-provider.ts │ ├── tree-data-provider.ts │ ├── tsconfig.json │ └── workspace-addresses.ts ├── reopt-vcg-webview │ ├── entry-point.tsx │ ├── tsconfig.json │ └── webview.tsx ├── shared │ ├── activity-webview-to-extension.ts │ ├── constants.ts │ ├── deserializers.ts │ ├── extension-to-activity-webview.ts │ ├── extension-to-reopt-vcg-webview.ts │ ├── interfaces.ts │ ├── package.json │ ├── project-configuration.ts │ ├── promisified.ts │ ├── reopt-vcg-webview-to-extension.ts │ ├── serializers.ts │ ├── tsconfig.json │ └── workspace-state.ts └── test │ ├── runTest.ts │ └── suite │ ├── extension.test.ts │ └── index.ts ├── tsconfig-common.json ├── tsconfig.json ├── webpack.config.ts └── webview-static ├── activity-webview.css ├── contents.html ├── nweb23.jsons └── webview.css /.gitattributes: -------------------------------------------------------------------------------- 1 | cabal.project.freeze* linguist-generated -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .direnv 2 | .envrc 3 | .ghcid 4 | .vscode 5 | /attic 6 | /cabal.project.freeze 7 | /cabal.project.local 8 | /dist-newstyle 9 | /hie.yml 10 | /scratch 11 | /TAGS 12 | /tar 13 | /typegen-test-programs/*.exe 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/dwarf"] 2 | path = deps/dwarf 3 | url = git@github.com:GaloisInc/dwarf.git 4 | [submodule "deps/elf-edit"] 5 | path = deps/elf-edit 6 | url = git@github.com:GaloisInc/elf-edit.git 7 | [submodule "deps/flexdis86"] 8 | path = deps/flexdis86 9 | url = git@github.com:GaloisInc/flexdis86.git 10 | [submodule "deps/llvm-pretty"] 11 | path = deps/llvm-pretty 12 | url = git@github.com:elliottt/llvm-pretty.git 13 | [submodule "deps/llvm-pretty-bc-parser"] 14 | path = deps/llvm-pretty-bc-parser 15 | url = git@github.com:GaloisInc/llvm-pretty-bc-parser.git 16 | [submodule "deps/macaw"] 17 | path = deps/macaw 18 | url = git@github.com:GaloisInc/macaw.git 19 | [submodule "deps/parameterized-utils"] 20 | path = deps/parameterized-utils 21 | url = git@github.com:GaloisInc/parameterized-utils.git 22 | [submodule "deps/reopt-vcg"] 23 | path = deps/reopt-vcg 24 | url = git@github.com:GaloisInc/reopt-vcg.git 25 | [submodule "deps/reopt-benchmark-binaries"] 26 | path = deps/reopt-benchmark-binaries 27 | url = git@github.com:GaloisInc/reopt-benchmark-binaries.git 28 | [submodule "deps/try-reopt"] 29 | path = deps/try-reopt 30 | url = https://github.com/GaloisInc/reopt.git 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2019 Galois Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of Galois, Inc. nor the names of its contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | tmp: 4 | mkdir -p tmp 5 | 6 | etags: tmp 7 | hasktags --ignore-close-implementation --etags --tags-absolute --output=tmp/TAGS src deps/*/src 8 | 9 | clean: 10 | -rm -rf tmp 11 | -------------------------------------------------------------------------------- /annotations/.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work -------------------------------------------------------------------------------- /annotations/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Galois Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of Galois, Inc. nor the names of its contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /annotations/reopt-vcg-ann.cabal: -------------------------------------------------------------------------------- 1 | name: reopt-vcg-ann 2 | version: 0.1.0.0 3 | synopsis: Annotation language that reopt generates for verification. 4 | description: This defines the core annotation language that reopt uses to generate annotations 5 | for the VCG. 6 | homepage: https://github.com/GaloisInc/reopt-vcg 7 | author: Joe Hendrix 8 | maintainer: Joe Hendrix 9 | copyright: 2018-2019 Galois, Inc 10 | category: binary analysis 11 | license: BSD3 12 | license-file: LICENSE 13 | build-type: Simple 14 | cabal-version: >= 1.10 15 | 16 | library 17 | hs-source-dirs: 18 | src 19 | build-depends: 20 | base >=4.7 && <5 21 | , aeson 22 | , attoparsec 23 | , containers 24 | -- flexdis86 used just for register names 25 | , flexdis86 26 | -- macaw-x86 only used for register names. 27 | , macaw-x86 28 | , scientific 29 | , text 30 | , unordered-containers 31 | , vector 32 | exposed-modules: 33 | Reopt.VCG.Annotations 34 | Reopt.VCG.SMTParser 35 | default-language: Haskell2010 -------------------------------------------------------------------------------- /cabal.project: -------------------------------------------------------------------------------- 1 | packages: 2 | reopt.cabal 3 | annotations 4 | tools 5 | tools/reopt-checker 6 | deps/dwarf 7 | deps/elf-edit 8 | deps/flexdis86 9 | deps/flexdis86/binary-symbols 10 | deps/llvm-pretty 11 | deps/llvm-pretty-bc-parser 12 | deps/macaw/base 13 | deps/macaw/x86 14 | deps/macaw/utils/compare-dwarfdump 15 | deps/parameterized-utils 16 | 17 | haddock-html-location: https://hackage.haskell.org/package/$pkg-$version/docs 18 | 19 | tests: true 20 | 21 | -- NOTE: This applies to the whole package: reopt and reopt-explore 22 | package reopt 23 | ghc-options: -Wall -Werror 24 | package reopt-tools 25 | ghc-options: -Wall 26 | package reopt-vcg-ann 27 | ghc-options: -Wall 28 | -------------------------------------------------------------------------------- /cabal.project.werror: -------------------------------------------------------------------------------- 1 | package reopt 2 | ghc-options: -Werror 3 | package reopt-tools 4 | ghc-options: -Werror 5 | package reopt-vcg-ann 6 | ghc-options: -Werror 7 | -------------------------------------------------------------------------------- /cabal.project.werror-all: -------------------------------------------------------------------------------- 1 | package reopt 2 | ghc-options: -Werror 3 | package reopt-tools 4 | ghc-options: -Werror 5 | package reopt-vcg-ann 6 | ghc-options: -Werror 7 | package macaw-base 8 | ghc-options: -Wall -Werror 9 | package elf-edit 10 | ghc-options: -Wall -Werror 11 | package galois-dwarf 12 | ghc-options: -Wall -Werror -------------------------------------------------------------------------------- /containers/dev-with-builds/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM galoisbinaryanalysisbot/reopt-vcg-dev 2 | 3 | # Install GHCUP 4 | ENV PATH=/root/.ghcup/bin:${PATH} 5 | 6 | RUN mkdir -p /root/.ghcup/bin 7 | RUN curl -o /root/.ghcup/bin/ghcup https://downloads.haskell.org/~ghcup/0.1.14.1/x86_64-linux-ghcup-0.1.14.1 \ 8 | && chmod a+x /root/.ghcup/bin/ghcup 9 | 10 | # Install GHC 11 | RUN ghcup install ghc 8.10.7 \ 12 | && ghcup install cabal 3.4.0.0 \ 13 | && ghcup set ghc 8.10.7 14 | 15 | COPY . /home/vadd/reopt 16 | 17 | WORKDIR /home/vadd/reopt 18 | 19 | RUN sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules 20 | RUN git submodule update --init 21 | RUN cabal update 22 | RUN cabal build exe:reopt exe:reopt-explore 23 | 24 | RUN cp /home/vadd/reopt-vcg/deps/cvc4-2020-09-16-x86_64-linux-opt /usr/local/bin/cvc4 25 | COPY ./containers/dev-with-builds/README.md /home/vadd 26 | WORKDIR /home/vadd 27 | -------------------------------------------------------------------------------- /containers/dev-with-builds/README.md: -------------------------------------------------------------------------------- 1 | # Reopt Dev Environment 2 | 3 | This Docker image contains the build tools and artifacts for `reopt` and `reopt-vcg` 4 | in `/home/vadd/reopt` and `/home/vadd/reopt-vcg` respectively. 5 | 6 | ## Reopt 7 | 8 | `reopt` and `reopt-explore` are implemented in Haskell and can be built from the 9 | `/home/vadd/reopt` directory using `cabal` via the command 10 | `cabal build exe:reopt exe:reopt-explore` and installed 11 | via `cabal install exe:reopt exe:reopt-explore`. After installation, the 12 | binary locations can be found using `cabal exec which $EXE` (where `$EXE` 13 | is `reopt` or `reopt-explore`). 14 | 15 | ## Reopt VCG 16 | 17 | `reopt-vcg` is implemented using the in-development Lean 4 programming language 18 | and a small amount of C++. The build script describes the precise snapshot of 19 | Lean 4 with which `reopt-vcg` can be built (it has been pre-installed in this 20 | container to avoid bit rot or other such issues which could arise over time). To 21 | build `reopt-vcg`, from the `/home/vadd/reopt-vcg` directory run the `build.sh` 22 | script. Once completed, the built executable will be found at 23 | `/home/vadd/reopt-vcg/build/bin/reopt-vcg`. 24 | -------------------------------------------------------------------------------- /containers/dev/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | # Install system libraries 4 | # https://www.haskell.org/ghcup/install/#version-2004-2010 5 | RUN apt update -y \ 6 | && apt install -y build-essential curl libffi-dev \ 7 | && apt install -y libffi7 libgmp-dev libgmp10 libncurses-dev \ 8 | && apt install -y libncurses5 libtinfo5 \ 9 | && apt install -y git lzma zlib1g-dev libghc-zlib-dev 10 | 11 | # Install GHCUP 12 | ENV PATH=/root/.ghcup/bin:${PATH} 13 | ARG ghcupVer=0.1.19.5 14 | ARG cabalVer=3.10.1.0 15 | ARG ghcVer=9.2.8 16 | 17 | RUN mkdir -p /root/.ghcup/bin 18 | RUN curl -o /root/.ghcup/bin/ghcup https://downloads.haskell.org/~ghcup/${ghcupVer}/x86_64-linux-ghcup-${ghcupVer} \ 19 | && chmod a+x /root/.ghcup/bin/ghcup 20 | 21 | # Install GHC 22 | RUN ghcup install ghc ${ghcVer} \ 23 | && ghcup install cabal ${cabalVer} \ 24 | && ghcup set ghc ${ghcVer} 25 | 26 | WORKDIR /root 27 | -------------------------------------------------------------------------------- /containers/eval-with-examples/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM galoisbinaryanalysis/reopt:latest 2 | 3 | COPY deps/try-reopt /root/deps/try-reopt 4 | COPY deps/reopt-benchmark-binaries /root/deps/reopt-benchmark-binaries 5 | COPY scripts/unpack_benchmarks.sh /root/scripts/unpack_benchmarks.sh 6 | COPY scripts/test_reopt.sh /root/scripts/test_reopt.sh 7 | COPY scripts/test_reopt_explore.sh /root/scripts/test_reopt_explore.sh 8 | COPY containers/eval-with-examples/README.md /root/README.md 9 | COPY README.md /root/reopt-README.md 10 | COPY deps/reopt-vcg/README.md /root/reopt-vcg-README.md 11 | RUN rm /root/deps/try-reopt/README.md 12 | 13 | WORKDIR /root 14 | -------------------------------------------------------------------------------- /containers/eval-with-examples/README.md: -------------------------------------------------------------------------------- 1 | # Reopt Docker Image 2 | 3 | This docker image contains the following Reopt related binaries 4 | in the user's PATH: 5 | 6 | ``` 7 | reopt 8 | reopt-explore 9 | reopt-vcg 10 | ``` 11 | 12 | Each binary has a CLI which can provide usage information 13 | via the `--help` flag. 14 | 15 | The `reopt-README.md` and `reopt-vcg-README.md` markdown files 16 | contain some high level documentation the respective tools. 17 | 18 | 19 | ## Simple Examples 20 | 21 | In `/root/deps/try-reopt/examples` there are a few subdirectories with simple 22 | example programs that `reopt` and `reopt-vcg` can be run on. To build the 23 | example programs and run `reopt` and `reopt-vcg`, simply run `make` in the 24 | respective subdirectory. 25 | 26 | The `/root/deps/reopt-benchmark-binaries` directory contains a compressed corpus 27 | of binaries and their dependencies from CentOS7 that can serve as example target 28 | programs for `reopt`. (See the scripts described in a later section for 29 | unpacking and exercising `reopt` on said binaries.) 30 | 31 | 32 | ## CentOS7 Binary Scripts 33 | 34 | The `/root/scripts` directory contains scripts that can be used to exercise 35 | Reopt's key functionality on CentOS7 binaries also included in this Docker image 36 | (i.e., in `/root/deps/reopt-benchmark-binaries`). 37 | 38 | The `test_reopt.sh` can be used to run reopt through function recovery on either 39 | `all` the included CentOS7 binaries, a `small` subset of the included binaries, 40 | or on particular subset of user specified binaries. 41 | 42 | Similarly, the `test_reopt.sh` can be used to run reopt through function 43 | recovery on either `all` the included CentOS7 binaries, a `small` subset of the 44 | included binaries, or on particular subset of user specified binaries. 45 | 46 | N.B., running the test scripts on `all` binaries can take a significant 47 | amount of time and resources. 48 | -------------------------------------------------------------------------------- /containers/eval/.gitignore: -------------------------------------------------------------------------------- 1 | /reopt 2 | /reopt.vsix -------------------------------------------------------------------------------- /containers/eval/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:focal 2 | 3 | RUN apt-get update \ 4 | && DEBIAN_FRONTEND=noninteractive TZ=UTC \ 5 | apt-get install -y --no-install-recommends \ 6 | llvm-8 clang-8 lld binutils cmake make openssh-client python git gdb lzma \ 7 | && rm -rf /var/lib/apt/lists/* 8 | RUN ln -s ../../lib/llvm-8/bin/opt /usr/local/bin 9 | RUN ln -s ../../lib/llvm-8/bin/llc /usr/local/bin 10 | RUN ln -s ../../lib/llvm-8/bin/llvm-mc /usr/local/bin 11 | RUN ln -s ../../lib/llvm-8/bin/clang /usr/local/bin 12 | COPY reopt/bin/reopt /usr/local/bin 13 | COPY reopt/bin/reopt-explore /usr/local/bin 14 | COPY reopt-vcg/bin/reopt-vcg /usr/local/bin 15 | COPY reopt-vcg/bin/cvc4 /usr/local/bin 16 | 17 | COPY reopt.vsix /usr/local/share/reopt/reopt.vsix 18 | WORKDIR /root 19 | -------------------------------------------------------------------------------- /containers/occam/Dockerfile: -------------------------------------------------------------------------------- 1 | # Pull base image. 2 | FROM buildpack-deps:focal 3 | 4 | RUN echo "Build type set to: $Release" && \ 5 | # Install deps. 6 | apt-get update && \ 7 | apt-get install -yqq software-properties-common && \ 8 | apt-get update && \ 9 | apt-get install -y wget libprotobuf-dev python-protobuf protobuf-compiler && \ 10 | apt-get install -y python3-pip && \ 11 | apt-get install -y cmake && \ 12 | apt-get install -y llvm-10 && \ 13 | apt-get install -y clang-10 && \ 14 | apt-get install -y clang-format-10 && \ 15 | apt-get install -y llvm-8 && \ 16 | apt-get install -y clang-8 && \ 17 | apt-get install -y lld && \ 18 | apt-get install -y binutils 19 | 20 | 21 | RUN pip3 --version && \ 22 | pip3 install setuptools --upgrade && \ 23 | pip3 install wheel && \ 24 | pip3 install protobuf && \ 25 | pip3 install lit 26 | RUN apt-get install -yqq libboost-dev 27 | 28 | RUN mkdir /go 29 | ENV GOPATH "/go" 30 | 31 | RUN apt-get -y install golang-go && \ 32 | go get github.com/SRI-CSL/gllvm/cmd/... 33 | 34 | ENV LLVM_HOME "/usr/lib/llvm-10" 35 | ENV PATH "$LLVM_HOME/bin:/bin:/usr/bin:/usr/local/bin:/occam/utils/FileCheck_trusty:$GOPATH/bin:$PATH" 36 | 37 | RUN cd / && rm -rf /occam && \ 38 | git clone --recurse-submodules https://github.com/SRI-CSL/OCCAM.git occam --depth=10 39 | 40 | WORKDIR /occam 41 | ENV CC clang 42 | ENV CXX clang++ 43 | ENV LLVM_COMPILER clang 44 | ENV WLLVM_OUTPUT WARNING 45 | ENV OCCAM_HOME "/occam" 46 | 47 | # Build configuration. 48 | RUN make 49 | RUN make install 50 | RUN make test 51 | 52 | 53 | # copy in reopt related binaries 54 | COPY reopt/bin/reopt /usr/local/bin 55 | COPY reopt/bin/reopt-relink /usr/local/bin 56 | COPY reopt/bin/reopt-vcg /usr/local/bin 57 | COPY reopt/bin/cvc4 /usr/local/bin 58 | -------------------------------------------------------------------------------- /containers/vcg-dev/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | # Install needed packages for building 4 | ARG DEBIAN_FRONTEND=noninteractive 5 | ENV TZ=America/Los_Angeles 6 | RUN apt-get update \ 7 | && DEBIAN_FRONTEND=noninteractive TZ=UTC \ 8 | apt-get install -y cmake ccache gcc g++ git \ 9 | libgmp-dev zlib1g-dev lib32z1-dev clang-8 llvm-8 10 | 11 | -------------------------------------------------------------------------------- /documentation/ArgumentAnalysis.md: -------------------------------------------------------------------------------- 1 | # X86 argument analysis 2 | 3 | This is just a very thin error-handling wrapper over Macaw's function demand 4 | analysis. The idea is that we want to know what registers every functions uses 5 | or sets, but we only get this information easily when we have access to C 6 | headers, ELF debug information, etc. In the absence of such information, we use 7 | Macaw's function demand analysis to compute what registers a function demands. 8 | 9 | We need this information to run Macaw's "register use" analysis (also called 10 | "block invariant inference") during [recovery](./Recovery.md), as Macaw wants an 11 | oracle for register usage by functions in order to compute register usage for 12 | every single block. 13 | 14 | ## Inputs 15 | - System call personality 16 | - A map resolving addresses to function names 17 | - A map resolving function names to their X86 function type 18 | - Final discovery state 19 | 20 | ## Outputs 21 | - A map from addresses to X86 function types (for those we suceeded) 22 | - A map from addresses to explanations for argument analysis failure 23 | 24 | ## How it works 25 | 26 | 1. For every function whose type we must infer, for every block of such function, 27 | `x86CallRegs` computes the registers that the block execution depends upon, 28 | relying on Macaw's `functionDemands` analysis. 29 | 30 | 2. We infer an X86 function type from the results of the demand analysis. 31 | Essentially this just follows the registers computed in the previous step, 32 | but it computes the necessary prefixes of contiguous registers necessary. 33 | For instance, if a function demands registers 0 and 3, we actually need to 34 | give it type (r0 -> r1 -> r2 -> r3 -> ret), supposedly to follow the calling 35 | convention. 36 | -------------------------------------------------------------------------------- /documentation/DESIGN.md: -------------------------------------------------------------------------------- 1 | # Reopt explained 2 | 3 | The overall goal of Reopt is to be able to lift a binary to some high-level 4 | representation, onto which one may perform program transformations, then to be 5 | able to recompile it. 6 | 7 | Basic blocks and the general control-flow graph are obtained through symbolic 8 | simulation via Macaw. One trick Reopt employs to succeed frequently is to just 9 | copy all blocks it failed to lift as is in the result binary. This way, failing 10 | to simulate some part of the program does not jeopardize the whole process. 11 | 12 | ## Reopt workflow 13 | 14 | Here is the very high-level view of what happens when we run Reopt with the 15 | expressed intent of producing an output object file. 16 | 17 | 1. C Headers are resolved, see [Header Resolution](./HeaderResolution.md) 18 | 19 | 2. We initialize Macaw's discovery with X86 support. 20 | 21 | 3. We make sure that no symbol in the binary starts with the prefix we will use 22 | to mark anonymous functions we recovered (usually it's just `reopt_`). 23 | 24 | 4. We proceed with [Discovery](./Discovery.md) of the code in the binary, 25 | leveraging Macaw's facilities. 26 | 27 | 5. We continue with [Recovery](./Recovery.md) of functions from the basic 28 | blocks we obtained through discovery and their pre- and post-execution 29 | symbolic states. 30 | 31 | 6. Module constraints are generated in order for us to do type 32 | inference/recovery, see [Module Constraints 33 | Generation](./ModuleConstraintsGeneration.md) 34 | 35 | 7. Modules are [compiled into LLVM bitcode](./LLVMBitcodeCompilation.md) based 36 | on all the information gathered. 37 | 38 | 8. An output object file is generated from the LLVM bitcode. 39 | -------------------------------------------------------------------------------- /documentation/Discovery.md: -------------------------------------------------------------------------------- 1 | # Discovery 2 | 3 | The point of discovery is to identify all functions available in a binary, given 4 | only information about at least one entry point. 5 | 6 | ## Inputs 7 | - Types from "Header resolution" 8 | - ELF header information 9 | - Architecture information 10 | - Initial discovery state 11 | - Reopt options 12 | 13 | ## Outputs 14 | - Map of function types 15 | - Final discovery state 16 | 17 | ## How it works 18 | 19 | 1. Parses the dynamic dependencies of the ELF header info, and computes the 20 | function type of external symbols. (`findDynamicDependencyDebugInfo`) 21 | 22 | 2. Builds the annotated function type map. (`headerTypeMap`) 23 | 24 | This includes: 25 | - types for functions declared in the [C header](./HeaderResolution.md), 26 | - types from dynamic dependencies found in the ELF header, 27 | - and some hardcoded types for some standard functions (as a crutch, 28 | particularly for printf-style functions). 29 | 30 | The map is actually made of multiple maps: 31 | - a bidirectional map between symbols names and addresses, 32 | - a map from external, undefined symbol names to their expected type, 33 | - a map from addresses that are function entries to their type, 34 | - something called a "no return map" in the code, that seems to be initialized 35 | with addresses that are believed to be function entry points. 36 | 37 | 3. Reopt computes additional function types using the ELF debug information. 38 | (`resolveDebugFunTypes`) 39 | 40 | 4. At this point, Reopt calls Macaw to run its incremental discovery algorithm 41 | (`incCompleteDiscovery`). From this comes back the Macaw `DiscoveryState`, 42 | which is the remaining piece for the final output. You can read more about 43 | Macaw code discovery 44 | [here](https://github.com/GaloisInc/macaw/blob/master/doc/Design.md#code-discovery). 45 | -------------------------------------------------------------------------------- /documentation/HeaderResolution.md: -------------------------------------------------------------------------------- 1 | # Header resolution 2 | 3 | Reopt can be helped by providing a C header file (for now, just one). This is 4 | because we can immediately tell what registers a function will need when called 5 | and use when returning just looking at the C signature of a function symbol. 6 | 7 | Without it, we must rely on successfully exploring all symbolic paths through 8 | the function execution to witness what registers are used, which may fail for a 9 | variety of reasons (see [Discovery](./Discovery.md)). 10 | 11 | The header resolution step builds an `AnnDeclarations` data type, which contains 12 | two maps: 13 | 14 | - `typeDefs`, a map resolving C `typedef`s to their C type (an `AnnType`), 15 | 16 | - `funDecls`, a map resolving function names to their C function type (an 17 | `AnnFunType`). 18 | 19 | The former is simply used to resolve the type of `typedef`-ed type aliases at 20 | their use sites. 21 | 22 | The latter is used during [discovery](./Discovery.md) to tell what registers a 23 | function will use. 24 | -------------------------------------------------------------------------------- /documentation/LLVMBitcodeCompilation.md: -------------------------------------------------------------------------------- 1 | # LLVM Bitcode Compilation 2 | 3 | TODO 4 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | default: nweb23_static_freebsd.ann 2 | 3 | .PHONY : default clean 4 | 5 | clean : 6 | rm -f nweb23_static_freebsd.ll nweb23_static_freebsd.ann 7 | 8 | 9 | # We use '-nostdlib' to get a minimal binary. 10 | division_by_zero: division_by_zero.c 11 | gcc -nostdlib $< -o $@ 12 | 13 | nweb23_static_freebsd.ll nweb23_static_freebsd.ann : nweb23_static_freebsd Makefile 14 | reopt -o nweb23_static_freebsd.ll \ 15 | --llvm \ 16 | --annotations nweb23_static_freebsd.ann \ 17 | --exclude extent_tree_ad_search \ 18 | --exclude grouping_print \ 19 | --exclude __build_env \ 20 | --exclude __sfvwrite \ 21 | --exclude catgets \ 22 | --exclude settzname \ 23 | --exclude __wrap_setrunelocale \ 24 | --exclude _Read_RuneMagi \ 25 | --exclude _collate_load_tables \ 26 | --exclude __part_load_locale \ 27 | --exclude bcopy \ 28 | --exclude memmove \ 29 | --exclude memcpy \ 30 | --exclude start \ 31 | --exclude init_aux \ 32 | $< 33 | 34 | nweb23_static_freebsd.bc : nweb23_static_freebsd.ll 35 | llvm-as -o=$@ $< 36 | -------------------------------------------------------------------------------- /examples/division_by_zero: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/division_by_zero -------------------------------------------------------------------------------- /examples/division_by_zero.c: -------------------------------------------------------------------------------- 1 | /* Division-by-zero example for testing processor exceptions and OS 2 | signals. 3 | 4 | The default Linux behavior is to send sigFPE to the process when it 5 | generated a division error (#DE) exception. 6 | */ 7 | int main(int argc, char *argv[]) { 8 | return 1/0; 9 | } 10 | -------------------------------------------------------------------------------- /examples/empty_main/artifacts/reopt_tmp/empty_main_args_diet_clang.reopt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/empty_main/artifacts/reopt_tmp/empty_main_args_diet_clang.reopt -------------------------------------------------------------------------------- /examples/empty_main/artifacts/reopt_tmp/empty_main_args_diet_gcc.reopt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/empty_main/artifacts/reopt_tmp/empty_main_args_diet_gcc.reopt -------------------------------------------------------------------------------- /examples/empty_main/artifacts/reopt_tmp/empty_main_no_args_diet_clang.reopt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/empty_main/artifacts/reopt_tmp/empty_main_no_args_diet_clang.reopt -------------------------------------------------------------------------------- /examples/empty_main/artifacts/reopt_tmp/empty_main_no_args_diet_gcc.reopt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/empty_main/artifacts/reopt_tmp/empty_main_no_args_diet_gcc.reopt -------------------------------------------------------------------------------- /examples/empty_main/empty_main_args.c: -------------------------------------------------------------------------------- 1 | int main(int argc, char **argv) { return 0; } 2 | -------------------------------------------------------------------------------- /examples/empty_main/empty_main_no_args.c: -------------------------------------------------------------------------------- 1 | int main() { return 0; } 2 | -------------------------------------------------------------------------------- /examples/hello_world/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | goodbye_world_diet.o 3 | goodbye_world 4 | hello_world_arm.o 5 | hello_world_arm.s 6 | hello_world_musl.o 7 | reopt_diet 8 | reopt_diet.blocks 9 | reopt_diet.fns 10 | reopt_diet.ll 11 | reopt_diet.o -------------------------------------------------------------------------------- /examples/hello_world/Makefile: -------------------------------------------------------------------------------- 1 | MUSL_ROOT=$(HOME)/opt/musl-freebsd 2 | CLANG=clang-3.5 3 | GCC=gcc-4.8 4 | 5 | all : hello_world hello_world_musl 6 | .PHONY : all 7 | 8 | # Build default target 9 | hello_world : hello_world.c Makefile 10 | $(CLANG) -static -o $@ $< 11 | 12 | ##################################################################### 13 | # musl related related environment variables and targets 14 | 15 | MUSL_CPP_FLAGS=-I$(MUSL_ROOT)/include 16 | MUSL_LD_FLAGS=-L$(MUSL_ROOT)/lib 17 | MUSL_LIBS=$(MUSL_ROOT)/lib/crt1.o $(MUSL_ROOT)/lib/crti.o $(MUSL_ROOT)/lib/crtn.o -lc 18 | 19 | hello_world_musl.o : hello_world.c Makefile 20 | $(CLANG) -static -nostdinc $(MUSL_CPP_FLAGS) -c -o $@ $< 21 | 22 | hello_world_musl : hello_world_musl.o Makefile 23 | $(CLANG) -static -nostdlib $(MUSL_LD_FLAGS) -o $@ $< $(MUSL_LIBS) 24 | 25 | 26 | ##################################################################### 27 | # diet libc related environment variables and targets 28 | 29 | DIET_ROOT=$(HOME)/software/dietlibc-0.33 30 | DIET_CPP_FLAGS=-I$(DIET_ROOT)/include 31 | DIET_LIB=$(DIET_ROOT)/bin-x86_64 32 | DIET_LD_FLAGS=-L$(DIET_LIB) 33 | DIET_LIBS=$(DIET_LIB)/start.o $(DIET_LIB)/dietlibc.a 34 | 35 | hello_world_diet.o : hello_world.c Makefile 36 | $(GCC) -static -nostdinc $(DIET_CPP_FLAGS) -c -o $@ $< 37 | 38 | goodbye_world_diet.o : goodbye_world.c Makefile 39 | $(GCC) -static -nostdinc $(DIET_CPP_FLAGS) -c -o $@ $< 40 | 41 | hello_world_diet : hello_world_diet.o Makefile $(DIET_LIBS) 42 | ld -static -nostdlib -o $@ $< $(DIET_LIBS) 43 | 44 | ##################################################################### 45 | # CLANG arm tests 46 | 47 | ARM_ABI=armv7a-none-eabi 48 | 49 | hello_world_arm.s : hello_world.c Makefile 50 | $(CLANG) -static -nostdlib -target $(ARM_ABI) -S -o $@ $< 51 | 52 | hello_world_arm.o : hello_world.c Makefile 53 | $(CLANG) -static -nostdlib -target $(ARM_ABI) -c -o $@ $< 54 | -------------------------------------------------------------------------------- /examples/hello_world/README: -------------------------------------------------------------------------------- 1 | This directory contains a minimal hello world example to test reopt. 2 | 3 | The Makefile uses clang-3.5, and has the ability to build with both 4 | the default libc and musl (by specifying MUSL_BASE to set the path). 5 | -------------------------------------------------------------------------------- /examples/hello_world/diet_redir.yaml: -------------------------------------------------------------------------------- 1 | - phdr : 0 2 | offset : 232 3 | target : main 4 | bytes_available : 20 -------------------------------------------------------------------------------- /examples/hello_world/goodbye_world.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | puts("Goodbye World!"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/hello_world/goodbye_world_ubuntu_64_lts_12_05_diet.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/goodbye_world_ubuntu_64_lts_12_05_diet.o -------------------------------------------------------------------------------- /examples/hello_world/hello_world.c: -------------------------------------------------------------------------------- 1 | 2 | int puts(const char *s); 3 | 4 | 5 | void h() { 6 | puts("Hello World!"); 7 | } 8 | 9 | void g() { 10 | h(); 11 | } 12 | 13 | void f() { 14 | g(); 15 | } 16 | 17 | int main(int argc, char** argv) { 18 | f(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /examples/hello_world/hello_world_example.sh: -------------------------------------------------------------------------------- 1 | # This script applies reopt to the Ubuntu diet example, and generates 2 | # intermediate files showing the different stages. 3 | #!/bin/bash 4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | 6 | set -e 7 | relink_output="reopt_diet" 8 | 9 | function check_path { 10 | (builtin type -P "$1" &> /dev/null) || (echo "Error: Could not find '$1' in path." && exit 1) 11 | } 12 | 13 | check_path "reopt" 14 | check_path "opt" 15 | check_path "llc" 16 | check_path "llvm-mc" 17 | 18 | 19 | reopt=$(which reopt) 20 | 21 | # Get reopt to just print out the basic blocks from discovery. 22 | $reopt "$DIR/hello_world_ubuntu_64_lts_12_04_diet" \ 23 | -o "$DIR/$relink_output.blocks" 24 | 25 | # Get reopt to just print out the functions that are discovered. 26 | $reopt "$DIR/hello_world_ubuntu_64_lts_12_04_diet" \ 27 | -o "$DIR/$relink_output.fns" 28 | 29 | # Get reopt to just print out the LLVM that is discovered. 30 | $reopt "$DIR/hello_world_ubuntu_64_lts_12_04_diet" \ 31 | -o "$DIR/$relink_output.ll" 32 | 33 | # Get reopt to create the object file. 34 | $reopt "$DIR/hello_world_ubuntu_64_lts_12_04_diet" \ 35 | -o "$DIR/$relink_output.o" 36 | 37 | # Get reopt to perform the full reoptimization script. 38 | $reopt "$DIR/hello_world_ubuntu_64_lts_12_04_diet" \ 39 | -o "$DIR/$relink_output" 40 | 41 | echo "Written relinked output to $relink_output" 42 | exit 0 43 | -------------------------------------------------------------------------------- /examples/hello_world/hello_world_ubuntu_64_lts_12_04_diet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/hello_world_ubuntu_64_lts_12_04_diet -------------------------------------------------------------------------------- /examples/hello_world/hello_world_ubuntu_64_lts_12_04_diet.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/hello_world_ubuntu_64_lts_12_04_diet.o -------------------------------------------------------------------------------- /examples/hello_world/hello_world_ubuntu_64_lts_12_04_glibc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/hello_world_ubuntu_64_lts_12_04_glibc -------------------------------------------------------------------------------- /examples/hello_world/hello_world_ubuntu_64_lts_12_04_musl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/hello_world_ubuntu_64_lts_12_04_musl -------------------------------------------------------------------------------- /examples/hello_world/hello_world_ubuntu_64_lts_12_04_musl.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/hello_world_ubuntu_64_lts_12_04_musl.o -------------------------------------------------------------------------------- /examples/hello_world/redir_diet_goodbye_world.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This script redirects main in the diet libc hello world to use the "Goodbye world" main. 3 | 4 | reopt --relink -r diet_redir.yaml -o goodbye_world hello_world_ubuntu_64_lts_12_04_diet --new goodbye_world_ubuntu_64_lts_12_05_diet.o 5 | -------------------------------------------------------------------------------- /examples/hello_world/test-binaries/test-diet-bad-elf.x86_64-exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/test-binaries/test-diet-bad-elf.x86_64-exe -------------------------------------------------------------------------------- /examples/hello_world/test-binaries/test-diet-good-elf.x86_64-exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/test-binaries/test-diet-good-elf.x86_64-exe -------------------------------------------------------------------------------- /examples/hello_world/test-binaries/test-diet-reopt.x86_64-exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/test-binaries/test-diet-reopt.x86_64-exe -------------------------------------------------------------------------------- /examples/hello_world/test-binaries/test-diet-return-0.x86_64-exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/hello_world/test-binaries/test-diet-return-0.x86_64-exe -------------------------------------------------------------------------------- /examples/libnewt.so.0.52: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/libnewt.so.0.52 -------------------------------------------------------------------------------- /examples/ls_ubuntu_64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/ls_ubuntu_64 -------------------------------------------------------------------------------- /examples/nweb23_static_freebsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/nweb23_static_freebsd -------------------------------------------------------------------------------- /examples/picoc/picoc-clang: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/picoc/picoc-clang -------------------------------------------------------------------------------- /examples/picoc/picoc-diet-c99: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/picoc/picoc-diet-c99 -------------------------------------------------------------------------------- /examples/picoc/picoc-gcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/picoc/picoc-gcc -------------------------------------------------------------------------------- /examples/simple: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/simple -------------------------------------------------------------------------------- /examples/simple.cpp: -------------------------------------------------------------------------------- 1 | class GrandParent { 2 | public: 3 | virtual int foo() { return 0; } 4 | virtual int bar() { return 20; } 5 | virtual int baz() { return 33; } 6 | }; 7 | 8 | class Parent : public GrandParent { 9 | public: 10 | virtual int foo() { return 1; } 11 | virtual int bar() { return 10; } 12 | }; 13 | 14 | class Child : public Parent { 15 | public: 16 | virtual int foo() { return 2; }; 17 | }; 18 | 19 | int main() { 20 | GrandParent *p0, *p1, *p2; 21 | 22 | p0 = new GrandParent; 23 | p1 = new Parent; 24 | p2 = new Child; 25 | 26 | int a = p0->foo(); 27 | int b = p1->foo(); 28 | int c = p2->foo(); 29 | int d = p0->bar(); 30 | int e = p1->bar(); 31 | int f = p2->bar(); 32 | int g = p0->baz(); 33 | int h = p1->baz(); 34 | int i = p2->baz(); 35 | 36 | delete p1; 37 | delete p2; 38 | } 39 | -------------------------------------------------------------------------------- /examples/test_1_a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/test_1_a -------------------------------------------------------------------------------- /examples/test_1_b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/test_1_b -------------------------------------------------------------------------------- /examples/test_add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/test_add -------------------------------------------------------------------------------- /examples/test_mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/test_mul -------------------------------------------------------------------------------- /examples/tests/README.md: -------------------------------------------------------------------------------- 1 | See :/radss_compare/README.md. 2 | -------------------------------------------------------------------------------- /examples/tests/fib_test.1234: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/tests/fib_test.1234 -------------------------------------------------------------------------------- /examples/tests/fib_test.123456: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/tests/fib_test.123456 -------------------------------------------------------------------------------- /examples/tests/fib_test.1234_123456.gpr_map: -------------------------------------------------------------------------------- 1 | fromList [(0,0),(3,3),(5,6),(14,14)] 2 | -------------------------------------------------------------------------------- /examples/tests/fib_test.1234_123456.rip_map: -------------------------------------------------------------------------------- 1 | fromList [(4198484,[4198469]),(4198511,[4198492])] 2 | -------------------------------------------------------------------------------- /examples/tests/fib_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main (int argc, char ** argv) { 5 | int count = strtol(argv[1], 0, 0); 6 | 7 | printf("%d\n", count); 8 | 9 | int x = 1, y = 0; 10 | for (int i = 0; i < count; i++) { 11 | int tmp = x; 12 | x = x+y; 13 | y = tmp; 14 | } 15 | printf ("%d\n", x); 16 | } 17 | -------------------------------------------------------------------------------- /examples/tests/identity.gpr_map: -------------------------------------------------------------------------------- 1 | fromList [(0, 0),(1, 1),(2, 2),(3, 3),(4, 4),(5, 5),(6, 6),(7, 7),(8, 8),(9, 9),(10, 10),(11, 11),(12, 12),(13, 13),(14, 14),(15, 15)] 2 | -------------------------------------------------------------------------------- /examples/tests/xor-nof.bc_map: -------------------------------------------------------------------------------- 1 | fromList [(4198496,4198496),(4198517,4198517),(4198557,4198545),(4198563,4198552),(4198570,4198559),(4198588,4198575),(4198608,4198589),(4198617,4198598),(4198623,4198610),(4198632,4198619),(4198672,4198654),(4198694,4198682),(4198699,4198682)] 2 | -------------------------------------------------------------------------------- /examples/tests/xor-nof.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main (int argc, char ** argv) { 6 | unsigned int x = 0x12345678, y = 0x23456789, z = 0x34567890, w = 0x4567890A; 7 | 8 | int count = argc; 9 | 10 | for (int i = 0; i < count; i++) { 11 | unsigned int t = x ^ (x<<11); 12 | x = y; 13 | y = z; 14 | z = w; 15 | w = w ^ (w >> 19) ^ t ^ (t >> 8); 16 | } 17 | 18 | return w; 19 | } 20 | -------------------------------------------------------------------------------- /examples/tests/xor-nof.rip_map: -------------------------------------------------------------------------------- 1 | fromList [(4198496, [4198496]), 2 | (4198570, [4198559]), 3 | (4198585, [4198574]), 4 | (4198691, [4198673])] 5 | -------------------------------------------------------------------------------- /examples/tests/xor-nof1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/tests/xor-nof1 -------------------------------------------------------------------------------- /examples/tests/xor-nof2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/tests/xor-nof2 -------------------------------------------------------------------------------- /examples/tests/xorshift.1234: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/tests/xorshift.1234 -------------------------------------------------------------------------------- /examples/tests/xorshift.123456: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/tests/xorshift.123456 -------------------------------------------------------------------------------- /examples/tests/xorshift.1234_123456.gpr_map: -------------------------------------------------------------------------------- 1 | fromList [(0,0),(8,9),(6,6),(7,7),(2,8),(1,2),(4,4),(5,5)] 2 | -------------------------------------------------------------------------------- /examples/tests/xorshift.1234_123456.rip_map: -------------------------------------------------------------------------------- 1 | fromList [(4198515,[4198520]),(4198454,[4198468]),(4198427,[4198437])] 2 | -------------------------------------------------------------------------------- /examples/tests/xorshift.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main (int argc, char ** argv) { 6 | unsigned int x = 0x12345678, y = 0x23456789, z = 0x34567890, w = 0x4567890A; 7 | 8 | int count = strtol(argv[1], 0, 0); 9 | 10 | for (int i = 0; i < count; i++) { 11 | unsigned int t = x ^ (x<<11); 12 | x = y; 13 | y = z; 14 | z = w; 15 | w = w ^ (w >> 19) ^ t ^ (t >> 8); 16 | } 17 | 18 | printf("%d\n", w); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /examples/thttpd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/examples/thttpd -------------------------------------------------------------------------------- /fourmolu.yaml: -------------------------------------------------------------------------------- 1 | comma-style: leading 2 | function-arrows: trailing 3 | haddock-style: single-line 4 | import-export-style: diff-friendly 5 | indentation: 2 6 | in-style: right-align 7 | let-style: mixed 8 | record-brace-space: false 9 | single-constraint-parens: never 10 | unicode: never 11 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: tmp/tree tmp/tree.ll 3 | 4 | CLANG=clang-3.5 5 | LLVM-DIS=llvm-dis35 6 | LLC=llc 7 | # LLC_FLAGS=-mtriple=x86_64-unknown-freebsd 8 | 9 | # LD=x86_64-unknown-freebsd-ld 10 | LD=ld 11 | 12 | tmp/tree: tmp/tree.o tmp/data.o | tmp 13 | $(LD) -o $@ $< 14 | 15 | tmp/data.bc: tree.c data.h | tmp 16 | $(CLANG) $(CFLAGS) -o $@ -c -emit-llvm -static tree.c 17 | 18 | tmp/tree.bc: tree.c data.h | tmp 19 | $(CLANG) $(CFLAGS) -o $@ -c -emit-llvm -static tree.c 20 | 21 | tmp/%.o : tmp/%.s | tmp 22 | $(AS) -o $@ $< 23 | 24 | tmp/%.s : tmp/%.bc | tmp 25 | $(LLC) $(LLC_FLAGS) -o $@ $< 26 | 27 | tmp/%.ll: tmp/%.bc | tmp 28 | $(LLVM-DIS) -o $@ $< 29 | 30 | clean: 31 | rm -f tmp 32 | 33 | tmp: 34 | mkdir -p tmp 35 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/README.md: -------------------------------------------------------------------------------- 1 | # LLVM merge example, Ubuntu version 2 | 3 | These examples were developed and tested on Ubuntu 15.10. 4 | 5 | This is based on `../llvm-merge-example`. See `README.md` there for 6 | more ideas. 7 | 8 | The main script `mk.sh` uses MUSL libc and its `musl-gcc` command. 9 | 10 | Do 11 | 12 | ./mk.sh 13 | 14 | to generate `tmp/original-tree` and `tmp/frankentree`. The former is a 15 | static compilation of `tree.c` and the latter is a compilation of 16 | `tree.c` together with a bunch of reopted versions of functions 17 | discovered by running reopt on `tmp/original-tree`. 18 | 19 | The files in this directory are as follows: 20 | 21 | - `tree.c`: the input C program. Functions are replaced by CPP macros 22 | which are replaced during compilation to form the variants; 23 | 24 | - `data.h`: defines the `tree` type and some strings; 25 | 26 | - `data.c`: not used right now; 27 | 28 | - `Makefile`: not used right now; 29 | 30 | - `mk.sh`: script that builds various versions of the program, 31 | defining the CPP macros as appropriate. It uses `musl-gcc`, so you 32 | need to install `musl`. 33 | 34 | - `example`: example output: 35 | 36 | - `llvm-latest` and `latest.txt`: copies of corresponding files from 37 | running `stack exec ../run-llvm.sh tmp/original-tree` as part of 38 | `./mk.sh`. 39 | 40 | - `tmp`: copy of `tmp` dir from running `./mk.sh`. 41 | 42 | - `tmp/frankentree`: copy of reassembled tree from running 43 | `./mk.sh`. 44 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/data.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains global data declarations. 3 | * 4 | * It is used so that the code does not contain separate copies of global data. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "data.h" 12 | 13 | struct tree g_left = { .left = NULL, .right = NULL, .payload = "left" }; 14 | struct tree g_right_right = { .left = NULL, .right = NULL, .payload = "right_right" }; 15 | struct tree g_right = { .left = NULL, .right = &g_right_right, .payload = "right" }; 16 | struct tree root = { .left = &g_left, .right = &g_right, .payload = "root" }; 17 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/data.h: -------------------------------------------------------------------------------- 1 | 2 | struct tree { 3 | struct tree* left; 4 | struct tree* right; 5 | const char* payload; 6 | }; 7 | const char sep = ','; 8 | const char* r_str = "r"; 9 | const char* w_str = "w"; 10 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/_Exit_40268f.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "_Exit_40268f.ll" 3 | .globl F40268f 4 | .align 16, 0x90 5 | .type F40268f,@function 6 | F40268f: # @F40268f 7 | .cfi_startproc 8 | # BB#0: # %block_40268f 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movslq %edi, %rdi 13 | movq $231, (%rsp) 14 | callq reopt.SystemCall.Linux 15 | .align 16, 0x90 16 | .LBB0_1: # %block_40269e 17 | # =>This Inner Loop Header: Depth=1 18 | movq $60, (%rsp) 19 | callq reopt.SystemCall.Linux 20 | jmp .LBB0_1 21 | .Ltmp1: 22 | .size F40268f, .Ltmp1-F40268f 23 | .cfi_endproc 24 | 25 | 26 | .section ".note.GNU-stack","",@progbits 27 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__aio_close_402b2f.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__aio_close_402b2f.ll" 3 | .globl F402b2f 4 | .align 16, 0x90 5 | .type F402b2f,@function 6 | F402b2f: # @F402b2f 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | movl %edi, %eax 10 | retq 11 | .Ltmp0: 12 | .size F402b2f, .Ltmp0-F402b2f 13 | .cfi_endproc 14 | 15 | 16 | .section ".note.GNU-stack","",@progbits 17 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__do_global_dtors_aux_400210.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__do_global_dtors_aux_400210.ll" 3 | .globl F400210 4 | .align 16, 0x90 5 | .type F400210,@function 6 | F400210: # @F400210 7 | .cfi_startproc 8 | # BB#0: # %block_400210 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | cmpb $0, 6308000 13 | jne .LBB0_2 14 | # BB#1: # %block_400222 15 | movd %xmm0, %rax 16 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 17 | movd %xmm0, %rcx 18 | movd %rax, %xmm0 19 | movd %rcx, %xmm1 20 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 21 | callq F400190 22 | movb $1, 6308000 23 | .LBB0_2: # %block_40022a 24 | addq $24, %rsp 25 | retq 26 | .Ltmp1: 27 | .size F400210, .Ltmp1-F400210 28 | .cfi_endproc 29 | 30 | 31 | .section ".note.GNU-stack","",@progbits 32 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__errno_location_402681.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__errno_location_402681.ll" 3 | .globl F402681 4 | .align 16, 0x90 5 | .type F402681,@function 6 | F402681: # @F402681 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | movd %xmm0, %rcx 10 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 11 | movd %xmm0, %rsi 12 | movq (%rax), %rax 13 | addq $68, %rax 14 | movd %rcx, %xmm0 15 | movd %rsi, %xmm1 16 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 17 | retq 18 | .Ltmp0: 19 | .size F402681, .Ltmp0-F402681 20 | .cfi_endproc 21 | 22 | 23 | .section ".note.GNU-stack","",@progbits 24 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__funcs_on_exit_40083c.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__funcs_on_exit_40083c.ll" 3 | .globl F40083c 4 | .align 16, 0x90 5 | .type F40083c,@function 6 | F40083c: # @F40083c 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | movd %xmm0, %rax 10 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 11 | movd %xmm0, %rcx 12 | movd %rax, %xmm0 13 | movd %rcx, %xmm1 14 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 15 | retq 16 | .Ltmp0: 17 | .size F40083c, .Ltmp0-F40083c 18 | .cfi_endproc 19 | 20 | 21 | .section ".note.GNU-stack","",@progbits 22 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__init_ssp_40068b.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__init_ssp_40068b.ll" 3 | .globl F40068b 4 | .align 16, 0x90 5 | .type F40068b,@function 6 | F40068b: # @F40068b 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | movd %xmm0, %rax 10 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 11 | movd %xmm0, %rcx 12 | movd %rax, %xmm0 13 | movd %rcx, %xmm1 14 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 15 | retq 16 | .Ltmp0: 17 | .size F40068b, .Ltmp0-F40068b 18 | .cfi_endproc 19 | 20 | 21 | .section ".note.GNU-stack","",@progbits 22 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__init_tp_402496.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__init_tp_402496.ll" 3 | .globl F402496 4 | .align 16, 0x90 5 | .type F402496,@function 6 | F402496: # @F402496 7 | .cfi_startproc 8 | # BB#0: # %block_4024a2 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $32, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 48 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | movq %rdi, %rbx 18 | movq %rbx, (%rbx) 19 | # kill: RDI RBX 20 | callq F402e57 21 | movl $4294967295, %eax # imm = 0xFFFFFFFF 22 | testl %eax, %eax 23 | js .LBB0_1 24 | # BB#2: # %block_4024a9 25 | testl %eax, %eax 26 | jne .LBB0_4 27 | # BB#3: # %block_4024ab 28 | movl $1, 6310272 29 | .LBB0_4: # %block_4024c0 30 | leaq 56(%rbx), %rdi 31 | movq $218, (%rsp) 32 | callq reopt.SystemCall.Linux 33 | movl %eax, 56(%rbx) 34 | leaq 224(%rbx), %rax 35 | movq $6310336, 256(%rbx) # imm = 0x6049C0 36 | movq %rax, 224(%rbx) 37 | xorl %eax, %eax 38 | # implicit-def: RCX 39 | # implicit-def: RDX 40 | jmp .LBB0_5 41 | .LBB0_1: 42 | movd %xmm0, %rcx 43 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 44 | movd %xmm0, %rdx 45 | .LBB0_5: # %block_4024de 46 | movd %rcx, %xmm0 47 | movd %rdx, %xmm1 48 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 49 | movq %rax, %rdx 50 | addq $32, %rsp 51 | popq %rbx 52 | retq 53 | .Ltmp3: 54 | .size F402496, .Ltmp3-F402496 55 | .cfi_endproc 56 | 57 | 58 | .section ".note.GNU-stack","",@progbits 59 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__libc_start_init_4007e2.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__libc_start_init_4007e2.ll" 3 | .globl F4007e2 4 | .align 16, 0x90 5 | .type F4007e2,@function 6 | F4007e2: # @F4007e2 7 | .cfi_startproc 8 | # BB#0: # %block_4007e2 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $16, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 32 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | callq F400120 18 | movd %xmm0, %rcx 19 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 20 | movd %xmm0, %rsi 21 | movl $6307816, %ebx # imm = 0x603FE8 22 | jmp .LBB0_1 23 | .align 16, 0x90 24 | .LBB0_2: # %block_4007fa 25 | # in Loop: Header=BB0_1 Depth=1 26 | movq %rax, %rdi 27 | movq %rdx, %rsi 28 | callq *(%rbx) 29 | movd %xmm0, %rcx 30 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 31 | movd %xmm0, %rsi 32 | addq $8, %rbx 33 | .LBB0_1: # %block_4007ed 34 | # =>This Inner Loop Header: Depth=1 35 | movd %rcx, %xmm0 36 | movd %rsi, %xmm1 37 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 38 | cmpq $6307823, %rbx # imm = 0x603FEF 39 | jbe .LBB0_2 40 | # BB#3: # %block_400800 41 | addq $16, %rsp 42 | popq %rbx 43 | retq 44 | .Ltmp3: 45 | .size F4007e2, .Ltmp3-F4007e2 46 | .cfi_endproc 47 | 48 | 49 | .section ".note.GNU-stack","",@progbits 50 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__libc_start_main_400802.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__libc_start_main_400802.ll" 3 | .globl F400802 4 | .align 16, 0x90 5 | .type F400802,@function 6 | F400802: # @F400802 7 | .cfi_startproc 8 | # BB#0: # %block_40083c 9 | pushq %r15 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | pushq %r14 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 24 15 | pushq %r12 16 | .Ltmp2: 17 | .cfi_def_cfa_offset 32 18 | pushq %rbx 19 | .Ltmp3: 20 | .cfi_def_cfa_offset 40 21 | subq $56, %rsp 22 | .Ltmp4: 23 | .cfi_def_cfa_offset 96 24 | .Ltmp5: 25 | .cfi_offset %rbx, -40 26 | .Ltmp6: 27 | .cfi_offset %r12, -32 28 | .Ltmp7: 29 | .cfi_offset %r14, -24 30 | .Ltmp8: 31 | .cfi_offset %r15, -16 32 | movq %rdx, %rbx 33 | movq %rdi, %r14 34 | movslq %esi, %r12 35 | movq (%rbx), %rsi 36 | leaq 8(%rbx,%r12,8), %r15 37 | movq %r15, %rdi 38 | callq F40068c 39 | movq %rax, %rdi 40 | movq %rdx, %rsi 41 | callq F4007e2 42 | movl %r12d, %edi 43 | movq %rbx, %rsi 44 | movq %r15, %rdx 45 | callq *%r14 46 | xorl %edi, %edi 47 | movq %rdx, %rsi 48 | callq F400130 49 | addq $56, %rsp 50 | popq %rbx 51 | popq %r12 52 | popq %r14 53 | popq %r15 54 | retq 55 | .Ltmp9: 56 | .size F400802, .Ltmp9-F400802 57 | .cfi_endproc 58 | 59 | 60 | .section ".note.GNU-stack","",@progbits 61 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__lock_4023a7.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__lock_4023a7.ll" 3 | .globl F4023a7 4 | .align 16, 0x90 5 | .type F4023a7,@function 6 | F4023a7: # @F4023a7 7 | .cfi_startproc 8 | # BB#0: # %block_4023a7 9 | pushq %r14 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | pushq %rbx 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 24 15 | subq $40, %rsp 16 | .Ltmp2: 17 | .cfi_def_cfa_offset 64 18 | .Ltmp3: 19 | .cfi_offset %rbx, -24 20 | .Ltmp4: 21 | .cfi_offset %r14, -16 22 | movq %rdi, %rbx 23 | movd %xmm0, %rax 24 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 25 | movd %xmm0, %rcx 26 | cmpl $0, 6310284 27 | je .LBB0_4 28 | # BB#1: # %block_4023b2 29 | leaq 4(%rbx), %r14 30 | movq %rdx, 16(%rsp) 31 | jmp .LBB0_2 32 | .align 16, 0x90 33 | .LBB0_3: # %block_4023c7 34 | # in Loop: Header=BB0_2 Depth=1 35 | movd %rax, %xmm0 36 | movd %rcx, %xmm1 37 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 38 | movl $1, %edx 39 | movl $1, %ecx 40 | movq %rbx, %rdi 41 | movq %r14, %rsi 42 | callq F40241c 43 | movd %xmm0, %rax 44 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 45 | movd %xmm0, %rcx 46 | .LBB0_2: # %block_4023bc 47 | # =>This Inner Loop Header: Depth=1 48 | cmpl $0, (%rbx) 49 | movl $1, (%rbx) 50 | jne .LBB0_3 51 | .LBB0_4: # %block_4023b1 52 | movd %rax, %xmm0 53 | movd %rcx, %xmm1 54 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 55 | addq $40, %rsp 56 | popq %rbx 57 | popq %r14 58 | retq 59 | .Ltmp5: 60 | .size F4023a7, .Ltmp5-F4023a7 61 | .cfi_endproc 62 | 63 | 64 | .section ".note.GNU-stack","",@progbits 65 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__madvise_401b0a.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__madvise_401b0a.ll" 3 | .globl F401b0a 4 | .align 16, 0x90 5 | .type F401b0a,@function 6 | F401b0a: # @F401b0a 7 | .cfi_startproc 8 | # BB#0: # %block_401b1d 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movslq %edx, %rdx 13 | movq $28, (%rsp) 14 | callq reopt.SystemCall.Linux 15 | movq %rax, %rdi 16 | callq F4026b0 17 | movq 16(%rsp), %rdx 18 | addq $24, %rsp 19 | retq 20 | .Ltmp1: 21 | .size F401b0a, .Ltmp1-F401b0a 22 | .cfi_endproc 23 | 24 | 25 | .section ".note.GNU-stack","",@progbits 26 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__malloc0_401860.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__malloc0_401860.ll" 3 | .globl F401860 4 | .align 16, 0x90 5 | .type F401860,@function 6 | F401860: # @F401860 7 | .cfi_startproc 8 | # BB#0: # %block_401869 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $16, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 32 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | movq %rdi, %rbx 18 | # kill: RDI RBX 19 | callq F401280 20 | testq %rax, %rax 21 | je .LBB0_6 22 | # BB#1: # %block_40186e 23 | testb $1, (%rax) 24 | je .LBB0_6 25 | # BB#2: # %block_401874 26 | addq $7, %rbx 27 | shrq $3, %rbx 28 | je .LBB0_6 29 | .align 16, 0x90 30 | .LBB0_3: # %block_401888 31 | # =>This Inner Loop Header: Depth=1 32 | cmpq $0, (%rax) 33 | je .LBB0_5 34 | # BB#4: # %block_40188e 35 | # in Loop: Header=BB0_3 Depth=1 36 | movq $0, (%rax) 37 | .LBB0_5: # %block_401895 38 | # in Loop: Header=BB0_3 Depth=1 39 | addq $8, %rax 40 | cmpq $1, %rbx 41 | leaq -1(%rbx), %rbx 42 | jne .LBB0_3 43 | .LBB0_6: # %block_40189f 44 | addq $16, %rsp 45 | popq %rbx 46 | retq 47 | .Ltmp3: 48 | .size F401860, .Ltmp3-F401860 49 | .cfi_endproc 50 | 51 | 52 | .section ".note.GNU-stack","",@progbits 53 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__munmap_401c4a.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__munmap_401c4a.ll" 3 | .globl F401c4a 4 | .align 16, 0x90 5 | .type F401c4a,@function 6 | F401c4a: # @F401c4a 7 | .cfi_startproc 8 | # BB#0: # %block_401c74 9 | subq $40, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 48 12 | movq %rdi, 24(%rsp) 13 | movq %rsi, 16(%rsp) 14 | callq F401b1f 15 | movq 16(%rsp), %rsi 16 | movq 24(%rsp), %rdi 17 | movq $11, (%rsp) 18 | callq reopt.SystemCall.Linux 19 | movq %rax, %rdi 20 | callq F4026b0 21 | addq $40, %rsp 22 | retq 23 | .Ltmp1: 24 | .size F401c4a, .Ltmp1-F401c4a 25 | .cfi_endproc 26 | 27 | 28 | .section ".note.GNU-stack","",@progbits 29 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__ofl_add_402d6a.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__ofl_add_402d6a.ll" 3 | .globl F402d6a 4 | .align 16, 0x90 5 | .type F402d6a,@function 6 | F402d6a: # @F402d6a 7 | .cfi_startproc 8 | # BB#0: # %block_402d73 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $16, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 32 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | movq %rdi, %rbx 18 | # kill: RDI RBX 19 | callq F40217e 20 | movd %xmm0, %rsi 21 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 22 | movd %xmm0, %rdi 23 | movq (%rax), %rcx 24 | movq %rcx, 112(%rbx) 25 | movq (%rax), %rcx 26 | testq %rcx, %rcx 27 | je .LBB0_2 28 | # BB#1: # %block_402d82 29 | movq %rbx, 104(%rcx) 30 | .LBB0_2: # %block_402d8e 31 | movq %rbx, (%rax) 32 | movd %rsi, %xmm0 33 | movd %rdi, %xmm1 34 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 35 | movq %rax, %rdi 36 | movq %rdx, %rsi 37 | movq %rcx, %rdx 38 | callq F402190 39 | movq %rbx, %rax 40 | addq $16, %rsp 41 | popq %rbx 42 | retq 43 | .Ltmp3: 44 | .size F402d6a, .Ltmp3-F402d6a 45 | .cfi_endproc 46 | 47 | 48 | .section ".note.GNU-stack","",@progbits 49 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__ofl_lock_40217e.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__ofl_lock_40217e.ll" 3 | .globl F40217e 4 | .align 16, 0x90 5 | .type F40217e,@function 6 | F40217e: # @F40217e 7 | .cfi_startproc 8 | # BB#0: # %block_402189 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movl $6309624, %edi # imm = 0x6046F8 13 | callq F4023a7 14 | movq 16(%rsp), %rdx 15 | movl $6309632, %eax # imm = 0x604700 16 | addq $24, %rsp 17 | retq 18 | .Ltmp1: 19 | .size F40217e, .Ltmp1-F40217e 20 | .cfi_endproc 21 | 22 | 23 | .section ".note.GNU-stack","",@progbits 24 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__ofl_unlock_402190.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__ofl_unlock_402190.ll" 3 | .globl F402190 4 | .align 16, 0x90 5 | .type F402190,@function 6 | F402190: # @F402190 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | pushq %rbp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | .Ltmp1: 13 | .cfi_offset %rbp, -16 14 | movq %rsp, %rbp 15 | .Ltmp2: 16 | .cfi_def_cfa_register %rbp 17 | movd %xmm0, %rax 18 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 19 | movd %xmm0, %rdi 20 | movd %rax, %xmm0 21 | movd %rdi, %xmm1 22 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 23 | movl $6309624, %edi # imm = 0x6046F8 24 | callq F4023e2 25 | movq %rbp, %rsp 26 | popq %rbp 27 | retq 28 | .Ltmp3: 29 | .size F402190, .Ltmp3-F402190 30 | .cfi_endproc 31 | 32 | 33 | .section ".note.GNU-stack","",@progbits 34 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__set_thread_area_402e57.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__set_thread_area_402e57.ll" 3 | .globl F402e57 4 | .align 16, 0x90 5 | .type F402e57,@function 6 | F402e57: # @F402e57 7 | .cfi_startproc 8 | # BB#0: # %block_402e66 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movq %rdi, %rax 13 | movq $158, (%rsp) 14 | movl $4098, %edi # imm = 0x1002 15 | movq %rax, %rsi 16 | callq reopt.SystemCall.Linux 17 | addq $24, %rsp 18 | retq 19 | .Ltmp1: 20 | .size F402e57, .Ltmp1-F402e57 21 | .cfi_endproc 22 | 23 | 24 | .section ".note.GNU-stack","",@progbits 25 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__stdio_close_402b32.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__stdio_close_402b32.ll" 3 | .globl F402b32 4 | .align 16, 0x90 5 | .type F402b32,@function 6 | F402b32: # @F402b32 7 | .cfi_startproc 8 | # BB#0: # %block_402b4d 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movl 120(%rdi), %edi 13 | callq F402b2f 14 | movq $3, (%rsp) 15 | xorl %edi, %edi 16 | callq reopt.SystemCall.Linux 17 | movq %rax, %rdi 18 | callq F4026b0 19 | addq $24, %rsp 20 | retq 21 | .Ltmp1: 22 | .size F402b32, .Ltmp1-F402b32 23 | .cfi_endproc 24 | 25 | 26 | .section ".note.GNU-stack","",@progbits 27 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__stdio_exit_needed_402eb4.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__stdio_exit_needed_402eb4.ll" 3 | .globl F402eb4 4 | .align 16, 0x90 5 | .type F402eb4,@function 6 | F402eb4: # @F402eb4 7 | .cfi_startproc 8 | # BB#0: # %block_402eba 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $16, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 32 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | callq F40217e 18 | movq %rdx, %rsi 19 | movd %xmm0, %rax 20 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 21 | movd %xmm0, %rcx 22 | movq (%rax), %rbx 23 | jmp .LBB0_1 24 | .align 16, 0x90 25 | .LBB0_2: # %block_402eca 26 | # in Loop: Header=BB0_1 Depth=1 27 | movd %rax, %xmm0 28 | movd %rcx, %xmm1 29 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 30 | movq %rbx, %rdi 31 | callq F402e67 32 | movd %xmm0, %rax 33 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 34 | movd %xmm0, %rcx 35 | movq 112(%rbx), %rbx 36 | # implicit-def: RSI 37 | .LBB0_1: # %block_402ebd 38 | # =>This Inner Loop Header: Depth=1 39 | testq %rbx, %rbx 40 | jne .LBB0_2 41 | # BB#3: # %block_402edc 42 | movq 6310216, %rdi 43 | movd %rax, %xmm0 44 | movd %rcx, %xmm1 45 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 46 | callq F402e67 47 | movq 6309616, %rdi 48 | callq F402e67 49 | addq $16, %rsp 50 | popq %rbx 51 | retq 52 | .Ltmp3: 53 | .size F402eb4, .Ltmp3-F402eb4 54 | .cfi_endproc 55 | 56 | 57 | .section ".note.GNU-stack","",@progbits 58 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__stdio_seek_402bf3.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__stdio_seek_402bf3.ll" 3 | .globl F402bf3 4 | .align 16, 0x90 5 | .type F402bf3,@function 6 | F402bf3: # @F402bf3 7 | .cfi_startproc 8 | # BB#0: # %block_402c01 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movslq 120(%rdi), %rdi 13 | movslq %edx, %rdx 14 | movq $8, (%rsp) 15 | callq reopt.SystemCall.Linux 16 | movq %rax, %rdi 17 | callq F4026b0 18 | addq $24, %rsp 19 | retq 20 | .Ltmp1: 21 | .size F402bf3, .Ltmp1-F402bf3 22 | .cfi_endproc 23 | 24 | 25 | .section ".note.GNU-stack","",@progbits 26 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__syscall_ret_4026b0.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__syscall_ret_4026b0.ll" 3 | .globl F4026b0 4 | .align 16, 0x90 5 | .type F4026b0,@function 6 | F4026b0: # @F4026b0 7 | .cfi_startproc 8 | # BB#0: # %block_4026b0 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $16, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 32 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | movq %rdi, %rbx 18 | movd %xmm0, %rax 19 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 20 | movd %xmm0, %rcx 21 | movd %rax, %xmm0 22 | movd %rcx, %xmm1 23 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 24 | cmpq $-4096, %rbx # imm = 0xFFFFFFFFFFFFF000 25 | jbe .LBB0_1 26 | # BB#3: # %block_4026c9 27 | movq %rbx, %rdi 28 | callq F402681 29 | negl %ebx 30 | movl %ebx, (%rax) 31 | movq $-1, %rax 32 | jmp .LBB0_2 33 | .LBB0_1: # %block_4026b9 34 | movq %rbx, %rax 35 | .LBB0_2: # %block_4026b9 36 | addq $16, %rsp 37 | popq %rbx 38 | retq 39 | .Ltmp3: 40 | .size F4026b0, .Ltmp3-F4026b0 41 | .cfi_endproc 42 | 43 | 44 | .section ".note.GNU-stack","",@progbits 45 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__toread_needs_stdio_exit_402f4f.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__toread_needs_stdio_exit_402f4f.ll" 3 | .globl F402f4f 4 | .align 16, 0x90 5 | .type F402f4f,@function 6 | F402f4f: # @F402f4f 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | pushq %rbp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | .Ltmp1: 13 | .cfi_offset %rbp, -16 14 | movq %rsp, %rbp 15 | .Ltmp2: 16 | .cfi_def_cfa_register %rbp 17 | movd %xmm0, %rax 18 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 19 | movd %xmm0, %rcx 20 | movd %rax, %xmm0 21 | movd %rcx, %xmm1 22 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 23 | callq F402eb4 24 | movq %rbp, %rsp 25 | popq %rbp 26 | retq 27 | .Ltmp3: 28 | .size F402f4f, .Ltmp3-F402f4f 29 | .cfi_endproc 30 | 31 | 32 | .section ".note.GNU-stack","",@progbits 33 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__towrite_402ce8.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__towrite_402ce8.ll" 3 | .globl F402ce8 4 | .align 16, 0x90 5 | .type F402ce8,@function 6 | F402ce8: # @F402ce8 7 | .cfi_startproc 8 | # BB#0: # %block_402ce8 9 | movd %xmm0, %r8 10 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 11 | movd %xmm0, %rcx 12 | movzbl 138(%rdi), %esi 13 | leaq -1(%rsi), %rax 14 | movl %eax, %edx 15 | orl %eax, %esi 16 | movb %sil, 138(%rdi) 17 | movl (%rdi), %esi 18 | testb $8, %sil 19 | je .LBB0_2 20 | # BB#1: # %block_402cff 21 | orl $32, %esi 22 | movl %esi, (%rdi) 23 | movd %r8, %xmm0 24 | movd %rcx, %xmm1 25 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 26 | movl $4294967295, %eax # imm = 0xFFFFFFFF 27 | retq 28 | .LBB0_2: # %block_402d08 29 | movq 88(%rdi), %rax 30 | movq $0, 16(%rdi) 31 | movq $0, 8(%rdi) 32 | movq %rax, 56(%rdi) 33 | movq %rax, 40(%rdi) 34 | addq 96(%rdi), %rax 35 | movq %rax, 32(%rdi) 36 | movd %r8, %xmm0 37 | movd %rcx, %xmm1 38 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 39 | xorl %eax, %eax 40 | retq 41 | .Ltmp0: 42 | .size F402ce8, .Ltmp0-F402ce8 43 | .cfi_endproc 44 | 45 | 46 | .section ".note.GNU-stack","",@progbits 47 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__towrite_needs_stdio_exit_402d2f.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__towrite_needs_stdio_exit_402d2f.ll" 3 | .globl F402d2f 4 | .align 16, 0x90 5 | .type F402d2f,@function 6 | F402d2f: # @F402d2f 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | pushq %rbp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | .Ltmp1: 13 | .cfi_offset %rbp, -16 14 | movq %rsp, %rbp 15 | .Ltmp2: 16 | .cfi_def_cfa_register %rbp 17 | movd %xmm0, %rax 18 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 19 | movd %xmm0, %rcx 20 | movd %rax, %xmm0 21 | movd %rcx, %xmm1 22 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 23 | callq F402eb4 24 | movq %rbp, %rsp 25 | popq %rbp 26 | retq 27 | .Ltmp3: 28 | .size F402d2f, .Ltmp3-F402d2f 29 | .cfi_endproc 30 | 31 | 32 | .section ".note.GNU-stack","",@progbits 33 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__uflow_402d34.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__uflow_402d34.ll" 3 | .globl F402d34 4 | .align 16, 0x90 5 | .type F402d34,@function 6 | F402d34: # @F402d34 7 | .cfi_startproc 8 | # BB#0: # %block_402d41 9 | pushq %r14 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | pushq %rbx 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 24 15 | subq $40, %rsp 16 | .Ltmp2: 17 | .cfi_def_cfa_offset 64 18 | .Ltmp3: 19 | .cfi_offset %rbx, -24 20 | .Ltmp4: 21 | .cfi_offset %r14, -16 22 | movq %rdi, %rbx 23 | # kill: RDI RBX 24 | callq F402ee9 25 | movd %xmm0, %rcx 26 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 27 | movd %xmm0, %rdx 28 | movl $4294967295, %eax # imm = 0xFFFFFFFF 29 | testl %eax, %eax 30 | jne .LBB0_3 31 | # BB#1: # %block_402d5a 32 | leaq 16(%rsp), %r14 33 | leaq 15(%r14), %rsi 34 | movd %rcx, %xmm0 35 | movd %rdx, %xmm1 36 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 37 | movl $1, %edx 38 | movq %rbx, %rdi 39 | callq *64(%rbx) 40 | movd %xmm0, %rcx 41 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 42 | movd %xmm0, %rdx 43 | movl $4294967295, %eax # imm = 0xFFFFFFFF 44 | cmpq $1, %rax 45 | jne .LBB0_3 46 | # BB#2: # %block_402d5f 47 | movzbl 15(%r14), %eax 48 | .LBB0_3: # %block_402d64 49 | movd %rcx, %xmm0 50 | movd %rdx, %xmm1 51 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 52 | addq $40, %rsp 53 | popq %rbx 54 | popq %r14 55 | retq 56 | .Ltmp5: 57 | .size F402d34, .Ltmp5-F402d34 58 | .cfi_endproc 59 | 60 | 61 | .section ".note.GNU-stack","",@progbits 62 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__unlist_locked_file_401c79.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__unlist_locked_file_401c79.ll" 3 | .globl F401c79 4 | .align 16, 0x90 5 | .type F401c79,@function 6 | F401c79: # @F401c79 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | movd %xmm0, %rax 10 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 11 | movd %xmm0, %rcx 12 | movd %rax, %xmm0 13 | movd %rcx, %xmm1 14 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 15 | retq 16 | .Ltmp0: 17 | .size F401c79, .Ltmp0-F401c79 18 | .cfi_endproc 19 | 20 | 21 | .section ".note.GNU-stack","",@progbits 22 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__unlock_4023e2.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__unlock_4023e2.ll" 3 | .globl F4023e2 4 | .align 16, 0x90 5 | .type F4023e2,@function 6 | F4023e2: # @F4023e2 7 | .cfi_startproc 8 | # BB#0: # %block_4023e2 9 | pushq %r15 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | pushq %r14 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 24 15 | pushq %rbx 16 | .Ltmp2: 17 | .cfi_def_cfa_offset 32 18 | subq $16, %rsp 19 | .Ltmp3: 20 | .cfi_def_cfa_offset 48 21 | .Ltmp4: 22 | .cfi_offset %rbx, -32 23 | .Ltmp5: 24 | .cfi_offset %r14, -24 25 | .Ltmp6: 26 | .cfi_offset %r15, -16 27 | movq %rdx, %r14 28 | movd %xmm0, %r15 29 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 30 | movd %xmm0, %rbx 31 | movl (%rdi), %eax 32 | testq %rax, %rax 33 | je .LBB0_4 34 | # BB#1: # %block_4023e8 35 | movl $0, (%rdi) 36 | movl 4(%rdi), %eax 37 | testq %rax, %rax 38 | je .LBB0_4 39 | # BB#2: # %block_40240d 40 | movq $202, (%rsp) 41 | movl $129, %esi 42 | movl $1, %edx 43 | movl $202, %r8d 44 | callq reopt.SystemCall.Linux 45 | cmpq $-38, %rax 46 | jne .LBB0_4 47 | # BB#3: # %block_402413 48 | movq $202, (%rsp) 49 | callq reopt.SystemCall.Linux 50 | .LBB0_4: # %block_40241b 51 | movd %r15, %xmm0 52 | movd %rbx, %xmm1 53 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 54 | movq %r14, %rdx 55 | addq $16, %rsp 56 | popq %rbx 57 | popq %r14 58 | popq %r15 59 | retq 60 | .Ltmp7: 61 | .size F4023e2, .Ltmp7-F4023e2 62 | .cfi_endproc 63 | 64 | 65 | .section ".note.GNU-stack","",@progbits 66 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__unlockfile_402a80.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__unlockfile_402a80.ll" 3 | .globl F402a80 4 | .align 16, 0x90 5 | .type F402a80,@function 6 | F402a80: # @F402a80 7 | .cfi_startproc 8 | # BB#0: # %block_402a80 9 | pushq %r14 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | pushq %rbx 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 24 15 | subq $24, %rsp 16 | .Ltmp2: 17 | .cfi_def_cfa_offset 48 18 | .Ltmp3: 19 | .cfi_offset %rbx, -24 20 | .Ltmp4: 21 | .cfi_offset %r14, -16 22 | movd %xmm0, %r14 23 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 24 | movd %xmm0, %rbx 25 | movl $0, 140(%rdi) 26 | movl 144(%rdi), %eax 27 | testq %rax, %rax 28 | je .LBB0_3 29 | # BB#1: # %block_402ab6 30 | addq $140, %rdi 31 | movq $202, (%rsp) 32 | movl $129, %esi 33 | movl $1, %edx 34 | movl $202, %r8d 35 | callq reopt.SystemCall.Linux 36 | cmpq $-38, %rax 37 | jne .LBB0_3 38 | # BB#2: # %block_402abc 39 | movq $202, (%rsp) 40 | callq reopt.SystemCall.Linux 41 | .LBB0_3: # %block_402ac4 42 | movd %r14, %xmm0 43 | movd %rbx, %xmm1 44 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 45 | xorl %edx, %edx 46 | addq $24, %rsp 47 | popq %rbx 48 | popq %r14 49 | retq 50 | .Ltmp5: 51 | .size F402a80, .Ltmp5-F402a80 52 | .cfi_endproc 53 | 54 | 55 | .section ".note.GNU-stack","",@progbits 56 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/__vm_wait_401b1f.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "__vm_wait_401b1f.ll" 3 | .globl F401b1f 4 | .align 16, 0x90 5 | .type F401b1f,@function 6 | F401b1f: # @F401b1f 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | retq 10 | .Ltmp0: 11 | .size F401b1f, .Ltmp0-F401b1f 12 | .cfi_endproc 13 | 14 | 15 | .section ".note.GNU-stack","",@progbits 16 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/_start_c_40016a.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "_start_c_40016a.ll" 3 | .globl F40016a 4 | .align 16, 0x90 5 | .type F40016a,@function 6 | F40016a: # @F40016a 7 | .cfi_startproc 8 | # BB#0: # %block_40018a 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | movq (%rdi), %rsi 13 | leaq 8(%rdi), %rdx 14 | movl $F400603, %edi 15 | callq F400802 16 | movq %rax, %rdi 17 | movq %rdx, %rsi 18 | callq F400190 19 | addq $24, %rsp 20 | retq 21 | .Ltmp1: 22 | .size F40016a, .Ltmp1-F40016a 23 | .cfi_endproc 24 | 25 | 26 | .section ".note.GNU-stack","",@progbits 27 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/alloc_fwd_4009a0.ll.out: -------------------------------------------------------------------------------- 1 | llc: alloc_fwd_4009a0.ll:184:19: error: '%R50' defined with type 'float' 2 | %R51 = zext i32 %R50 to i128 3 | ^ 4 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/alloc_rev_400bf0.ll.out: -------------------------------------------------------------------------------- 1 | llc: alloc_rev_400bf0.ll:182:19: error: '%R49' defined with type 'float' 2 | %R50 = zext i32 %R49 to i128 3 | ^ 4 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/deregister_tm_clones_400190.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "deregister_tm_clones_400190.ll" 3 | .globl F400190 4 | .align 16, 0x90 5 | .type F400190,@function 6 | F400190: # @F400190 7 | .cfi_startproc 8 | # BB#0: # %block_4001c0 9 | movl $7, %eax 10 | retq 11 | .Ltmp0: 12 | .size F400190, .Ltmp0-F400190 13 | .cfi_endproc 14 | 15 | 16 | .section ".note.GNU-stack","",@progbits 17 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/dummy_40068a.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "dummy_40068a.ll" 3 | .globl F40068a 4 | .align 16, 0x90 5 | .type F40068a,@function 6 | F40068a: # @F40068a 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | retq 10 | .Ltmp0: 11 | .size F40068a, .Ltmp0-F40068a 12 | .cfi_endproc 13 | 14 | 15 | .section ".note.GNU-stack","",@progbits 16 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/dummy_401bb5.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "dummy_401bb5.ll" 3 | .globl F401bb5 4 | .align 16, 0x90 5 | .type F401bb5,@function 6 | F401bb5: # @F401bb5 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | retq 10 | .Ltmp0: 11 | .size F401bb5, .Ltmp0-F401bb5 12 | .cfi_endproc 13 | 14 | 15 | .section ".note.GNU-stack","",@progbits 16 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/dummy_401c49.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "dummy_401c49.ll" 3 | .globl F401c49 4 | .align 16, 0x90 5 | .type F401c49,@function 6 | F401c49: # @F401c49 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | retq 10 | .Ltmp0: 11 | .size F401c49, .Ltmp0-F401c49 12 | .cfi_endproc 13 | 14 | 15 | .section ".note.GNU-stack","",@progbits 16 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/exit_400130.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "exit_400130.ll" 3 | .globl F400130 4 | .align 16, 0x90 5 | .type F400130,@function 6 | F400130: # @F400130 7 | .cfi_startproc 8 | # BB#0: # %block_40018a 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $32, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 48 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | movl %edi, 20(%rsp) 18 | leaq 8(%rsp), %rbx 19 | callq F40083c 20 | movq %rax, %rdi 21 | movq %rdx, %rsi 22 | callq F40083d 23 | movq %rax, %rdi 24 | movq %rdx, %rsi 25 | callq F402eb4 26 | movl 20(%rsp), %edi 27 | callq F40268f 28 | movq %rbx, %rdi 29 | callq F40016a 30 | movq (%rax), %rsi 31 | leaq 8(%rax), %rdx 32 | movl $F400603, %edi 33 | callq F400802 34 | movq %rax, %rdi 35 | movq %rdx, %rsi 36 | callq F400190 37 | addq $32, %rsp 38 | popq %rbx 39 | retq 40 | .Ltmp3: 41 | .size F400130, .Ltmp3-F400130 42 | .cfi_endproc 43 | 44 | 45 | .section ".note.GNU-stack","",@progbits 46 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/fputs_402023.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "fputs_402023.ll" 3 | .globl F402023 4 | .align 16, 0x90 5 | .type F402023,@function 6 | F402023: # @F402023 7 | .cfi_startproc 8 | # BB#0: # %block_402048 9 | pushq %r14 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | pushq %rbx 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 24 15 | subq $40, %rsp 16 | .Ltmp2: 17 | .cfi_def_cfa_offset 64 18 | .Ltmp3: 19 | .cfi_offset %rbx, -24 20 | .Ltmp4: 21 | .cfi_offset %r14, -16 22 | movq %rsi, %r14 23 | movq %rdi, %rbx 24 | # kill: RDI RBX 25 | callq F402300 26 | movl $1, %esi 27 | movq %rbx, %rdi 28 | movq %r14, %rcx 29 | callq F402101 30 | addq $40, %rsp 31 | popq %rbx 32 | popq %r14 33 | retq 34 | .Ltmp5: 35 | .size F402023, .Ltmp5-F402023 36 | .cfi_endproc 37 | 38 | 39 | .section ".note.GNU-stack","",@progbits 40 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/frame_dummy_400230.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "frame_dummy_400230.ll" 3 | .globl F400230 4 | .align 16, 0x90 5 | .type F400230,@function 6 | F400230: # @F400230 7 | .cfi_startproc 8 | # BB#0: # %block_40023b 9 | pushq %rax 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | callq F4001d0 13 | popq %rcx 14 | retq 15 | .Ltmp1: 16 | .size F400230, .Ltmp1-F400230 17 | .cfi_endproc 18 | 19 | 20 | .section ".note.GNU-stack","",@progbits 21 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/free_400e40.ll.out: -------------------------------------------------------------------------------- 1 | llc: free_400e40.ll:371:20: error: '%R133' defined with type 'float' 2 | %R134 = zext i32 %R133 to i128 3 | ^ 4 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/main_400603.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "main_400603.ll" 3 | .globl F400603 4 | .align 16, 0x90 5 | .type F400603,@function 6 | F400603: # @F400603 7 | .cfi_startproc 8 | # BB#0: # %block_400603 9 | subq $56, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 64 12 | movd %xmm0, %r8 13 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 14 | movd %xmm0, %r9 15 | movl %edi, 28(%rsp) 16 | movq %rsi, 16(%rsp) 17 | movl 28(%rsp), %ecx 18 | movl %ecx, %edi 19 | decl %edi 20 | seto %al 21 | cmpl $0, %edi 22 | seto %r10b 23 | cmpl $1, %ecx 24 | je .LBB0_2 25 | # BB#1: # %block_400603 26 | orb %r10b, %al 27 | shrl $31, %edi 28 | xorb %al, %dil 29 | movzbl %dil, %eax 30 | cmpl $1, %eax 31 | jne .LBB0_3 32 | .LBB0_2: # %block_400618 33 | movd %r8, %xmm0 34 | movd %r9, %xmm1 35 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 36 | movl $158, %edi 37 | callq F400130 38 | movd %xmm0, %r8 39 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 40 | movd %xmm0, %r9 41 | .LBB0_3: # %block_400680 42 | movq 16(%rsp), %rax 43 | movq 8(%rax), %rax 44 | movq %rax, 32(%rsp) 45 | movd %r8, %xmm0 46 | movd %r9, %xmm1 47 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 48 | xorl %edi, %edi 49 | movl $6307968, %esi # imm = 0x604080 50 | callq F400256 51 | movq 32(%rsp), %rdi 52 | movl $6307968, %esi # imm = 0x604080 53 | callq F4003c1 54 | movq 32(%rsp), %rdi 55 | callq F4005aa 56 | xorl %edi, %edi 57 | callq F400256 58 | movq 40(%rsp), %rsi 59 | movl $6307968, %edi # imm = 0x604080 60 | callq F4002a0 61 | addq $56, %rsp 62 | retq 63 | .Ltmp1: 64 | .size F400603, .Ltmp1-F400603 65 | .cfi_endproc 66 | 67 | 68 | .section ".note.GNU-stack","",@progbits 69 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/malloc_401280.ll.out: -------------------------------------------------------------------------------- 1 | llc: malloc_401280.ll:1782:20: error: '%R692' defined with type 'float' 2 | %R693 = zext i32 %R692 to i128 3 | ^ 4 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/print_tree_400256.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "print_tree_400256.ll" 3 | .globl F400256 4 | .align 16, 0x90 5 | .type F400256,@function 6 | F400256: # @F400256 7 | .cfi_startproc 8 | # BB#0: # %block_400256 9 | subq $40, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 48 12 | movd %xmm0, %rax 13 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 14 | movd %xmm0, %rcx 15 | movl %edi, 28(%rsp) 16 | movq %rsi, 16(%rsp) 17 | testq %rsi, %rsi 18 | je .LBB0_2 19 | # BB#1: # %block_400283 20 | movq 16(%rsp), %rdx 21 | movq (%rdx), %rsi 22 | movl 28(%rsp), %edi 23 | incl %edi 24 | movd %rax, %xmm0 25 | movd %rcx, %xmm1 26 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 27 | callq F400256 28 | movq 16(%rsp), %rax 29 | movq 8(%rax), %rsi 30 | movl 28(%rsp), %edi 31 | incl %edi 32 | callq F400256 33 | movd %xmm0, %rax 34 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 35 | movd %xmm0, %rcx 36 | .LBB0_2: # %block_40029e 37 | movd %rax, %xmm0 38 | movd %rcx, %xmm1 39 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 40 | addq $40, %rsp 41 | retq 42 | .Ltmp1: 43 | .size F400256, .Ltmp1-F400256 44 | .cfi_endproc 45 | 46 | 47 | .section ".note.GNU-stack","",@progbits 48 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/read_tree_4005aa.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "read_tree_4005aa.ll" 3 | .globl F4005aa 4 | .align 16, 0x90 5 | .type F4005aa,@function 6 | F4005aa: # @F4005aa 7 | .cfi_startproc 8 | # BB#0: # %block_4005cc 9 | subq $56, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 64 12 | movq %rdi, 24(%rsp) 13 | movq 6307856, %rsi 14 | movq %rsi, %rdx 15 | callq F401ee8 16 | movd %xmm0, %rax 17 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 18 | movd %xmm0, %rcx 19 | testq %rax, %rax 20 | jne .LBB0_2 21 | # BB#1: # %block_4005d7 22 | movd %rax, %xmm0 23 | movd %rcx, %xmm1 24 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 25 | movl $147, %edi 26 | movq %rdx, %rsi 27 | callq F400130 28 | movd %xmm0, %rax 29 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 30 | movd %xmm0, %rcx 31 | .LBB0_2: # %block_4005fd 32 | movq 32(%rsp), %rdi 33 | movd %rax, %xmm0 34 | movd %rcx, %xmm1 35 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 36 | movq %rdx, %rsi 37 | callq F400522 38 | movq 32(%rsp), %rdi 39 | movq %rdx, %rsi 40 | callq F401c7a 41 | movq 40(%rsp), %rax 42 | addq $56, %rsp 43 | retq 44 | .Ltmp1: 45 | .size F4005aa, .Ltmp1-F4005aa 46 | .cfi_endproc 47 | 48 | 49 | .section ".note.GNU-stack","",@progbits 50 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/register_tm_clones_4001d0.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "register_tm_clones_4001d0.ll" 3 | .globl F4001d0 4 | .align 16, 0x90 5 | .type F4001d0,@function 6 | F4001d0: # @F4001d0 7 | .cfi_startproc 8 | # BB#0: # %block_400208 9 | retq 10 | .Ltmp0: 11 | .size F4001d0, .Ltmp0-F4001d0 12 | .cfi_endproc 13 | 14 | 15 | .section ".note.GNU-stack","",@progbits 16 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/strchr_4021a0.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "strchr_4021a0.ll" 3 | .globl F4021a0 4 | .align 16, 0x90 5 | .type F4021a0,@function 6 | F4021a0: # @F4021a0 7 | .cfi_startproc 8 | # BB#0: # %block_4021a8 9 | pushq %rbx 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | subq $16, %rsp 13 | .Ltmp1: 14 | .cfi_def_cfa_offset 32 15 | .Ltmp2: 16 | .cfi_offset %rbx, -16 17 | movq %rsi, %rbx 18 | # kill: RSI RBX 19 | callq F4021c0 20 | movd %xmm0, %rax 21 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 22 | movd %xmm0, %rcx 23 | movzbl (%rax), %edx 24 | movzbl %bl, %esi 25 | cmpl %esi, %edx 26 | movd %rax, %xmm0 27 | movd %rcx, %xmm1 28 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 29 | xorl %eax, %eax 30 | xorl %edx, %edx 31 | addq $16, %rsp 32 | popq %rbx 33 | retq 34 | .Ltmp3: 35 | .size F4021a0, .Ltmp3-F4021a0 36 | .cfi_endproc 37 | 38 | 39 | .section ".note.GNU-stack","",@progbits 40 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/strcmp_4022c0.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "strcmp_4022c0.ll" 3 | .globl F4022c0 4 | .align 16, 0x90 5 | .type F4022c0,@function 6 | F4022c0: # @F4022c0 7 | .cfi_startproc 8 | # BB#0: # %block_4022c0 9 | movzbl (%rdi), %ecx 10 | movzbl (%rsi), %eax 11 | cmpl %ecx, %eax 12 | jne .LBB0_5 13 | # BB#1: # %subblock_4022c0_1 14 | incq %rdi 15 | incq %rsi 16 | xorl %ecx, %ecx 17 | jmp .LBB0_4 18 | .align 16, 0x90 19 | .LBB0_3: # %subblock_4022d0_2 20 | # in Loop: Header=BB0_4 Depth=1 21 | incq %rdi 22 | incq %rsi 23 | .LBB0_4: # %block_4022e2 24 | # =>This Inner Loop Header: Depth=1 25 | testb %al, %al 26 | je .LBB0_5 27 | # BB#2: # %block_4022d0 28 | # in Loop: Header=BB0_4 Depth=1 29 | movzbl (%rdi), %eax 30 | movzbl (%rsi), %edx 31 | cmpl %edx, %eax 32 | je .LBB0_3 33 | # BB#6: # %block_4022f0 34 | subl %edx, %eax 35 | retq 36 | .LBB0_5: # %block_4022e8 37 | subl %eax, %ecx 38 | movq %rcx, %rax 39 | retq 40 | .Ltmp0: 41 | .size F4022c0, .Ltmp0-F4022c0 42 | .cfi_endproc 43 | 44 | 45 | .section ".note.GNU-stack","",@progbits 46 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/tree_equal_4002a0.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "tree_equal_4002a0.ll" 3 | .globl F4002a0 4 | .align 16, 0x90 5 | .type F4002a0,@function 6 | F4002a0: # @F4002a0 7 | .cfi_startproc 8 | # BB#0: # %block_4002a0 9 | subq $40, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 48 12 | movq %rdi, 24(%rsp) 13 | movq %rsi, 16(%rsp) 14 | cmpq $0, 24(%rsp) 15 | je .LBB0_1 16 | # BB#4: # %block_4002c4 17 | cmpq $0, 16(%rsp) 18 | je .LBB0_8 19 | # BB#5: # %block_4002e6 20 | movq 16(%rsp), %rax 21 | movq 24(%rsp), %rcx 22 | movq 16(%rax), %rsi 23 | movq 16(%rcx), %rdi 24 | callq F4022c0 25 | testl %eax, %eax 26 | jne .LBB0_8 27 | # BB#6: # %block_400303 28 | movq 16(%rsp), %rax 29 | movq 24(%rsp), %rcx 30 | movq (%rax), %rsi 31 | movq (%rcx), %rdi 32 | callq F4002a0 33 | testl %eax, %eax 34 | je .LBB0_8 35 | # BB#7: # %block_400322 36 | movq 16(%rsp), %rax 37 | movq 24(%rsp), %rcx 38 | movq 8(%rax), %rsi 39 | movq 8(%rcx), %rdi 40 | callq F4002a0 41 | movl $1, %eax 42 | testl %eax, %eax 43 | jne .LBB0_9 44 | .LBB0_8: # %block_40032d 45 | xorl %eax, %eax 46 | .LBB0_9: # %block_400333 47 | addq $40, %rsp 48 | retq 49 | .LBB0_1: # %block_4002b7 50 | movb $1, %al 51 | cmpq $0, 16(%rsp) 52 | je .LBB0_3 53 | # BB#2: # %select.mid 54 | xorl %eax, %eax 55 | .LBB0_3: # %select.end 56 | movzbl %al, %eax 57 | addq $40, %rsp 58 | retq 59 | .Ltmp1: 60 | .size F4002a0, .Ltmp1-F4002a0 61 | .cfi_endproc 62 | 63 | 64 | .section ".note.GNU-stack","",@progbits 65 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/unknown_400120.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "unknown_400120.ll" 3 | .globl F400120 4 | .align 16, 0x90 5 | .type F400120,@function 6 | F400120: # @F400120 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | pushq %rbp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | .Ltmp1: 13 | .cfi_offset %rbp, -16 14 | movq %rsp, %rbp 15 | .Ltmp2: 16 | .cfi_def_cfa_register %rbp 17 | movd %xmm0, %rax 18 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 19 | movd %xmm0, %rcx 20 | movq %rsp, %rsi 21 | addq $-16, %rsi 22 | movq %rsi, %rsp 23 | movd %rax, %xmm0 24 | movd %rcx, %xmm1 25 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 26 | movq %rbp, %rsp 27 | popq %rbp 28 | retq 29 | .Ltmp3: 30 | .size F400120, .Ltmp3-F400120 31 | .cfi_endproc 32 | 33 | 34 | .section ".note.GNU-stack","",@progbits 35 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/unknown_400154.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "unknown_400154.ll" 3 | .globl F400154 4 | .align 16, 0x90 5 | .type F400154,@function 6 | F400154: # @F400154 7 | .cfi_startproc 8 | # BB#0: # %block_40018a 9 | subq $24, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 32 12 | leaq 24(%rsp), %rdi 13 | callq F40016a 14 | movq (%rax), %rsi 15 | leaq 8(%rax), %rdx 16 | movl $F400603, %edi 17 | callq F400802 18 | movq %rax, %rdi 19 | movq %rdx, %rsi 20 | callq F400190 21 | addq $24, %rsp 22 | retq 23 | .Ltmp1: 24 | .size F400154, .Ltmp1-F400154 25 | .cfi_endproc 26 | 27 | 28 | .section ".note.GNU-stack","",@progbits 29 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/unknown_402f54.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "unknown_402f54.ll" 3 | .globl F402f54 4 | .align 16, 0x90 5 | .type F402f54,@function 6 | F402f54: # @F402f54 7 | .cfi_startproc 8 | # BB#0: # %entry 9 | pushq %rbp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 16 12 | .Ltmp1: 13 | .cfi_offset %rbp, -16 14 | movq %rsp, %rbp 15 | .Ltmp2: 16 | .cfi_def_cfa_register %rbp 17 | movd %xmm0, %rax 18 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 19 | movd %xmm0, %rcx 20 | movq %rsp, %rsi 21 | addq $-16, %rsi 22 | movq %rsi, %rsp 23 | movd %rax, %xmm0 24 | movd %rcx, %xmm1 25 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 26 | movq %rbp, %rsp 27 | popq %rbp 28 | retq 29 | .Ltmp3: 30 | .size F402f54, .Ltmp3-F402f54 31 | .cfi_endproc 32 | 33 | 34 | .section ".note.GNU-stack","",@progbits 35 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/llvm-latest/write_tree_4003c1.s: -------------------------------------------------------------------------------- 1 | .text 2 | .file "write_tree_4003c1.ll" 3 | .globl F4003c1 4 | .align 16, 0x90 5 | .type F4003c1,@function 6 | F4003c1: # @F4003c1 7 | .cfi_startproc 8 | # BB#0: # %block_4003e7 9 | subq $56, %rsp 10 | .Ltmp0: 11 | .cfi_def_cfa_offset 64 12 | movq %rdi, 24(%rsp) 13 | movq %rsi, 16(%rsp) 14 | movq 6307864, %rsi 15 | movq 24(%rsp), %rdi 16 | movq %rsi, %rdx 17 | callq F401ee8 18 | movd %xmm0, %rax 19 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 20 | movd %xmm0, %rcx 21 | testq %rax, %rax 22 | jne .LBB0_2 23 | # BB#1: # %block_4003f2 24 | movd %rax, %xmm0 25 | movd %rcx, %xmm1 26 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 27 | movl $75, %edi 28 | movq %rdx, %rsi 29 | callq F400130 30 | movd %xmm0, %rax 31 | pshufd $78, %xmm0, %xmm0 # xmm0 = xmm0[2,3,0,1] 32 | movd %xmm0, %rcx 33 | .LBB0_2: # %block_40041b 34 | movq 16(%rsp), %rsi 35 | movq 40(%rsp), %rdi 36 | movd %rax, %xmm0 37 | movd %rcx, %xmm1 38 | punpcklqdq %xmm1, %xmm0 # xmm0 = xmm0[0],xmm1[0] 39 | movq %rsi, %rdx 40 | callq F400335 41 | movq 40(%rsp), %rdi 42 | movq %rdx, %rsi 43 | callq F401c7a 44 | addq $56, %rsp 45 | retq 46 | .Ltmp1: 47 | .size F4003c1, .Ltmp1-F4003c1 48 | .cfi_endproc 49 | 50 | 51 | .section ".note.GNU-stack","",@progbits 52 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/frankentree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/llvm-merge-example-ubuntu/example/tmp/frankentree -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/original-tree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/llvm-merge-example-ubuntu/example/tmp/original-tree -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F40016a_to__start_c.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F40016a 3 | F40016a: 4 | jmp _start_c 5 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F400603_to_main.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F400603 3 | F400603: 4 | jmp main 5 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F400802_to___libc_start_main.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F400802 3 | F400802: 4 | jmp __libc_start_main 5 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F40083d_to___libc_exit_fini.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F40083d 3 | F40083d: 4 | jmp __libc_exit_fini 5 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F400e40_to_free.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F400e40 3 | F400e40: 4 | jmp free 5 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F401280_to_malloc.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F401280 3 | F401280: 4 | jmp malloc 5 | -------------------------------------------------------------------------------- /llvm-merge-example-ubuntu/example/tmp/redirect_F4018b0_to_realloc.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl F4018b0 3 | F4018b0: 4 | jmp realloc 5 | -------------------------------------------------------------------------------- /llvm-merge-example/.gitignore: -------------------------------------------------------------------------------- 1 | *.o -------------------------------------------------------------------------------- /llvm-merge-example/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: tree tree.ll 3 | 4 | CLANG=clang-3.5 5 | LLVM-DIS=llvm-dis35 6 | LLC=llc 7 | LLC_FLAGS=-mtriple=x86_64-unknown-freebsd 8 | 9 | LD=x86_64-unknown-freebsd-ld 10 | 11 | tree: tree.o data.o 12 | $(LD) -o tree tree.o data.o 13 | 14 | data.bc: tree.c data.h 15 | $(CLANG) $(CFLAGS) -c -emit-llvm -static tree.c 16 | 17 | tree.bc: tree.c data.h 18 | $(CLANG) $(CFLAGS) -c -emit-llvm -static tree.c 19 | 20 | %.o : %.s 21 | $(AS) $< 22 | 23 | %.s : %.bc 24 | $(LLC) $(LLC_FLAGS) $< 25 | 26 | %.ll: %.bc 27 | $(LLVM-DIS) $< 28 | 29 | clean: 30 | rm -f tree tree.ll tree.bc -------------------------------------------------------------------------------- /llvm-merge-example/data.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains global data declarations. 3 | * 4 | * It is used so that the code does not contain separate copies of global data. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "data.h" 12 | 13 | struct tree g_left = { .left = NULL, .right = NULL, .payload = "left" }; 14 | struct tree g_right_right = { .left = NULL, .right = NULL, .payload = "right_right" }; 15 | struct tree g_right = { .left = NULL, .right = &g_right_right, .payload = "right" }; 16 | struct tree root = { .left = &g_left, .right = &g_right, .payload = "root" }; 17 | -------------------------------------------------------------------------------- /llvm-merge-example/data.h: -------------------------------------------------------------------------------- 1 | 2 | struct tree { 3 | struct tree* left; 4 | struct tree* right; 5 | const char* payload; 6 | }; 7 | const char sep = ','; 8 | const char* r_str = "r"; 9 | const char* w_str = "w"; 10 | -------------------------------------------------------------------------------- /llvm-merge-example/mk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | syms=("w_str" "r_str" "root" "fopen" "fclose" "fputc" "fgetc" "fputs" "strcmp" "exit" "malloc" "feof" "realloc" "free") 6 | 7 | function get_addr () 8 | { 9 | nm --defined-only original-tree | grep -E "\<$1\>" | cut -d' ' -f1 10 | } 11 | 12 | function make_original_cflags () { 13 | local cflags="-O3" 14 | for i in ${syms[*]}; do 15 | local name=$(echo ${i} | tr 'a-z' 'A-Z') 16 | cflags="$cflags -D$name=$i" 17 | done 18 | echo $cflags 19 | } 20 | 21 | 22 | original_cflags=$(make_original_cflags) 23 | echo make CFLAGS="${original_cflags}" 24 | make CFLAGS="${original_cflags}" 25 | mv tree original-tree 26 | mv tree.ll original-tree.ll 27 | 28 | 29 | function make_cflags () { 30 | local cflags="-O3" 31 | for i in ${syms[*]}; do 32 | local v=$(get_addr $i) 33 | local name=$(echo ${i} | tr 'a-z' 'A-Z') 34 | cflags="$cflags -D$name='(*((typeof($i) *) (0x$v)))'" 35 | done 36 | echo $cflags 37 | } 38 | 39 | cflags=$(make_cflags) 40 | echo make CFLAGS="${cflags}" 41 | make CFLAGS="${cflags}" 42 | -------------------------------------------------------------------------------- /llvm-merge-example/original-tree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/llvm-merge-example/original-tree -------------------------------------------------------------------------------- /llvm-testbed/README.md: -------------------------------------------------------------------------------- 1 | Examples comparing reopt-processed functions to the original 2 | version. Do 3 | 4 | cd ./ 5 | make 6 | tmp/main 7 | 8 | to run an example. 9 | -------------------------------------------------------------------------------- /llvm-testbed/memcmp/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: tmp/main 3 | 4 | tmp/main: main.c tmp/memcmp_F4004ec.s | tmp 5 | gcc -o $@ $^ 6 | 7 | tmp/%.s: %.ll | tmp 8 | llc -o $@ $^ 9 | 10 | tmp: 11 | mkdir -p tmp 12 | 13 | .PHONY: clean 14 | clean: 15 | -rm -rf tmp 16 | -------------------------------------------------------------------------------- /llvm-testbed/memcmp/main.c: -------------------------------------------------------------------------------- 1 | // Compare original 'memcmp' to reopted 'memcmp'. 2 | #include 3 | #include 4 | #include 5 | 6 | // uint64_t _F4004ec(uint64_t b1, uint64_t b2, uint64_t b3); 7 | int F4004ec(const char *b1, const char *b2, uint64_t sz); 8 | 9 | int main(void) 10 | { 11 | printf("All output pairs should be equal:\n"); 12 | 13 | char b1[] = "Hello World"; 14 | char b2[] = "hello world"; 15 | 16 | int r1 = F4004ec(b1, b2, strlen(b1)); 17 | int s1 = memcmp(b1, b2, strlen(b1)); 18 | 19 | printf("%d %d\n", r1, s1); 20 | 21 | int r2 = F4004ec(b1, b1, strlen(b1)); 22 | int s2 = memcmp(b1, b1, strlen(b1)); 23 | 24 | printf("%d %d\n", r2, s2); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | all: tmp/main tmp/generator-musl 3 | 4 | # tmp/main: main.c tmp/memcpy_400a28.s tmp/strlen_4009b0.s | tmp 5 | tmp/main: main.c tmp/memcpy_400645.s tmp/strlen_4005d0.s 6 | gcc -Wall -o $@ $^ 7 | 8 | tmp/%.s: %.ll | tmp 9 | llc -o $@ $^ 10 | 11 | # http://www.musl-libc.org/download.html 12 | tmp/generator-musl: generator.c | tmp 13 | musl-gcc -static -Wall -o $@ $^ 14 | 15 | tmp: 16 | mkdir -p tmp 17 | 18 | .PHONY: clean 19 | clean: 20 | -rm -rf tmp 21 | -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/README.md: -------------------------------------------------------------------------------- 1 | The `.ll` files came from running 2 | 3 | stack exec -- ./run-llvm.sh examples/hello_world/hello_world_ubuntu_64_lts_12_04_musl 4 | 5 | in the repo and root and copying into 6 | `./reopted-files-from-hello-world/`, and by running 7 | 8 | stack exec ../../run-llvm.sh tmp/generator-musl 9 | 10 | in this dir and copying into `./reopted-files-from-generator/`. 11 | 12 | Do `make` and then `./tmp/main` to run the example. 13 | -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/generator.c: -------------------------------------------------------------------------------- 1 | // Use 'memcpy' and 'strlen' so we can reopt them. 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | int main() { 8 | /* 9 | int main(int argc, char **argv) { 10 | if (argc != 2) { 11 | fprintf(stderr, "usage: %s STRING\n", argv[0]); 12 | exit(2); 13 | } 14 | 15 | char *orig = argv[1]; 16 | */ 17 | char *orig = "Time flies like the wind; fruit flies like bananas"; 18 | char *copy = malloc(strlen(orig) + 1); 19 | char *copy_ret = memcpy(copy, orig, strlen(orig) + 1); 20 | /* 21 | printf("%p = %p\n", (void *) copy, (void *) copy_ret); 22 | printf("%s\n", copy); 23 | */ 24 | 25 | // Eliminate warming about unused 'copy_ret'. 26 | return ! (copy_ret == copy_ret); 27 | } 28 | -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/memcpy_400645.ll: -------------------------------------------------------------------------------- 1 | reopted-files-from-generator/memcpy_400645.ll -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/memcpy_400a28.ll: -------------------------------------------------------------------------------- 1 | reopted-files-from-hello-world/memcpy_400a28.ll -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/strlen_4005d0.ll: -------------------------------------------------------------------------------- 1 | reopted-files-from-generator/strlen_4005d0.ll -------------------------------------------------------------------------------- /llvm-testbed/memcpy-and-strlen/strlen_4009b0.ll: -------------------------------------------------------------------------------- 1 | reopted-files-from-hello-world/strlen_4009b0.ll -------------------------------------------------------------------------------- /reopt-explore/Common.hs: -------------------------------------------------------------------------------- 1 | module Common where 2 | 3 | import Control.Monad (foldM) 4 | import Data.IORef (IORef, modifyIORef', newIORef, readIORef) 5 | 6 | import Reopt.Utils.Dir (withElfExeFilesInDir) 7 | 8 | findAllElfFilesInDirs :: 9 | [FilePath] -> 10 | IO [(Int, FilePath)] 11 | findAllElfFilesInDirs paths = do 12 | counter <- newIORef 1 13 | files <- foldM (withElfExeFilesInDir (recordFile counter)) [] paths 14 | pure $ reverse files 15 | where 16 | recordFile :: IORef Int -> [(Int, FilePath)] -> FilePath -> IO [(Int, FilePath)] 17 | recordFile counter ps p = do 18 | index <- readIORef counter 19 | modifyIORef' counter (+ 1) 20 | pure $ (index, p) : ps 21 | -------------------------------------------------------------------------------- /reopt_test/SignalUtils.hs: -------------------------------------------------------------------------------- 1 | {- | 2 | Module : $Header$ 3 | Description : Utilities for POSIX signals. 4 | Copyright : (c) Galois, Inc 2015 5 | Maintainer : Nathan Collins 6 | 7 | Convert signals and @waitpid@ statuses to strings. 8 | -} 9 | {-# LANGUAGE ForeignFunctionInterface #-} 10 | {-# LANGUAGE LambdaCase #-} 11 | module SignalUtils 12 | ( signalToString 13 | , statusToString 14 | ) where 15 | 16 | import Foreign.C (CInt(..), CString, peekCString) 17 | import System.Posix.Signals (Signal) 18 | import System.Posix.Waitpid (Status(..)) 19 | 20 | -- | "strsignal - return string describing signal". 21 | foreign import ccall "string.h strsignal" strsignal :: CInt -> IO CString 22 | 23 | -- | Convert a signal number to its Unix string representation. 24 | -- 25 | -- A mapping from signal names to numbers is in @signal.h@, e.g. 26 | -- @ 27 | -- /usr/src/linux-headers-3.16.0-44/arch/ia64/include/uapi/asm/signal.h 28 | -- @ on conathan's machine. 29 | signalToString :: Signal -> IO String 30 | signalToString signal = do 31 | cString <- strsignal signal 32 | peekCString cString 33 | 34 | -- | Convert a status to a string using 'signalToString' to convert embedded signals. 35 | statusToString :: Status -> IO String 36 | statusToString = \case 37 | Signaled signal -> go "Signaled" signal 38 | Stopped signal -> go "Stopped" signal 39 | status -> return $ show status 40 | where 41 | go prefix signal = do 42 | s <- signalToString signal 43 | let i = show signal 44 | return $ prefix ++ " " ++ i ++ " (" ++ s ++ ")" 45 | -------------------------------------------------------------------------------- /scripts/linux_binutils.sh: -------------------------------------------------------------------------------- 1 | # This script downloads binutils and compiles it for a freebsd target. 2 | # 3 | #!/bin/bash 4 | set -e 5 | 6 | INSTALL_PATH=${1?Please specify the install location as first target.} 7 | 8 | BUILD_DIR=binutils-linux-build 9 | BINUTILS=binutils-2.29 10 | TARGET=x86_64-unknown-linux 11 | 12 | 13 | wget http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.xz 14 | tar xfj $BINUTILS.tar.xz 15 | 16 | mkdir -p $BUILD_DIR 17 | pushd $BUILD_DIR > /dev/null 18 | ../$BINUTILS/configure --target=$TARGET --prefix=$INSTALL_PATH 19 | make 20 | make install 21 | popd > /dev/null 22 | -------------------------------------------------------------------------------- /scripts/run_graphmod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # make sure graphmod and dot are in the PATH 5 | if ! type -p graphmod; then 6 | echo "Error: cannot find Haskell 'graphmod' in PATH" 1>&2 7 | echo "It can be installed via cabal or stack." 1>&2 8 | exit 1 9 | fi 10 | 11 | if ! type -p dot; then 12 | echo "Error: cannot find 'dot' in PATH" 1>&2 13 | echo "It can be installed via 'brew install graphviz' or your system package manger." 1>&2 14 | exit 1 15 | fi 16 | 17 | dir="src" 18 | name="reopt" 19 | FILES="$(find src -name '*.hs') $(find reopt -name '*.hs')" 20 | echo "Writing graphmod file to $name.svg" 21 | graphmod -i src -i reopt -p --no-cluster $FILES -q | dot -Tsvg > reopt.svg 22 | 23 | graphmod -i src -i reopt -p $FILES -q | dot -Tsvg > reopt_cluster.svg 24 | -------------------------------------------------------------------------------- /scripts/run_reopt.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | set -euv 3 | 4 | # Building first, so that if build is needed, the output does not bother us 5 | cabal build reopt:exe:reopt 6 | 7 | cabal run -v0 reopt:exe:reopt -- \ 8 | --debug-dir ./deps/reopt-benchmark-binaries/centos7-dev/debug-lib64 \ 9 | --header ./scratch/shed.h \ 10 | --export-llvm ./scratch/out.ll \ 11 | ${*} 2>&1 | less -R 12 | -------------------------------------------------------------------------------- /scripts/run_residuals.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | set -euv 3 | 4 | # Building first, so that if build is needed, the output does not bother us 5 | cabal build reopt:exe:reopt-explore 6 | 7 | cabal run -v0 reopt:exe:reopt-explore -- \ 8 | --debug-dir ./deps/reopt-benchmark-binaries/centos7-dev/debug-lib64 \ 9 | residuals \ 10 | --output-for-spreadsheet \ 11 | --header ./scratch/shed.h \ 12 | ${*} 2>&1 | less -R 13 | -------------------------------------------------------------------------------- /scripts/test_reopt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Euo pipefail 4 | 5 | if [[ -x $(which reopt) ]] ; then 6 | REOPT=$(which reopt) 7 | else 8 | REOPT="cabal run exe:reopt --" 9 | fi 10 | 11 | run_reopt () { 12 | echo "Running reopt on $1" 13 | $REOPT --recover $1 --lib-dir=lib64 --debug-dir=debug-lib64 14 | } 15 | 16 | 17 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 18 | 19 | CENTOS7_DEV_DIR="$DIR/../deps/reopt-benchmark-binaries/centos7-dev" 20 | 21 | /bin/bash $DIR/unpack_benchmarks.sh 22 | 23 | if [[ $# -lt 1 ]]; then 24 | echo "No options or binaries specified!" 25 | echo "" 26 | echo " usage: ./test_reopt.sh [all|small|bin...+]" 27 | echo " where" 28 | echo " all: runs reopt against all binaries in the centos7-dev/bin directory" 29 | echo " small: runs reopt against a few binaries in the centos7-dev/bin directory" 30 | echo " bin...+: runs reopt against the specified binaries in deps/reopt-benchmark-binaries/centos7-dev/bin" 31 | elif [[ $1 == "small" ]]; then 32 | echo "Running small default set of reopt tests..." 33 | pushd $CENTOS7_DEV_DIR 34 | run_reopt bin/mkdir 35 | run_reopt bin/curl 36 | run_reopt bin/date 37 | popd > /dev/null # $CENTOS7_DEV_DIR 38 | elif [[ $1 == "all" ]]; then 39 | echo "Running reopt on all centos7-dev binaries..." 40 | pushd $CENTOS7_DEV_DIR 41 | for exe in bin/* 42 | do 43 | if [[ -x "$exe" ]]; then 44 | run_reopt $exe 45 | fi 46 | done 47 | else 48 | pushd $CENTOS7_DEV_DIR 49 | for exe in "$@" 50 | do 51 | if [[ -x "bin/$exe" ]]; then 52 | run_reopt bin/$exe 53 | else 54 | echo "Could not find binary $exe in bin" 55 | exit 1 56 | fi 57 | done 58 | fi 59 | -------------------------------------------------------------------------------- /scripts/test_reopt_explore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuo pipefail 4 | 5 | if [[ -x $(which reopt-explore) ]] ; then 6 | REOPT_EXPLORE=$(which reopt-explore) 7 | else 8 | REOPT_EXPLORE="cabal run exe:reopt-explore --" 9 | fi 10 | 11 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 12 | 13 | CENTOS7_DEV_DIR="$DIR/../deps/reopt-benchmark-binaries/centos7-dev/" 14 | 15 | if [[ $# -lt 1 ]]; 16 | then 17 | echo "Need a command, one of 'all', 'small', or 'all-debug-info'." 18 | exit 1 19 | fi 20 | 21 | COMMAND="$1" 22 | shift 23 | 24 | /bin/bash $DIR/unpack_benchmarks.sh 25 | 26 | case $COMMAND in 27 | all) 28 | pushd $CENTOS7_DEV_DIR 29 | $REOPT_EXPLORE --lib-dir=lib64 --debug-dir=debug-lib64 llvm \ 30 | --export-summary=centos7-bin-summary.txt \ 31 | --export-log=centos7-bin-casts.csv \ 32 | bin 33 | popd > /dev/null # $CENTOS7_DEV_DIR 34 | ;; 35 | # all-debug-info) 36 | # pushd $CENTOS7_DEV_DIR 37 | # $REOPT_EXPLORE --debug-info debug-lib64 38 | # popd > /dev/null # $CENTOS7_DEV_DIR 39 | # ;; 40 | small) 41 | pushd $CENTOS7_DEV_DIR 42 | rm -fr test-bins 43 | mkdir test-bins 44 | cp bin/mkdir test-bins/mkdir 45 | cp bin/curl test-bins/curl 46 | cp bin/date test-bins/date 47 | $REOPT_EXPLORE --lib-dir=lib64 --debug-dir=debug-lib64 llvm test-bins/mkdir # --export-summary=centos7-small-bin-mkdir-summary.txt 48 | $REOPT_EXPLORE --lib-dir=lib64 --debug-dir=debug-lib64 llvm test-bins # --export-summary=centos7-small-bin-summary.txt 49 | popd > /dev/null # $CENTOS7_DEV_DIR 50 | ;; 51 | # *) echo "unknown command - use 'all', 'small', or 'all-debug-info'"; exit 1;; 52 | *) echo "unknown command - use 'all' or 'small'"; exit 1;; 53 | esac 54 | -------------------------------------------------------------------------------- /scripts/unpack_benchmarks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xe 4 | 5 | CENTOS7_DEV_DIR="centos7-dev" 6 | 7 | 8 | unlzma_mv_untar () { 9 | TAR_FILE=$1 10 | DIR=$2 11 | 12 | pushd $DIR 13 | echo -n "Unpacking and extracting contents of $TAR_FILE.lzma in $DIR..." 14 | if [[ "$TAR_FILE.lzma" -nt "$TAR_FILE" ]] ; then 15 | unlzma -fk "$TAR_FILE.lzma" 16 | fi 17 | TARVER=`tar --version | head -n 1` 18 | if [[ "$TARVER" =~ "tar (GNU tar)" ]]; then 19 | tar -xf $TAR_FILE 20 | elif [[ "$TARVER" =~ "bsdtar" ]]; then 21 | tar -xkf $TAR_FILE 22 | else 23 | echo "Unknown version of tar, please report!" 24 | exit 1 25 | fi 26 | echo " done!" 27 | popd # $DIR 28 | } 29 | 30 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 31 | BENCHMARK_DIR="$SCRIPT_DIR/../deps/reopt-benchmark-binaries" 32 | pushd $BENCHMARK_DIR > /dev/null 33 | 34 | 35 | echo "Decompressing and unpacking centos7-dev files..." 36 | unlzma_mv_untar "bin.tar" "centos7-dev/bin" 37 | unlzma_mv_untar "lib64.tar" "centos7-dev/lib64" 38 | unlzma_mv_untar "debug-lib64.tar" "centos7-dev/debug-lib64" 39 | 40 | 41 | popd > /dev/null # $BENCHMARK_DIR 42 | -------------------------------------------------------------------------------- /src/Reopt/CFG/FnRep/X86.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -fno-warn-orphans #-} 2 | 3 | -- | Defines the X86-specific definitions needed in the function representation. 4 | module Reopt.CFG.FnRep.X86 ( 5 | X86FnStmt (..), 6 | ) where 7 | 8 | import Data.Macaw.CFG (IsArchStmt (..)) 9 | import Data.Macaw.X86.ArchTypes (X86Stmt, X86_64) 10 | import Data.Parameterized.TraversableF (FoldableF (foldrF)) 11 | 12 | import Reopt.CFG.FnRep (FnArchStmt) 13 | 14 | newtype X86FnStmt f = X86FnStmt (X86Stmt f) 15 | 16 | type instance FnArchStmt X86_64 = X86FnStmt 17 | 18 | instance IsArchStmt X86FnStmt where 19 | ppArchStmt pp (X86FnStmt s) = ppArchStmt pp s 20 | 21 | instance FoldableF X86FnStmt where 22 | foldrF f s (X86FnStmt t) = foldrF f s t 23 | -------------------------------------------------------------------------------- /src/Reopt/Hints.hs: -------------------------------------------------------------------------------- 1 | -- | 2 | -- This defines a JSON format for providing hints to Reopt to help its 3 | -- analysis. 4 | module Reopt.Hints ( 5 | FunIdent (..), 6 | resolveSymName, 7 | ) where 8 | 9 | import Data.ByteString.Char8 qualified as BSC 10 | import Data.Hashable (Hashable (hashWithSalt)) 11 | import Data.Word (Word64) 12 | import Numeric (readHex) 13 | 14 | -- | A function identifier 15 | data FunIdent 16 | = -- | A function identified by an offset in the virtual address 17 | -- space. 18 | AddrIdent !Word64 19 | | -- | A function identified by a symbol name. 20 | SymbolIdent !BSC.ByteString 21 | deriving (Eq) 22 | 23 | instance Hashable FunIdent where 24 | hashWithSalt i (AddrIdent w) = hashWithSalt (hashWithSalt i (0 :: Int)) w 25 | hashWithSalt i (SymbolIdent w) = hashWithSalt (hashWithSalt i (1 :: Int)) w 26 | 27 | -- | Resolve a hex string or other string as a address of symbol name. 28 | resolveSymName :: String -> FunIdent 29 | resolveSymName ('0' : 'x' : nm) | [(w, "")] <- readHex nm = AddrIdent w 30 | resolveSymName ('0' : 'X' : nm) | [(w, "")] <- readHex nm = AddrIdent w 31 | resolveSymName nm = SymbolIdent (BSC.pack nm) 32 | -------------------------------------------------------------------------------- /src/Reopt/Relinker/Constants.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | This module contains constants and general functions used as assumptions in relinking. 3 | -} 4 | {-# LANGUAGE OverloadedStrings #-} 5 | module Reopt.Relinker.Constants 6 | ( overflowOffsetMultiple 7 | , pageSize 8 | , newCodeSectionName 9 | , newRodataSectionName 10 | , infoIsShdrIndex 11 | ) where 12 | 13 | import qualified Data.ByteString as BS 14 | import qualified Data.ElfEdit as Elf 15 | 16 | -- | Multiple for offset of overflow code section 17 | overflowOffsetMultiple :: Int 18 | overflowOffsetMultiple = 16 19 | 20 | -- | Page size (new program headers are aligned to page boundaries) 21 | pageSize :: Int 22 | pageSize = 0x1000 23 | 24 | newCodeSectionName :: BS.ByteString 25 | newCodeSectionName = ".text.reopt" 26 | 27 | newRodataSectionName :: BS.ByteString 28 | newRodataSectionName = ".rodata.reopt" 29 | 30 | -- | Return true if the index of this section should refer to a section 31 | -- index 32 | infoIsShdrIndex :: Elf.Shdr BS.ByteString v -> Bool 33 | infoIsShdrIndex shdr = 34 | let nm = Elf.shdrName shdr 35 | in (Elf.shdrType shdr == Elf.SHT_RELA || nm == ".rela.plt") 36 | && nm /= ".rela.dyn" -------------------------------------------------------------------------------- /src/Reopt/TypeInference/Solver/TypeVariables.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | module Reopt.TypeInference.Solver.TypeVariables ( 4 | TyVar (TyVar, tyVarInt), 5 | ) 6 | where 7 | 8 | import Data.Function (on) 9 | import Prettyprinter qualified as PP 10 | 11 | import Reopt.TypeInference.Solver.UnionFindMap (UFMKeyInfo (..)) 12 | 13 | data TyVar = TyVar 14 | { tyVarInt :: Int 15 | , tyVarOrigin :: Maybe String 16 | -- ^ If you want to record the origin of this type variable, it will show 17 | -- out when you pretty-print it. Recommended, except in the test suite 18 | -- where there is not much point in marking test type variables. 19 | } 20 | deriving (Show) 21 | 22 | instance Eq TyVar where 23 | (==) = (==) `on` tyVarInt 24 | 25 | instance Ord TyVar where 26 | compare = compare `on` tyVarInt 27 | 28 | instance PP.Pretty TyVar where 29 | pretty tyv = PP.hcat ["α", PP.pretty (tyVarInt tyv), maybeOrigin (tyVarOrigin tyv)] 30 | where 31 | maybeOrigin Nothing = mempty 32 | maybeOrigin (Just origin) = PP.space <> PP.parens (PP.pretty origin) 33 | 34 | instance UFMKeyInfo TyVar TyVar where 35 | compact _ x = x 36 | projectKey = id 37 | injectKey = id 38 | invertKey k _ = k 39 | -------------------------------------------------------------------------------- /src/Reopt/Utils/Flags.hs: -------------------------------------------------------------------------------- 1 | {-| Primitive function related to testing flags. -} 2 | module Reopt.Utils.Flags ( hasFlags ) where 3 | 4 | import Data.Bits 5 | 6 | -- | `hasFlag x a` returns true if `x` has all the flags in `a`. 7 | hasFlags :: Bits a => a -> a -> Bool 8 | hasFlags x a = x .&. a == a -------------------------------------------------------------------------------- /src/Reopt/Utils/Folds.hs: -------------------------------------------------------------------------------- 1 | module Reopt.Utils.Folds (sumBy) where 2 | 3 | -- | Sum a map over a structure. 4 | -- 5 | -- `sumBy f t = sum (fmap f t)` 6 | sumBy :: (Foldable t, Num b) => (a -> b) -> t a -> b 7 | sumBy f = foldl (\z e -> z + f e) 0 -------------------------------------------------------------------------------- /src/Reopt/Utils/Hex.hs: -------------------------------------------------------------------------------- 1 | module Reopt.Utils.Hex (Hex (..)) where 2 | 3 | import Numeric (showHex) 4 | 5 | newtype Hex a = Hex a 6 | deriving (Eq, Ord) 7 | 8 | instance (Integral a, Show a) => Show (Hex a) where 9 | show (Hex v) 10 | | v >= 0 = showHex v "" 11 | | otherwise = '-' : showHex (negate (toInteger v)) "" 12 | -------------------------------------------------------------------------------- /src/Reopt/X86.hs: -------------------------------------------------------------------------------- 1 | module Reopt.X86 ( 2 | osArchitectureInfo, 3 | osLinkName, 4 | osPersonality, 5 | X86OS(..), 6 | x86OSForABI, 7 | ) where 8 | 9 | import Data.Map.Strict qualified as Map 10 | 11 | import Data.Macaw.Architecture.Info (ArchitectureInfo (..)) 12 | import Data.ElfEdit qualified as Elf 13 | import Data.Macaw.X86 qualified as X86 14 | import Data.Macaw.X86.SyscallInfo (SyscallPersonality) 15 | import Data.Macaw.X86 (X86_64) 16 | 17 | data X86OS = Linux | FreeBSD 18 | 19 | instance Show X86OS where 20 | show Linux = "Linux" 21 | show FreeBSD = "FreeBSD" 22 | 23 | osPersonality :: X86OS -> SyscallPersonality 24 | osPersonality Linux = X86.linux_syscallPersonality 25 | osPersonality FreeBSD = X86.freeBSD_syscallPersonality 26 | 27 | osArchitectureInfo :: X86OS -> ArchitectureInfo X86_64 28 | osArchitectureInfo Linux = X86.x86_64_linux_info 29 | osArchitectureInfo FreeBSD = X86.x86_64_freeBSD_info 30 | 31 | -- | Return the name to pass the linker for this architecture. 32 | osLinkName :: X86OS -> String 33 | osLinkName Linux = "x86_64-unknown-linux-gnu" 34 | osLinkName FreeBSD = "x86_64-unknown-freebsd-elf" 35 | 36 | -- | Maps x86 ABIs to the x86 OS value we use for it. 37 | x86ABIMap :: Map.Map Elf.ElfOSABI X86OS 38 | x86ABIMap = 39 | Map.fromList 40 | [ (Elf.ELFOSABI_LINUX, Linux) 41 | , (Elf.ELFOSABI_SYSV, Linux) 42 | , (Elf.ELFOSABI_FREEBSD, FreeBSD) 43 | , (Elf.ELFOSABI_NETBSD, FreeBSD) 44 | ] 45 | 46 | -- | Return x86 OS value for Elf file with given ABI 47 | x86OSForABI :: Elf.ElfOSABI -> Maybe X86OS 48 | x86OSForABI abi = Map.lookup abi x86ABIMap 49 | -------------------------------------------------------------------------------- /stats/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | /dist 3 | credentials.json 4 | token.json 5 | *.out 6 | -------------------------------------------------------------------------------- /stats/README.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/stats/README.rst -------------------------------------------------------------------------------- /stats/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "stats" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Valentin Robert "] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.10" 9 | google-api-python-client = "^2.65.0" 10 | google-auth-httplib2 = "^0.1.0" 11 | google-auth-oauthlib = "^0.7.0" 12 | 13 | [tool.poetry.dev-dependencies] 14 | pytest = "^5.2" 15 | black = "^22.10.0" 16 | 17 | [tool.poetry.scripts] 18 | stats = "stats:main" 19 | 20 | [build-system] 21 | requires = ["poetry-core>=1.0.0"] 22 | build-backend = "poetry.core.masonry.api" 23 | -------------------------------------------------------------------------------- /stats/stats/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.1.0" 2 | 3 | from .main import main 4 | 5 | main = main 6 | -------------------------------------------------------------------------------- /stats/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/stats/tests/__init__.py -------------------------------------------------------------------------------- /stats/tests/test_stats.py: -------------------------------------------------------------------------------- 1 | from stats import __version__ 2 | 3 | 4 | def test_version(): 5 | assert __version__ == '0.1.0' 6 | -------------------------------------------------------------------------------- /support/.gitignore: -------------------------------------------------------------------------------- 1 | *.as 2 | *.bc 3 | *.256.ll 4 | *.512.ll 5 | *.o 6 | print_stackheap_addrs 7 | -------------------------------------------------------------------------------- /support/Makefile: -------------------------------------------------------------------------------- 1 | LLVM_DIS ?= llvm-dis 2 | 3 | 4 | all : llvm_return_test.512.as abi_test.512.ll abi_test.256.ll print_stackheap_addrs avx_intrin.512.o avx_intrin.512.ll 5 | 6 | print_stackheap_addrs: print_stackheap_addrs.c 7 | clang -o $@ -fstack-protector-strong -fstack-protector-all $< 8 | 9 | 10 | %.512.o : %.ll 11 | llc --mtriple=x86_64-pc-linux-elf -mattr=avx512f -filetype=obj -o $@ $< 12 | 13 | %.512.as : %.ll 14 | llc --mtriple=x86_64-pc-linux-elf -mattr=avx512f -filetype=asm --x86-asm-syntax=intel -o $@ $< 15 | 16 | %.256.as : %.ll 17 | llc --mtriple=x86_64-pc-linux-elf -mattr=avx2 --x86-asm-syntax=intel -o $@ $< 18 | 19 | %.128.as : %.ll 20 | llc --mtriple=x86_64-pc-linux-elf --x86-asm-syntax=intel -o $@ $< 21 | 22 | %.as : %.bc 23 | llc --mtriple=x86_64-pc-linux-elf --x86-asm-syntax=intel -o $@ $< 24 | 25 | %.512.bc : %.c 26 | clang -c --target=x86_64-pc-linux-elf -emit-llvm -mavx512f -O3 -o $@ $< 27 | 28 | %.256.bc : %.c 29 | clang -c --target=x86_64-pc-linux-elf -emit-llvm -mavx2 -O3 -o $@ $< 30 | 31 | %.512.o : %.512.c 32 | clang --target=x86_64-pc-linux-elf -mavx512f -c -o $@ $< 33 | 34 | %.512.bc : %.512.c 35 | clang -c --target=x86_64-pc-linux-elf -mavx512f -emit-llvm -O3 -o $@ $< 36 | 37 | %.ll : %.bc 38 | $(LLVM_DIS) $< 39 | 40 | .PHONY : all clean 41 | .PRECIOUS : %.512.bc %.256.bc %.bc %.ll 42 | 43 | clean : 44 | rm -rf *.as *.bc *.o abi_test.ll print_stackheap_addrs 45 | -------------------------------------------------------------------------------- /support/README: -------------------------------------------------------------------------------- 1 | This directory contains some files to test intrinsics, inline 2 | assembly, and conventions. 3 | 4 | It is not directly needed by Reopt. 5 | -------------------------------------------------------------------------------- /support/avx_intrin.512.c: -------------------------------------------------------------------------------- 1 | // This file contains test cases to generate AVX 512 intrinsics. 2 | // 3 | // It must be compiled with -mavx512f 4 | #include 5 | #include 6 | 7 | __m512d add(__m512d a, __m512d b) { 8 | return _mm512_add_round_pd(a, b, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC); 9 | } 10 | 11 | // This returns in zmm0. 12 | __m512d set_512_pd() { 13 | return _mm512_set_pd (7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /support/print_csize_info.c: -------------------------------------------------------------------------------- 1 | // This program prints out the sizes of different datatypes 2 | // in bytes so that we can check for reopt compatibility. 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char** argv) { 9 | printf("sizeof(short) = %lu\n", sizeof(short)); 10 | printf("sizeof(int) = %lu\n", sizeof(int)); 11 | printf("sizeof(long) = %lu\n", sizeof(long)); 12 | printf("sizeof(long long) = %lu\n", sizeof(long long)); 13 | printf("sizeof(intmax_t) = %lu\n", sizeof(intmax_t)); 14 | printf("sizeof(ssize_t) = %lu\n", sizeof(ssize_t)); 15 | printf("sizeof(ptrdiff_t) = %lu\n", sizeof(ptrdiff_t)); 16 | printf("sizeof(wint_t) = %lu\n", sizeof(wint_t)); 17 | printf("sizeof(double) = %lu\n", sizeof(double)); 18 | printf("sizeof(long double) = %lu\n", sizeof(long double)); 19 | 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /support/print_startup_info/Makefile: -------------------------------------------------------------------------------- 1 | clang?=clang 2 | 3 | print_startup_info : print_startup_info.c write.s start.s 4 | $(clang) -g -nostdlib -o $@ $^ 5 | 6 | clean : 7 | rm -f print_startup_info 8 | 9 | .PHONY : clean 10 | -------------------------------------------------------------------------------- /support/print_startup_info/README: -------------------------------------------------------------------------------- 1 | This is a small program that runs without a standard library. 2 | 3 | It prints out the arguments, environment, then the Elf auxilary 4 | vector. 5 | 6 | It's primary use is to help one debug the records constructed by the 7 | Linux static process loader. It can only be built on Linux. -------------------------------------------------------------------------------- /support/print_startup_info/print_startup_info: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/support/print_startup_info/print_startup_info -------------------------------------------------------------------------------- /support/print_startup_info/print_startup_info.c: -------------------------------------------------------------------------------- 1 | typedef long uint64_t; 2 | 3 | void mywrite(int fd, const char* s, int len); 4 | 5 | int mystrlen(const char* s) { 6 | int r = 0; 7 | while (*s) { 8 | ++s; ++r; 9 | } 10 | return r; 11 | } 12 | 13 | void myprint(int fd, const char* s) { 14 | mywrite(fd, s, mystrlen(s)); 15 | } 16 | 17 | 18 | char myitoc(uint64_t x) { 19 | return x < 10 ? '0' + x : ('a' - 10) + x; 20 | } 21 | 22 | char spbuf[17]; 23 | 24 | const char* myitoa(uint64_t x) { 25 | for (int i = 0; i != 16; ++i) { 26 | uint64_t p = (x >> 4 * i) & 0xf; 27 | spbuf[15-i] = myitoc(p); 28 | } 29 | spbuf[16] = 0; 30 | return spbuf; 31 | 32 | } 33 | 34 | typedef struct 35 | { 36 | int a_type; 37 | union { 38 | long a_val; 39 | void *a_ptr; 40 | void (*a_fnc)(); 41 | } a_un; 42 | } auxv_t; 43 | 44 | // Run with the stack pointer 45 | void run(const uint64_t* sp) { 46 | 47 | myprint(0, "Printing arguments:\n"); 48 | uint64_t argc = sp[0]; 49 | const char** argv = (const char**) (sp + 1); 50 | uint64_t i; 51 | for (i = 0; i != argc; ++i) { 52 | myprint(0, argv[i]); 53 | myprint(0, "\n"); 54 | } 55 | 56 | myprint(0, "Printing environment:\n"); 57 | const char** init_envp = (const char**) (sp + 2 + argc); 58 | const char** envp = init_envp; 59 | while (*envp) { 60 | myprint(0, *envp); 61 | myprint(0, "\n"); 62 | ++envp; 63 | } 64 | 65 | myprint(0, "Printing ELF Auxiliary Vectors:\n"); 66 | const auxv_t* init_auxv = (const auxv_t*) (envp + 1); 67 | const auxv_t* auxv = init_auxv; 68 | while (auxv->a_type) { 69 | myprint(0, "AUXV\n"); 70 | myprint(0, myitoa(auxv->a_type)); 71 | myprint(0, "\n"); 72 | switch (auxv->a_type) { 73 | case 0x3: 74 | myprint(0, "PHDR: "); 75 | myprint(0, myitoa(auxv->a_un.a_val)); 76 | myprint(0, "\n"); 77 | break; 78 | } 79 | ++auxv; 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /support/print_startup_info/reopt_print_startup_info.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | reopt -o psi_new print_startup_info --exclude=_start --exclude mywrite --exclude mystrlen --exclude myprint --exclude myctoi --exclude myatoi --exclude run --exclude __GNU_EH_FRAME_HDR 4 | -------------------------------------------------------------------------------- /support/print_startup_info/start.s: -------------------------------------------------------------------------------- 1 | # A start method that pushs 2 | .globl _start 3 | .type _start, @function 4 | _start: 5 | mov %rsp, %rdi 6 | call run 7 | mov $60, %rax 8 | syscall 9 | hlt 10 | -------------------------------------------------------------------------------- /support/print_startup_info/write.s: -------------------------------------------------------------------------------- 1 | .globl mywrite 2 | .type mywrite, @function 3 | mywrite: 4 | mov $1, %rax 5 | syscall 6 | ret 7 | -------------------------------------------------------------------------------- /support/test_except/.gitignore: -------------------------------------------------------------------------------- 1 | /test_except_static.exe -------------------------------------------------------------------------------- /support/test_except/Makefile: -------------------------------------------------------------------------------- 1 | test_except_dynamic.exe : test_except.cpp 2 | clang++ -o $@ -g $< 3 | 4 | test_except_static.exe : test_except.cpp 5 | clang++ -o $@ -g -static $< 6 | -------------------------------------------------------------------------------- /support/test_except/test_except.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | try { 5 | throw 20; 6 | } catch (int e) { 7 | std::cout << "An exception occurred. Exception Nr. " << e << '\n'; 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /support/x86_llvm_asm_examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.ll 2 | test_movsd -------------------------------------------------------------------------------- /support/x86_llvm_asm_examples/Makefile: -------------------------------------------------------------------------------- 1 | run : test_movsd test_repstos.ll 2 | ./test_movsd 3 | 4 | clean : 5 | rm -f test_movsd *.ll 6 | 7 | test_movsd : test_movsd.ll 8 | clang -o $@ $< 9 | 10 | test_repstos : test_repstos.ll 11 | clang -o $@ $< 12 | 13 | %.ll : %.c 14 | clang -Wall -S -emit-llvm -O3 $< 15 | 16 | .PHONY : run clean 17 | -------------------------------------------------------------------------------- /support/x86_llvm_asm_examples/README.md: -------------------------------------------------------------------------------- 1 | This directory contains development artifacts used to understand how 2 | to create inline assembly in LLVM for x86 specific operations. 3 | 4 | Th example files will also let us test the semantics of certain tricky 5 | instructions. To run these test, simply type `make`. 6 | -------------------------------------------------------------------------------- /support/x86_llvm_asm_examples/test_repstos.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo(uint64_t cnt, void* rdi, uint64_t val) { 4 | asm ( "rep stosq" 5 | : 6 | : "c" (cnt), "D" (rdi), "a" (val) 7 | : "memory"); 8 | } 9 | -------------------------------------------------------------------------------- /tests/Main.hs: -------------------------------------------------------------------------------- 1 | module Main ( main ) where 2 | 3 | import System.FilePath.Glob ( namesMatching ) 4 | import qualified Test.Tasty as T 5 | 6 | import qualified ReoptTests as T 7 | import qualified TyConstraintTests as TC 8 | 9 | main :: IO () 10 | main = do 11 | 12 | x64AsmTests <- namesMatching "tests/x64/*.exe" 13 | T.defaultMain $ T.testGroup "ReoptTests" [ 14 | TC.constraintTests, 15 | T.reoptTests x64AsmTests 16 | ] 17 | 18 | -------------------------------------------------------------------------------- /tests/README.rst: -------------------------------------------------------------------------------- 1 | This directory contains some automated tests for reopt_, but currently 2 | focuses on the code discovery implementation in macaw. Specifically, 3 | they check: 4 | 5 | 1) That the correct number of functions are found, 6 | 2) Each function starts at the expected address, 7 | 3) Each function contains the correct number of basic blocks, 8 | 4) Each basic block starts at the expected address 9 | 10 | The ``Makefile`` in the tests directory rebuilds the test files from 11 | source. The resulting binaries are checked in to the repository so 12 | that Mac OS users can run the tests without having to have a Linux 13 | build toolchain available. Additionally, having the binaries in the 14 | repository keeps the code layout stable. Expected addresses are 15 | hard-coded into the expected results of the test suite; regenerating 16 | the binaries on a different system or with a different compiler could 17 | change the offsets in the test binaries, which would require the 18 | expected results to be tweaked. This is unfortunate, but difficult to 19 | avoid in a robust way. 20 | 21 | Note that the tests are bare-bones and do not link against libc. They 22 | issue the exit system call directly to terminate. This lets us get 23 | small and comprehensible test cases. 24 | 25 | .. _reopt: https://github.com/GaloisInc/reopt 26 | -------------------------------------------------------------------------------- /tests/plan.org: -------------------------------------------------------------------------------- 1 | * Initial research 2 | ** basic blocks 3 | *** Functions 4 | **** getElfArchInfo (Main) 5 | Takes an ELF object and returns an ArchitectureInfo object. Don't worry about 6 | the Some, that just replaces the architecture type parameter with the width of 7 | that same architecture (the ArchitectureInfo contained therein has all the 8 | needed information, and the particular architecture gets hidden). 9 | **** elfClassInstances (Data.ElfEdit.Types) 10 | Takes an ElfClass w, an ElfWidthConstraints w => a, and satisfies the 11 | constraints, producing an a. 12 | **** withArchConstraints 13 | A field of ArchitectureInfo, provides the architecture constraints to any 14 | computation that needs it. 15 | **** mkFinalCFGWithSyms 16 | Create a discovery state and a symbol-address map from an ELF file, the 17 | corresponding memory object, ArchitectureInfo, and DiscoveryOptions. 18 | 19 | * Implement first test 20 | ** Stub out separate HelloWorld test module 21 | with HelloWorld/ directory containing all the test executables and such. 22 | ** Factor out code in Main_reopt.hs that we need for test runs 23 | under Reopt 24 | ** Test should 25 | read in executable, create Elf and Memory objects for it, run mkFinalCFGWithSyms, 26 | basically do everything in the performReopt case for block discovery. Also, it 27 | should print out all the basic block information to a ".blocks" file. 28 | * Complete tests 29 | ** Blocks (done), Functions (done), LLVM (done), object file, full reoptimization 30 | * get rid of stderr output 31 | * Make tests fail on any error 32 | * Debug resulting failures 33 | * Integrate with llvm-as to test LLVM output 34 | * be able to perform analysis on .o files and integrate into test suite 35 | -------------------------------------------------------------------------------- /tests/x64/.gitignore: -------------------------------------------------------------------------------- 1 | *.ll 2 | *.blocks 3 | *.fns -------------------------------------------------------------------------------- /tests/x64/Makefile: -------------------------------------------------------------------------------- 1 | all: $(patsubst %c,%exe, $(wildcard *.c)) 2 | 3 | # We have a special rule for the tail call test case because we need 4 | # -O2 to convince gcc to emit a tail call, but we'd rather not have 5 | # that much aggressive optimization for the other tests because it 6 | # usually makes them trivial. 7 | test-tail-call.exe: test-tail-call.c 8 | gcc -fno-stack-protector -O2 -fno-inline -S -c $< -o test-tail-call.s 9 | gcc -fno-stack-protector -O2 -fno-inline -nostdlib $< -o $@ 10 | 11 | %.exe: %.s 12 | gcc -fno-stack-protector -nostdlib $< -o $@ 13 | 14 | %.s: %.c 15 | gcc -fno-stack-protector -foptimize-sibling-calls -S -c $< -o $@ 16 | 17 | .PRECIOUS: %.s 18 | 19 | clean: 20 | rm *.s *.exe 21 | -------------------------------------------------------------------------------- /tests/x64/test-conditional.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | int g = -11; 4 | 5 | void _start() { 6 | if(g > 0) { 7 | g = g + 1; 8 | } 9 | 10 | EXIT(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/x64/test-conditional.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/tests/x64/test-conditional.exe -------------------------------------------------------------------------------- /tests/x64/test-conditional.s: -------------------------------------------------------------------------------- 1 | .file "test2.c" 2 | .globl g 3 | .data 4 | .align 4 5 | .type g, @object 6 | .size g, 4 7 | g: 8 | .long -11 9 | .text 10 | .globl _start 11 | .type _start, @function 12 | _start: 13 | .LFB0: 14 | .cfi_startproc 15 | pushq %rbp 16 | .cfi_def_cfa_offset 16 17 | .cfi_offset 6, -16 18 | movq %rsp, %rbp 19 | .cfi_def_cfa_register 6 20 | movl g(%rip), %eax 21 | testl %eax, %eax 22 | jle .L2 23 | movl g(%rip), %eax 24 | addl $1, %eax 25 | movl %eax, g(%rip) 26 | .L2: 27 | #APP 28 | # 10 "test2.c" 1 29 | movq $60,%rax 30 | movq $0,%rdi 31 | syscall 32 | # 0 "" 2 33 | #NO_APP 34 | nop 35 | popq %rbp 36 | .cfi_def_cfa 7, 8 37 | ret 38 | .cfi_endproc 39 | .LFE0: 40 | .size _start, .-_start 41 | .ident "GCC: (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005" 42 | .section .note.GNU-stack,"",@progbits 43 | -------------------------------------------------------------------------------- /tests/x64/test-direct-calls.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | int g1; 4 | int g2; 5 | int g3; 6 | int g4; 7 | 8 | int f2() { 9 | return (int)&g2; 10 | } 11 | 12 | int f1(long l1, long l2, long l3) { 13 | long i1 = (long)&g1; 14 | i1 = l1 + i1 + l2 + l3; 15 | i1 += l3 * 2; 16 | i1 = i1 / (l2 - 100 + f2()); 17 | return (int)i1; 18 | } 19 | 20 | void _start() { 21 | long i1 = (long)&g1; 22 | long i2 = (long)&g2; 23 | long i3 = (long)&g3; 24 | g1 = f1(i1, i2, i3); 25 | EXIT(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/x64/test-direct-calls.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/tests/x64/test-direct-calls.exe -------------------------------------------------------------------------------- /tests/x64/test-indirect-call.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | int g = -11; 4 | 5 | int (*fptr)(int); 6 | 7 | int callee(int x) { 8 | return x * 2; 9 | } 10 | 11 | void _start() { 12 | fptr = callee; 13 | g = fptr(g); 14 | 15 | EXIT(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/x64/test-indirect-call.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/tests/x64/test-indirect-call.exe -------------------------------------------------------------------------------- /tests/x64/test-indirect-call.s: -------------------------------------------------------------------------------- 1 | .file "test-indirect-call.c" 2 | .globl g 3 | .data 4 | .align 4 5 | .type g, @object 6 | .size g, 4 7 | g: 8 | .long -11 9 | .comm fptr,8,8 10 | .text 11 | .globl callee 12 | .type callee, @function 13 | callee: 14 | .LFB0: 15 | .cfi_startproc 16 | pushq %rbp 17 | .cfi_def_cfa_offset 16 18 | .cfi_offset 6, -16 19 | movq %rsp, %rbp 20 | .cfi_def_cfa_register 6 21 | movl %edi, -4(%rbp) 22 | movl -4(%rbp), %eax 23 | addl %eax, %eax 24 | popq %rbp 25 | .cfi_def_cfa 7, 8 26 | ret 27 | .cfi_endproc 28 | .LFE0: 29 | .size callee, .-callee 30 | .globl _start 31 | .type _start, @function 32 | _start: 33 | .LFB1: 34 | .cfi_startproc 35 | pushq %rbp 36 | .cfi_def_cfa_offset 16 37 | .cfi_offset 6, -16 38 | movq %rsp, %rbp 39 | .cfi_def_cfa_register 6 40 | leaq callee(%rip), %rax 41 | movq %rax, fptr(%rip) 42 | movq fptr(%rip), %rax 43 | movl g(%rip), %edx 44 | movl %edx, %edi 45 | call *%rax 46 | movl %eax, g(%rip) 47 | #APP 48 | # 15 "test-indirect-call.c" 1 49 | movq $60,%rax 50 | movq $0,%rdi 51 | syscall 52 | # 0 "" 2 53 | #NO_APP 54 | nop 55 | popq %rbp 56 | .cfi_def_cfa 7, 8 57 | ret 58 | .cfi_endproc 59 | .LFE1: 60 | .size _start, .-_start 61 | .ident "GCC: (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005" 62 | .section .note.GNU-stack,"",@progbits 63 | -------------------------------------------------------------------------------- /tests/x64/test-just-exit.c: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | void _start() { 4 | EXIT(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/x64/test-just-exit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/tests/x64/test-just-exit.exe -------------------------------------------------------------------------------- /tests/x64/test-just-exit.s: -------------------------------------------------------------------------------- 1 | .file "test1.c" 2 | .text 3 | .globl _start 4 | .type _start, @function 5 | _start: 6 | .LFB0: 7 | .cfi_startproc 8 | pushq %rbp 9 | .cfi_def_cfa_offset 16 10 | .cfi_offset 6, -16 11 | movq %rsp, %rbp 12 | .cfi_def_cfa_register 6 13 | #APP 14 | # 4 "test1.c" 1 15 | movq $60,%rax 16 | movq $0,%rdi 17 | syscall 18 | # 0 "" 2 19 | #NO_APP 20 | nop 21 | popq %rbp 22 | .cfi_def_cfa 7, 8 23 | ret 24 | .cfi_endproc 25 | .LFE0: 26 | .size _start, .-_start 27 | .ident "GCC: (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005" 28 | .section .note.GNU-stack,"",@progbits 29 | -------------------------------------------------------------------------------- /tests/x64/test-tail-call.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This test case makes sure that macaw can find functions only 4 | reachable via tail call. 5 | 6 | callee1 issues a tail call to callee2. Note that macaw identifies 7 | callee2 as a function, but also includes its body as a block in 8 | callee1 (so that block appears in two function definitions). That 9 | seems fine. 10 | 11 | */ 12 | #include "util.h" 13 | 14 | int g = -11; 15 | 16 | void callee2(int x) { 17 | g += x; 18 | } 19 | 20 | void callee1(int x) { 21 | g += x * 2; 22 | callee2(x); 23 | } 24 | 25 | void _start() { 26 | callee1(g); 27 | 28 | EXIT(); 29 | } 30 | -------------------------------------------------------------------------------- /tests/x64/test-tail-call.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/tests/x64/test-tail-call.exe -------------------------------------------------------------------------------- /tests/x64/test-tail-call.s: -------------------------------------------------------------------------------- 1 | .file "test-tail-call.c" 2 | .text 3 | .p2align 4,,15 4 | .globl callee2 5 | .type callee2, @function 6 | callee2: 7 | .LFB0: 8 | .cfi_startproc 9 | addl %edi, g(%rip) 10 | ret 11 | .cfi_endproc 12 | .LFE0: 13 | .size callee2, .-callee2 14 | .p2align 4,,15 15 | .globl callee1 16 | .type callee1, @function 17 | callee1: 18 | .LFB1: 19 | .cfi_startproc 20 | leal (%rdi,%rdi), %eax 21 | addl %eax, g(%rip) 22 | jmp callee2 23 | .cfi_endproc 24 | .LFE1: 25 | .size callee1, .-callee1 26 | .p2align 4,,15 27 | .globl _start 28 | .type _start, @function 29 | _start: 30 | .LFB2: 31 | .cfi_startproc 32 | movl g(%rip), %edi 33 | call callee1 34 | #APP 35 | # 18 "test-tail-call.c" 1 36 | movq $60,%rax 37 | movq $0,%rdi 38 | syscall 39 | # 0 "" 2 40 | #NO_APP 41 | ret 42 | .cfi_endproc 43 | .LFE2: 44 | .size _start, .-_start 45 | .globl g 46 | .data 47 | .align 4 48 | .type g, @object 49 | .size g, 4 50 | g: 51 | .long -11 52 | .ident "GCC: (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005" 53 | .section .note.GNU-stack,"",@progbits 54 | -------------------------------------------------------------------------------- /tests/x64/util.h: -------------------------------------------------------------------------------- 1 | #define EXIT() \ 2 | asm("movq $60,%rax\n" \ 3 | "movq $0,%rdi\n" \ 4 | "syscall") 5 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | This directory contains extra executables that may be of interest to 2 | Reopt users or developers. 3 | 4 | - `LLVMDumpInstr`: A utility for dumping LLVM for bytestrings. 5 | - `dump_debug_data`: A utility for exporting DWARF debug data. 6 | - `dump_vtables`: A utility for dumping C++ vtables from an executable. 7 | 8 | In addition, there are several scripts 9 | 10 | - `utils/dump_bytes.sh`: Use objdump to generate diassembly from a bytes. 11 | - `utils/dump_instr.sh`: Use objdump to generate diassembly from assembly (for testing purposes). -------------------------------------------------------------------------------- /tools/dump_debug_data/Main.hs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import qualified Data.ByteString as BS 4 | import Data.ElfEdit 5 | import Data.Macaw.Dwarf 6 | import System.Environment 7 | import System.IO 8 | 9 | run :: Elf v -> IO () 10 | run e = do 11 | case dwarfInfoFromElf e of 12 | (nonFatalErrors, cunits) -> do 13 | hPutStrLn stderr "Errors:" 14 | mapM_ (hPutStrLn stderr . (" " ++)) nonFatalErrors 15 | mapM_ print cunits 16 | 17 | main :: IO () 18 | main = do 19 | [path] <- getArgs 20 | bs <- BS.readFile path 21 | case parseElf bs of 22 | Elf64Res _ e -> do 23 | run e 24 | Elf32Res _ e -> do 25 | run e 26 | ElfHeaderError _ msg -> do 27 | hPutStrLn stderr $ 28 | "Error parsing file:\n" 29 | ++ " " ++ msg 30 | -------------------------------------------------------------------------------- /tools/reopt-checker/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Galois Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in 13 | the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of Galois, Inc. nor the names of its contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /tools/reopt-checker/README.md: -------------------------------------------------------------------------------- 1 | # reopt-checker 2 | 3 | This is a utility program that runs various checks to ensure 4 | reopt's underlying algorithms understand the inputs. 5 | 6 | ## Usage 7 | 8 | Run `reopt-checker` with the names of any executable files or 9 | directories to check. Directories are checked recursively 10 | automatically. Symbolic links in directories are not followed. 11 | 12 | If any inconsistencies are found, the name of the file and brief 13 | description are printed. 14 | -------------------------------------------------------------------------------- /tools/reopt-checker/reopt-checker.cabal: -------------------------------------------------------------------------------- 1 | name: reopt-checker 2 | version: 0.1.0 3 | author: Galois, Inc. 4 | maintainer: jhendrix@galois.com 5 | build-type: Simple 6 | cabal-version: >= 1.10 7 | license: BSD3 8 | license-file: LICENSE 9 | 10 | executable reopt-checker 11 | default-language: Haskell2010 12 | build-depends: 13 | base >= 0, 14 | bytestring, 15 | containers, 16 | directory, 17 | elf-edit >= 0.38, 18 | filepath, 19 | mtl, 20 | process, 21 | reopt, 22 | vector 23 | 24 | hs-source-dirs: src 25 | main-is: Main.hs 26 | -------------------------------------------------------------------------------- /tools/reopt-tools.cabal: -------------------------------------------------------------------------------- 1 | name: reopt-tools 2 | version: 0.0.1 3 | author: Galois, Inc. 4 | maintainer: jhendrix@galois.com 5 | build-type: Simple 6 | cabal-version: >= 1.9.2 7 | 8 | flag enable-hpc 9 | Description: Collect HPC coverage information. 10 | Default: False 11 | 12 | flag enable-arm 13 | Description: Enable support for ARM binaries 14 | Default: False 15 | 16 | executable dump_debug_data 17 | build-depends: 18 | base >= 4, 19 | bytestring, 20 | elf-edit, 21 | macaw-base, 22 | reopt 23 | hs-source-dirs: dump_debug_data 24 | main-is: Main.hs 25 | 26 | executable dump_vtables 27 | build-depends: 28 | ansi-wl-pprint, 29 | base >= 4, 30 | bytestring, 31 | containers, 32 | directory, 33 | elf-edit, 34 | lens, 35 | macaw-base, 36 | parameterized-utils, 37 | reopt, 38 | split, 39 | vector 40 | hs-source-dirs: dump_vtables 41 | main-is: Main.hs -------------------------------------------------------------------------------- /tools/utils/ConcreteDumpInstr.hs: -------------------------------------------------------------------------------- 1 | -- Based on flexdis86.git/utils/DumpInstr.hs. 2 | module Main where 3 | 4 | import Control.Monad (forM_, when) 5 | import qualified Data.ByteString as BS 6 | import Data.Maybe (catMaybes) 7 | import Data.Parameterized.NatRepr 8 | import Numeric (readHex) 9 | import System.Environment (getArgs) 10 | import System.Exit (exitFailure) 11 | 12 | import Flexdis86 13 | 14 | import Data.Macaw.CFG (Value(..)) 15 | import Data.Macaw.X86.Semantics (execInstruction) 16 | 17 | import Reopt.Concrete.MachineState 18 | import Reopt.Concrete.Semantics as C 19 | 20 | usageExit :: IO () 21 | usageExit = do putStrLn "DumpInstr aa bb cc dd ee ff ..." 22 | exitFailure 23 | 24 | main :: IO () 25 | main = do args <- getArgs 26 | when (args == []) usageExit 27 | 28 | let nums = map readHex args 29 | 30 | when (any (\v -> length v /= 1 || any ((/=) 0 . length . snd) v) nums) usageExit 31 | 32 | let bs = BS.pack $ map (fst . head) nums 33 | 34 | let diss = disassembleBuffer bs 35 | forM_ diss $ \dis -> do 36 | case disInstruction dis of 37 | Nothing ->return () 38 | Just i -> do 39 | putStrLn $ "Semantics for " ++ show i ++ ":" 40 | case execInstruction (ValueExpr (Literal (bitVector knownNat (fromIntegral (disLen dis))))) i of 41 | Nothing -> error "Reopt.Semantics.FlexdisMatcher.execInstruction returned 'Nothing'!" 42 | Just result -> print . C.ppStmts . C.execSemantics $ result 43 | -------------------------------------------------------------------------------- /tools/utils/cleaner.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python 2 | 3 | import sys 4 | import re 5 | 6 | filename = sys.argv[1] 7 | 8 | myfile = open(filename, "r") 9 | 10 | fileFormatFixer = re.compile(r'.*file format.*') 11 | zeroFixer = re.compile(r' *<.*>| *#.*|\+0x0') # remove +0x0 because we can't tell when we need it 12 | stringFixer = re.compile(r'(stos|scas|cmps|movs) .*') # remove implicit arguments on strings 13 | nopFixer = re.compile(r'(data32 )*nop( *)(BYTE|.?WORD|XMMWORD) PTR (.s:)?') # remove pointer widths on nops 14 | voidFixer = re.compile(r'(prefetchnta|prefetcht0|prefetchw|prefetch)( *)(BYTE|.?WORD|XMMWORD) PTR ') 15 | nullFixer = re.compile(r'(movnti|movntdq|movntdqa)( *)(BYTE|.?WORD|XMMWORD) PTR ') 16 | xmmMovFixer = re.compile(r'(mulss|mulsd|movq|movd|movss|movsd|movhps|movhpd|movlps|movlpd)(.*?)(BYTE|.?WORD|XMMWORD) PTR ') 17 | movabsFixer = re.compile(r'movabs') # change movabs to mov 18 | floatRegisterFixer = re.compile(r'st(\(.\))') 19 | funcstartFixer = re.compile(r'^\w* <\S*>:$') 20 | movdFixer = re.compile(r'movd ') 21 | prefetchFixer = re.compile(r'prefetch\w* ') 22 | 23 | for line in myfile.readlines(): 24 | if funcstartFixer.match(line) != None or fileFormatFixer.match(line) != None: 25 | continue 26 | line = zeroFixer.sub("", line) 27 | line = floatRegisterFixer.sub("st", line) 28 | line = stringFixer.sub(r'\g<1>', line) 29 | line = nopFixer.sub(r'nop ', line) 30 | line = voidFixer.sub(r'\g<1>\g<2>', line) 31 | line = nullFixer.sub(r'\g<1>\g<2>', line) 32 | line = movabsFixer.sub("mov ", line) 33 | line = xmmMovFixer.sub(r'\g<1>\g<2>', line) 34 | line = movdFixer.sub(r'movq ', line) 35 | line = prefetchFixer.sub(r'prefetch ', line) 36 | line = line.rstrip() 37 | if line != "": 38 | print (line) 39 | -------------------------------------------------------------------------------- /tools/utils/compare.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | tempobjdumps=`mktemp --tmpdir=.` 4 | tempobjdumpc=`mktemp --tmpdir=.` 5 | tempreopts=`mktemp --tmpdir=.` 6 | tempreoptc=`mktemp --tmpdir=.` 7 | tempdiff=`mktemp --tmpdir=.` 8 | objdump -d -M intel $1 > $tempobjdumps 9 | ./cleaner.py $tempobjdumps > $tempobjdumpc 10 | ../.cabal-sandbox/bin/reopt -d $1 > $tempreopts 11 | ./cleaner.py $tempreopts > $tempreoptc 12 | diff $tempobjdumpc $tempreoptc > $tempdiff 13 | ./diffcleaner.py $tempdiff 14 | 15 | rm $tempobjdumps 16 | rm $tempobjdumpc 17 | rm $tempreopts 18 | rm $tempreoptc 19 | rm $tempdiff 20 | -------------------------------------------------------------------------------- /tools/utils/concrete-dump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | out=`mktemp testfile-XXXXXX` 6 | out_obj=${out%.S}.o 7 | 8 | cat < $out 9 | .text 10 | $@ 11 | EOF 12 | 13 | gcc -x assembler -c $out 14 | objdump --disassembler-options=intel-mnemonic -dw $out_obj | sed -n 's/^[[:space:]]*0:[[:space:]]*//p' 15 | objdump --disassembler-options=intel-mnemonic -dw $out_obj | sed -n 's/^[[:space:]]*0:[[:space:]]*//p' | cut -f1 | xargs ConcreteDumpInstr 16 | rm -f $out $out_obj 17 | -------------------------------------------------------------------------------- /tools/utils/diffcleaner.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python 2 | 3 | import sys 4 | import re 5 | 6 | filename = sys.argv[1] 7 | 8 | myfile = open(filename, "r") 9 | 10 | openMatcher = re.compile(r'^\w') 11 | AVXMatcher = re.compile('> \\w*:\tc[45]') 12 | 13 | buf = "" 14 | printBuf = False 15 | startLine = False 16 | midLine = False 17 | for line in myfile.readlines(): 18 | if midLine == True: 19 | midLine = False 20 | if AVXMatcher.match(line): 21 | printBuf = False 22 | if openMatcher.match(line): 23 | if printBuf: 24 | print(buf) 25 | buf = "" 26 | printBuf = True 27 | if line == "---\n": 28 | midLine = True 29 | buf = buf + line 30 | -------------------------------------------------------------------------------- /tools/utils/dump_bytes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | out=`mktemp testfile-XXXXXX` 4 | out_obj=${out%.S}.o 5 | 6 | cat < $out 7 | .text 8 | EOF 9 | 10 | for i in $@ 11 | do 12 | echo ".byte 0x$i" >> $out 13 | done 14 | 15 | gcc -x assembler -c $out 16 | objdump -d $out_obj | grep '0:' 17 | objdump --disassembler-options=intel-mnemonic -d $out_obj | grep '0:' 18 | rm -f $out $out_obj 19 | -------------------------------------------------------------------------------- /tools/utils/dump_instr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | out=`mktemp testfile-XXXXXX` 6 | out_obj=${out%.S}.o 7 | 8 | cat < $out 9 | .text 10 | $@ 11 | EOF 12 | 13 | gcc -x assembler -c $out 14 | objdump -d $out_obj | grep '0:' 15 | objdump --disassembler-options=intel-mnemonic -d $out_obj | grep '0:' 16 | rm -f $out $out_obj 17 | -------------------------------------------------------------------------------- /tools/utils/llvm-dump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | out=`mktemp testfile-XXXXXX` 6 | out_obj=${out%.S}.o 7 | 8 | cat < $out 9 | .text 10 | $@ 11 | EOF 12 | 13 | gcc -x assembler -c $out 14 | objdump --disassembler-options=intel-mnemonic -dw $out_obj | sed -n 's/^[[:space:]]*[0-9a-f]*:[[:space:]]*//p' 15 | objdump --disassembler-options=intel-mnemonic -dw $out_obj | sed -n 's/^[[:space:]]*[0-9a-f]*:[[:space:]]*//p' | cut -f1 | xargs LLVMDumpInstr 16 | rm -f $out $out_obj 17 | -------------------------------------------------------------------------------- /tools/utils/mkbin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | outtmp=`mktemp testfile-XXXXXX` 6 | 7 | if $( which gobjcopy > /dev/null 2>&1 ); 8 | then 9 | OC=`which gobjcopy` 10 | else 11 | OC=`which objcopy` 12 | fi 13 | 14 | out=$1 15 | shift 16 | 17 | cat < $outtmp.S 18 | .text 19 | .global _main 20 | _main: 21 | $@ 22 | EOF 23 | 24 | gcc -x assembler $outtmp.S -o $outtmp 25 | $OC -O elf64-x86-64 $outtmp $out 26 | rm -f $outtmp.S $outtmp 27 | 28 | -------------------------------------------------------------------------------- /typegen-test-programs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | SOURCES := $(wildcard *.c) 4 | ROOTS := $(patsubst %.c,%,${SOURCES}) 5 | TARGETS := ${foreach bin,${ROOTS},$(foreach lvl,O0 O1 O2,$(bin)_$(lvl).exe)} 6 | 7 | CFLAGS += -std=c11 8 | 9 | all: ${TARGETS} 10 | 11 | # hack 12 | %_O0.exe: %.c 13 | $(CC) $(CFLAGS) -O0 -o $@ $< 14 | 15 | %_O1.exe: %.c 16 | $(CC) $(CFLAGS) -O1 -o $@ $< 17 | 18 | %_O2.exe: %.c 19 | $(CC) $(CFLAGS) -O2 -o $@ $< 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /typegen-test-programs/README.md: -------------------------------------------------------------------------------- 1 | 2 | Type generation examples 3 | ======================== 4 | 5 | This directory contains examples for testing the type inference support in reopt. 6 | 7 | -------------------------------------------------------------------------------- /typegen-test-programs/byte_loop.c: -------------------------------------------------------------------------------- 1 | // byte_loop.c --- simple byte loop 2 | 3 | #include "test.h" 4 | 5 | #define N 1000 6 | char bytes[N]; 7 | 8 | int byte_loop_result; 9 | 10 | int NOINLINE 11 | byte_loop(char *p, int n) { 12 | int count = 0; 13 | for (int i = 0; i < n; i++) 14 | count += *(p++); 15 | return count; 16 | } 17 | 18 | void NOINLINE 19 | doit(void) { 20 | byte_loop_result = byte_loop(bytes, N); 21 | } 22 | 23 | int 24 | main(void) { 25 | doit(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /typegen-test-programs/make_in_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # compiles in a docker container 4 | 5 | 6 | IMAGE=gcc:4.9 7 | 8 | docker run --rm -v "$PWD":/workspace -w /workspace $IMAGE make 9 | -------------------------------------------------------------------------------- /typegen-test-programs/mixed_struct_pointer.c: -------------------------------------------------------------------------------- 1 | // mixed_struct_pointer.c --- passing a pointer into a function containing a bitvec and a pointer 2 | 3 | 4 | #include "test.h" 5 | 6 | int global_v = 0; 7 | 8 | struct global_struct { 9 | int *ptr; 10 | int val; 11 | } global_struct_v = { &global_v, 42 }; 12 | 13 | void NOINLINE 14 | add(struct global_struct *p) { 15 | *(p->ptr) += p->val; 16 | } 17 | 18 | void NOINLINE 19 | doit(void) { 20 | add(&global_struct_v); 21 | } 22 | 23 | int 24 | main(void) { 25 | doit(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /typegen-test-programs/nested_mutual_rec_types.c: -------------------------------------------------------------------------------- 1 | // nested_mutual_rec_types.c --- Nested, mutually recursive types. 2 | 3 | #include 4 | #include "test.h" 5 | 6 | struct forest; 7 | 8 | struct tree { 9 | int val; 10 | struct forest *children; 11 | }; 12 | 13 | struct forest { 14 | struct tree *child; 15 | struct forest *next; 16 | }; 17 | 18 | struct tree global_tree; 19 | 20 | int NOINLINE tree_sum(struct tree *p); 21 | 22 | int NOINLINE 23 | forest_sum(struct forest *p) { 24 | int sum = 0; 25 | for (struct forest *ptr = p; p; p = p->next) { 26 | sum += tree_sum(p->child); 27 | } 28 | return sum; 29 | } 30 | 31 | int NOINLINE 32 | tree_sum(struct tree *p) { 33 | if (p == NULL) { 34 | return 0; 35 | } else { 36 | int children_sum = forest_sum(p->children); 37 | return (children_sum + p->val); 38 | } 39 | } 40 | 41 | void NOINLINE 42 | doit(void) { 43 | tree_sum(&global_tree); 44 | } 45 | 46 | int 47 | main(void) { 48 | doit(); 49 | return 0; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /typegen-test-programs/nested_struct_ptr.c: -------------------------------------------------------------------------------- 1 | // nested_struct_pointer.c --- passing a pointer into a function containing a bitvec and a pointer 2 | 3 | #include "test.h" 4 | 5 | int global_v = 0; 6 | 7 | struct global_struct { 8 | int *ptr; 9 | int val; 10 | } global_struct_v = { &global_v, 42 }; 11 | 12 | struct super_struct { 13 | int some_val; 14 | struct global_struct glob; 15 | } global_super_struct; 16 | 17 | 18 | void NOINLINE 19 | init_super(struct super_struct *p) { 20 | p->some_val = 42; 21 | p->glob.ptr = &global_v; 22 | p->glob.val = 43; 23 | } 24 | 25 | void NOINLINE 26 | add(struct global_struct *p) { 27 | *(p->ptr) += p->val; 28 | } 29 | 30 | void NOINLINE 31 | add_super(struct super_struct *p) { 32 | add(&(p->glob)); 33 | } 34 | 35 | void NOINLINE 36 | doit(void) { 37 | init_super(&global_super_struct); 38 | add_super(&global_super_struct); 39 | add(&global_struct_v); 40 | } 41 | 42 | int 43 | main(void) { 44 | doit(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /typegen-test-programs/nested_struct_ptr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/typegen-test-programs/nested_struct_ptr.o -------------------------------------------------------------------------------- /typegen-test-programs/nested_struct_ptr2.c: -------------------------------------------------------------------------------- 1 | // nested_struct_ptr2.c --- passing a pointer into a function containing a bitvec and a pointer 2 | 3 | 4 | #include "test.h" 5 | 6 | int global_v = 0; 7 | 8 | struct global_struct { 9 | int *ptr; 10 | int val; 11 | } global_struct_v = { &global_v, 42 }; 12 | 13 | struct super_struct { 14 | int some_val; 15 | struct global_struct glob; 16 | int *some_pointer; 17 | }; 18 | 19 | // models global heap 20 | struct global_data { 21 | // padding doesn't seem to matter, nor does the order. 22 | // unsigned long padding1[4]; 23 | struct global_struct s2; 24 | // unsigned long padding2[4]; 25 | struct super_struct s1; 26 | // unsigned long padding3[4]; 27 | } global_data_v; 28 | 29 | void NOINLINE 30 | init_super(struct super_struct *p) { 31 | p->some_val = 42; 32 | p->glob.ptr = &global_v; 33 | p->glob.val = 43; 34 | p->some_pointer = &p->some_val; 35 | } 36 | 37 | void NOINLINE 38 | add(struct global_struct *p) { 39 | *(p->ptr) += p->val; 40 | } 41 | 42 | void NOINLINE 43 | add_super(struct super_struct *p) { 44 | add(&(p->glob)); 45 | } 46 | 47 | void NOINLINE 48 | doit(struct global_data *p) { 49 | init_super(&p->s1); 50 | add_super(&p->s1); 51 | add(&p->s2); 52 | } 53 | 54 | int 55 | main(void) { 56 | doit(&global_data_v); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /typegen-test-programs/simple_pointer.c: -------------------------------------------------------------------------------- 1 | // simple_pointer.c --- passing a pointer into a function to be incremented 2 | 3 | 4 | #include "test.h" 5 | 6 | int global_v = 0; 7 | 8 | void NOINLINE 9 | inc(int *p) { 10 | *p += 1; 11 | } 12 | 13 | void NOINLINE 14 | doit(void) { 15 | inc(&global_v); 16 | } 17 | 18 | int 19 | main(void) { 20 | doit(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /typegen-test-programs/test.h: -------------------------------------------------------------------------------- 1 | 2 | #define NOINLINE __attribute__((noinline)) 3 | 4 | -------------------------------------------------------------------------------- /typegen-test-programs/union_argument.c: -------------------------------------------------------------------------------- 1 | // union_argument.c --- passing a type dep. on another type 2 | 3 | #include "test.h" 4 | 5 | int global_v = 0; 6 | 7 | union u { 8 | int *ptr; 9 | int val; 10 | } global_u = { .ptr = &global_v }; 11 | 12 | int NOINLINE 13 | plusplus(int tag, union u *p) { 14 | if (tag) 15 | return ++(*(p->ptr)); 16 | else 17 | return ++(p->val); 18 | } 19 | 20 | void NOINLINE 21 | doit(void) { 22 | plusplus(global_v, &global_u); 23 | } 24 | 25 | int 26 | main(void) { 27 | doit(); 28 | return 0; 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /typegen-test-programs/union_in_struct.c: -------------------------------------------------------------------------------- 1 | // union_in_struct.c --- passing a dep. type 2 | 3 | #include "test.h" 4 | 5 | int global_v = 0; 6 | 7 | union u { 8 | int *ptr; 9 | int val; 10 | } global_u = { .ptr = &global_v }; 11 | 12 | struct s { 13 | int tag; 14 | union u u; 15 | } global_s = { 0, { .ptr = &global_v }}; 16 | 17 | int NOINLINE 18 | plusplus(struct s *p) { 19 | if (p->tag) 20 | return ++(*(p->u.ptr)); 21 | else 22 | return ++(p->u.val); 23 | } 24 | 25 | void NOINLINE 26 | doit(void) { 27 | plusplus(&global_s); 28 | } 29 | 30 | int 31 | main(void) { 32 | doit(); 33 | return 0; 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /vcg-test-programs/.gitignore: -------------------------------------------------------------------------------- 1 | *.crt 2 | *.dis 3 | *.cfg 4 | *.fns 5 | *.ll 6 | /*.ann 7 | /test_fpadd_diet_lld.exe 8 | /test_*.o 9 | /out 10 | /glibc/placeholder_initfini.o -------------------------------------------------------------------------------- /vcg-test-programs/README: -------------------------------------------------------------------------------- 1 | This directory contains a simple example that has been compiled 2 | with both Diet libc and glibc. 3 | 4 | We use the extension .exe to denote executables, and have a Makefile 5 | to build them. Because the verifier is tightly depend on exact layout 6 | choices made during compilation, we check in the executables even 7 | though they can be build from LLVM 7.0.1. 8 | 9 | The other examples will likely be integrated into this directory. 10 | -------------------------------------------------------------------------------- /vcg-test-programs/diet/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/diet/libc.a -------------------------------------------------------------------------------- /vcg-test-programs/diet/start.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/diet/start.o -------------------------------------------------------------------------------- /vcg-test-programs/glibc/crt1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/glibc/crt1.o -------------------------------------------------------------------------------- /vcg-test-programs/glibc/crti.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/glibc/crti.o -------------------------------------------------------------------------------- /vcg-test-programs/glibc/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/glibc/libc.a -------------------------------------------------------------------------------- /vcg-test-programs/glibc/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/glibc/libgcc.a -------------------------------------------------------------------------------- /vcg-test-programs/glibc/libgcc_eh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/glibc/libgcc_eh.a -------------------------------------------------------------------------------- /vcg-test-programs/glibc/placeholder_initfini.c: -------------------------------------------------------------------------------- 1 | // This defines _init and _fini functions that do nothing. 2 | 3 | void _init() { 4 | } 5 | 6 | void _fini() { 7 | } 8 | -------------------------------------------------------------------------------- /vcg-test-programs/nweb/.gitignore: -------------------------------------------------------------------------------- 1 | /nweb23.ann 2 | /nweb23.reopt.exe -------------------------------------------------------------------------------- /vcg-test-programs/nweb/Makefile: -------------------------------------------------------------------------------- 1 | # This builds nweb and runs the 2 | all : nweb23.reopt.exe nweb23.ann 3 | 4 | # Use cabal to run reopt if we are in source tree, and otherwise search path. 5 | ifneq ("$(wildcard ../../reopt.cabal)","") 6 | reopt := cabal run exe:reopt -- 7 | else 8 | reopt := reopt 9 | endif 10 | 11 | clean : 12 | rm -f nweb23.exe nweb23.reopt.exe nweb23.ann nweb23.ll 13 | 14 | .PHONY : all clean 15 | 16 | nweb23.exe : nweb23.c 17 | cc -o $@ -g $< 18 | 19 | nweb23.cfg : nweb23.exe nweb.h 20 | $(reopt) --cfg -o $@ --header nweb.h nweb23.exe 21 | .PHONY : nweb23.cfg 22 | 23 | nweb23.fns : nweb23.exe nweb.h 24 | $(reopt) --fns -o $@ --header nweb.h nweb23.exe 25 | 26 | .PHONY : nweb23.fns 27 | 28 | nweb23.ll nweb23.ann : nweb23.exe nweb.h 29 | $(reopt) --export-llvm nweb23.ll --annotations nweb23.ann --header nweb.h nweb23.exe || true 30 | 31 | .PHONY : nweb23.ann 32 | 33 | nweb23.reopt.exe : nweb23.exe 34 | $(reopt) -o nweb23.reopt.exe $< 35 | -------------------------------------------------------------------------------- /vcg-test-programs/nweb/README.md: -------------------------------------------------------------------------------- 1 | This directory contains the nweb web server. It has been tested to 2 | work with reopt. The makefile expects to be in the source tree or for 3 | reopt to be in the local path. It also expects `cc` to be a valid C 4 | compiler, and a Posix operating system. 5 | 6 | You can build the original executablew and build the artifact 7 | by running `make`. This will build the original executable, 8 | and run reopt to recompile and produce a new executable. Reopt's 9 | output is quite verbose and will report warnings, but these can 10 | be ignored for now. 11 | 12 | One reopt is built, you can run nweb by providing it with a port 13 | number and a directory with some content, e.g., 14 | 15 | ``` 16 | ./nweb23.reopt.exe 1238 content 17 | ``` 18 | -------------------------------------------------------------------------------- /vcg-test-programs/nweb/content/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | A very simple webpage 5 | 6 | 7 | 8 | 9 |

A very simple webpage.

10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /vcg-test-programs/nweb/integration_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | reopt nweb23.exe --header=nweb.h --export-llvm=nweb23.ll --annotations=nweb23.ann 4 | reopt-vcg nweb23.ann 5 | if [[ 0 -eq $? ]]; then 6 | echo "reopt-vcg succeeded!" 7 | exit 0 8 | elif [[ 1 -eq $? ]]; then 9 | # exit code of 1 means some verification conditions 10 | # failed to verify but no other errors were encountered 11 | echo "reopt-vcg succeeded in generating verification conditions, but some were not verified." 12 | exit 0 13 | else 14 | echo "reopt-vcg encountered errors during verification condition generation and/or during verification." 15 | exit 1 16 | fi 17 | -------------------------------------------------------------------------------- /vcg-test-programs/nweb/nweb.h: -------------------------------------------------------------------------------- 1 | 2 | typedef unsigned long size_t; 3 | typedef int pid_t; 4 | typedef long off_t; 5 | typedef unsigned uint32_t; 6 | typedef unsigned uint16_t; 7 | 8 | long read(int fd, void *buf, size_t count); 9 | long write(int fd, void* buf, size_t count); 10 | int strcmp(const char *s1, const char *s2); 11 | int strncmp(const char *s1, const char *s2, size_t n); 12 | pid_t getpid(); 13 | int chdir(const char *path); 14 | char *strcpy(char *dest, const char *src); 15 | size_t strlen(const char *s); 16 | int close(int fd); 17 | pid_t fork(); 18 | off_t lseek(int fd, off_t offset, int whence); 19 | 20 | //typedef void (*sighandler_t)(int); 21 | typedef void* sighandler_t; 22 | sighandler_t signal(int signum, sighandler_t handler); 23 | 24 | unsigned sleep(unsigned seconds); 25 | int setpgrp(); 26 | int socket(int domain, int type, int protocol); 27 | int atoi(const char *nptr); 28 | uint32_t htonl(uint32_t hostlong); 29 | uint16_t htons(uint16_t hostshort); 30 | 31 | 32 | typedef size_t socklen_t; 33 | int bind(int sockfd, const void *addr, socklen_t addrlen); 34 | int listen(int sockfd, int backlog); 35 | int accept(int sockfd, void *addr, socklen_t *addrlen); -------------------------------------------------------------------------------- /vcg-test-programs/nweb/nweb23.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/nweb/nweb23.exe -------------------------------------------------------------------------------- /vcg-test-programs/nweb/nweb23.manifest: -------------------------------------------------------------------------------- 1 | { "main" : "nweb.bc" 2 | , "modules" : [] 3 | , "native_libs" : [] 4 | , "ldflags" : [] 5 | , "static_args" : [] 6 | , "dynamic_args" : "2" 7 | } 8 | -------------------------------------------------------------------------------- /vcg-test-programs/test_add.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/test_add.bc -------------------------------------------------------------------------------- /vcg-test-programs/test_add.c: -------------------------------------------------------------------------------- 1 | long add(long x) { 2 | long y = x; 3 | return y + 1; 4 | } 5 | 6 | int main() { 7 | long x = add(42); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /vcg-test-programs/test_add.manifest: -------------------------------------------------------------------------------- 1 | { "main" : "add.bc" 2 | , "modules" : [] 3 | , "native_libs" : [] 4 | , "ldflags" : [] 5 | , "static_args" : [] 6 | , "dynamic_args" : "0" 7 | } 8 | -------------------------------------------------------------------------------- /vcg-test-programs/test_add_diet_ld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/test_add_diet_ld.exe -------------------------------------------------------------------------------- /vcg-test-programs/test_add_diet_lld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/test_add_diet_lld.exe -------------------------------------------------------------------------------- /vcg-test-programs/test_add_glibc_lld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/test_add_glibc_lld.exe -------------------------------------------------------------------------------- /vcg-test-programs/test_add_protos.h: -------------------------------------------------------------------------------- 1 | // This file provides annotations for test_add.c to help reopt 2 | // infer function arguments. 3 | 4 | typedef long uint64_t; 5 | 6 | uint64_t add(uint64_t x); 7 | 8 | long main(); 9 | -------------------------------------------------------------------------------- /vcg-test-programs/test_fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | uint64_t fib(uint64_t x) { 6 | if (x <= 1) { 7 | return x; 8 | } else { 9 | return fib(x-1)+fib(x-2); 10 | } 11 | } 12 | 13 | int main() { 14 | printf("fib(5): %" PRIx64 "\n", fib(5)); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /vcg-test-programs/test_fib.manifest: -------------------------------------------------------------------------------- 1 | { "main" : "fib.bc" 2 | , "modules" : [] 3 | , "native_libs" : [] 4 | , "ldflags" : [] 5 | , "static_args" : [] 6 | , "dynamic_args" : "0" 7 | } 8 | -------------------------------------------------------------------------------- /vcg-test-programs/test_fib_diet_ld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/test_fib_diet_ld.exe -------------------------------------------------------------------------------- /vcg-test-programs/test_fib_diet_lld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vcg-test-programs/test_fib_diet_lld.exe -------------------------------------------------------------------------------- /vcg-test-programs/test_fib_protos.h: -------------------------------------------------------------------------------- 1 | // This file provides annotations for test_add.c to help reopt 2 | // infer function arguments. 3 | 4 | typedef long uint64_t; 5 | 6 | uint64_t fib(uint64_t x); 7 | 8 | long main(); 9 | -------------------------------------------------------------------------------- /vcg-test-programs/test_fpadd.c: -------------------------------------------------------------------------------- 1 | double fpadd(double x) { 2 | long y = x; 3 | return y + 1; 4 | } 5 | 6 | int main() { 7 | double x = fpadd(42.0); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /vcg-test-programs/test_fpadd_protos.h: -------------------------------------------------------------------------------- 1 | // This file provides annotations for test_add.c to help reopt 2 | // infer function arguments. 3 | 4 | double fpadd(double x); 5 | 6 | long main(); 7 | -------------------------------------------------------------------------------- /vscode-plugin/.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | out 4 | -------------------------------------------------------------------------------- /vscode-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /node_modules 3 | /pirate-architecture-*.vsix 4 | /reopt-0.0.1.vsix 5 | /webpack.config.js 6 | /webpack.config.d.ts 7 | *.ann 8 | *.jsons 9 | *.tsbuildinfo 10 | -------------------------------------------------------------------------------- /vscode-plugin/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /vscode-plugin/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}", 15 | "${workspaceFolder}/example" 16 | ], 17 | "preLaunchTask": "compile", 18 | "outFiles": [ 19 | "${workspaceFolder}/out/**/*.js" 20 | ], 21 | "debugWebviews": true // experimental 22 | }, 23 | { 24 | "name": "Extension Tests", 25 | "type": "extensionHost", 26 | "request": "launch", 27 | "runtimeExecutable": "${execPath}", 28 | "args": [ 29 | "--extensionDevelopmentPath=${workspaceFolder}", 30 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 31 | ], 32 | "outFiles": [ 33 | "${workspaceFolder}/out/extension/test/**/*.js" 34 | ], 35 | "preLaunchTask": "${defaultBuildTask}" 36 | }, 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /vscode-plugin/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true, // set this to false to include "out" folder in search results 8 | "package-lock.json": true 9 | }, 10 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 11 | "typescript.tsc.autoDetect": "off", 12 | "files.associations": { 13 | "chrono": "cpp", 14 | "cstdint": "cpp", 15 | "ctime": "cpp", 16 | "limits": "cpp", 17 | "ratio": "cpp", 18 | "type_traits": "cpp" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vscode-plugin/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | }, 19 | { 20 | "label": "compile", 21 | "type": "npm", 22 | "script": "compile" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /vscode-plugin/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | examples 4 | node_modules 5 | out/extension/test/** 6 | src/** 7 | .gitignore 8 | tsconfig.json 9 | tsconfig-webview.json 10 | **/.eslintrc.json 11 | **/*.map 12 | **/*.ts 13 | -------------------------------------------------------------------------------- /vscode-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this plugin will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [Unreleased] 9 | 10 | ### Added 11 | 12 | - Began development of plugin. -------------------------------------------------------------------------------- /vscode-plugin/assets/codicon-list-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/codicon-list-tree.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-diagnostics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-diagnostics.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-full-window-annotated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-full-window-annotated.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-full-window-project-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-full-window-project-file.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-full-window-vcg-diagnostics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-full-window-vcg-diagnostics.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-full-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-full-window.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-generate-buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-generate-buttons.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-project-buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-project-buttons.png -------------------------------------------------------------------------------- /vscode-plugin/assets/reopt-vcg-diagnostics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/assets/reopt-vcg-diagnostics.png -------------------------------------------------------------------------------- /vscode-plugin/example/.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/ 2 | *.cfg 3 | *.dis 4 | *.fns 5 | *.ll 6 | *.rpj 7 | -------------------------------------------------------------------------------- /vscode-plugin/example/test_add_diet_lld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/example/test_add_diet_lld.exe -------------------------------------------------------------------------------- /vscode-plugin/reopt-0.0.1.vsix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaloisInc/reopt/7948b660aee0ccf2c7e46adccbef4fc2a49efcb7/vscode-plugin/reopt-0.0.1.vsix -------------------------------------------------------------------------------- /vscode-plugin/schemas/rpj-schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema#", 3 | "$id": "reopt-project", 4 | "type": "object", 5 | "properties": { 6 | "annotations": { 7 | "type": "string" 8 | }, 9 | "binaryFile": { 10 | "type": "string" 11 | }, 12 | "excludes": { 13 | "type": "array", 14 | "items": { 15 | "type": "string" 16 | } 17 | }, 18 | "headers": { 19 | "type": "array", 20 | "items": { 21 | "type": "string" 22 | } 23 | }, 24 | "includes": { 25 | "type": "array", 26 | "items": { 27 | "type": "string" 28 | } 29 | }, 30 | "name": { 31 | "type": [ 32 | "string", 33 | "null" 34 | ] 35 | }, 36 | "outputNameCFG": { 37 | "type": [ 38 | "string", 39 | "null" 40 | ] 41 | }, 42 | "outputNameDisassemble": { 43 | "type": [ 44 | "string", 45 | "null" 46 | ] 47 | }, 48 | "outputNameFunctions": { 49 | "type": [ 50 | "string", 51 | "null" 52 | ] 53 | }, 54 | "outputNameLLVM": { 55 | "type": [ 56 | "string", 57 | "null" 58 | ] 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /vscode-plugin/src/activity-webview/entry-point.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import * as ReactDOM from 'react-dom' 3 | 4 | import * as Constants from '@shared/constants' 5 | import * as E2W from '@shared/extension-to-activity-webview' 6 | import * as Interfaces from '@shared/interfaces' 7 | 8 | import { ActivityWebview } from './webview' 9 | 10 | interface ActivityWebviewWindow extends Window { 11 | [E2W.activityWebviewInitialDataKey]: E2W.ActivityWebviewInitialData, 12 | } 13 | declare const window: ActivityWebviewWindow 14 | 15 | declare const acquireVsCodeApi: () => Interfaces.ActivityViewVSCodeAPI 16 | const vscode = acquireVsCodeApi() 17 | 18 | const container = document.getElementById(Constants.activityWebviewId) as HTMLDivElement | null 19 | 20 | if (container === null) { 21 | console.log(`Webview container with id ${Constants.activityWebviewId} is missing`) 22 | } else { 23 | ReactDOM.render( 24 | , 28 | container, 29 | ) 30 | } 31 | -------------------------------------------------------------------------------- /vscode-plugin/src/activity-webview/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig-common.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "../../out", 6 | "paths": { 7 | "@shared/*": [ 8 | "../shared/*", 9 | ], 10 | }, 11 | "rootDir": "..", 12 | }, 13 | "include": [ 14 | ".", 15 | ], 16 | "references": [ 17 | { 18 | "path": "../shared", 19 | }, 20 | ], 21 | } 22 | -------------------------------------------------------------------------------- /vscode-plugin/src/extension/check-magic-number.ts: -------------------------------------------------------------------------------- 1 | import * as Promisified from '@shared/promisified' 2 | 3 | const elfMagicNumber = Uint8Array.from([0x7F, 0x45, 0x4C, 0x46]) 4 | 5 | export async function checkMagicNumber( 6 | filePath: string, 7 | ): Promise { 8 | 9 | const fd = await Promisified.open(filePath, 'r') 10 | const buffer = new Uint8Array(elfMagicNumber.length) 11 | const read = await Promisified.read(fd, buffer, 0, elfMagicNumber.length, 0) 12 | if (read.bytesRead !== elfMagicNumber.length) { 13 | return false 14 | } 15 | Promisified.close(fd) 16 | 17 | return (Buffer.compare(buffer, elfMagicNumber) === 0) 18 | 19 | } 20 | -------------------------------------------------------------------------------- /vscode-plugin/src/extension/nonce.ts: -------------------------------------------------------------------------------- 1 | export function getNonce(): string { 2 | let text = '' 3 | const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 4 | for (let i = 0; i < 32; i++) { 5 | text += possible.charAt(Math.floor(Math.random() * possible.length)) 6 | } 7 | return text 8 | } 9 | -------------------------------------------------------------------------------- /vscode-plugin/src/extension/symbol-provider.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode' 2 | 3 | function* lineIterator( 4 | document: vscode.TextDocument, 5 | ): Generator { 6 | for (let i = 0; i < document.lineCount; i++) { 7 | yield document.lineAt(i) 8 | } 9 | } 10 | 11 | function inspectLineForSymbol( 12 | document: vscode.TextDocument, 13 | line: vscode.TextLine, 14 | ): vscode.SymbolInformation[] { 15 | 16 | const text = line.text 17 | 18 | if (text.startsWith('declare') || text.startsWith('define')) { 19 | const atSignIndex = text.indexOf('@') 20 | const suffix = text.slice(atSignIndex) 21 | const parenIndex = suffix.indexOf('(') 22 | const functionName = suffix.slice(0, parenIndex) 23 | 24 | const start = new vscode.Position( 25 | line.range.start.line, 26 | atSignIndex, 27 | ) 28 | 29 | const end = new vscode.Position( 30 | line.range.end.line, 31 | atSignIndex + parenIndex, 32 | ) 33 | 34 | return [ 35 | new vscode.SymbolInformation( 36 | functionName, 37 | vscode.SymbolKind.Function, 38 | '', 39 | new vscode.Location(document.uri, new vscode.Range(start, end)) 40 | ), 41 | ] 42 | 43 | } 44 | 45 | return [] 46 | 47 | } 48 | 49 | export class LLVMDocumentSymbolProvider implements vscode.DocumentSymbolProvider { 50 | 51 | provideDocumentSymbols( 52 | document: vscode.TextDocument, 53 | _token?: vscode.CancellationToken, 54 | ): vscode.SymbolInformation[] { 55 | 56 | return ( 57 | Array.from(lineIterator(document)).flatMap( 58 | (line) => inspectLineForSymbol(document, line) 59 | ) 60 | ) 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /vscode-plugin/src/extension/tree-data-provider.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode' 2 | 3 | interface LLVMFunction { 4 | name: string 5 | location: { 6 | line: number 7 | } 8 | } 9 | 10 | function* fakeLLVMParser( 11 | llvmContents: string, 12 | ): Generator { 13 | 14 | for (const [index, element] of llvmContents.split('\n').entries()) { 15 | if (element.startsWith('declare') || element.startsWith('define')) { 16 | const suffix = element.slice(element.indexOf('@')) 17 | const functionName = suffix.slice(0, suffix.indexOf('(')) 18 | yield { name: functionName, location: { line: index } } 19 | } 20 | } 21 | 22 | } 23 | 24 | export class ReoptNodeProvider implements vscode.TreeDataProvider, vscode.TextDocumentContentProvider { 25 | 26 | getChildren(_e?: LLVMFunction): LLVMFunction[] { 27 | const currentDocument = vscode.window.activeTextEditor?.document 28 | if ( 29 | currentDocument === undefined 30 | || currentDocument.languageId !== 'llvm' 31 | ) { return [] } 32 | return Array.from(fakeLLVMParser(currentDocument.getText())) 33 | } 34 | 35 | getTreeItem(e: LLVMFunction): vscode.TreeItem { 36 | return new vscode.TreeItem(e.name) 37 | } 38 | 39 | provideTextDocumentContent(): vscode.ProviderResult { 40 | const currentDocument = vscode.window.activeTextEditor?.document 41 | return currentDocument?.getText() 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /vscode-plugin/src/extension/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig-common.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "../../out", 6 | "paths": { 7 | "@shared/*": [ 8 | "../shared/*", 9 | ], 10 | }, 11 | "rootDir": "..", 12 | }, 13 | "include": [ 14 | ".", 15 | ], 16 | "references": [ 17 | { 18 | "path": "../shared", 19 | }, 20 | ], 21 | } 22 | -------------------------------------------------------------------------------- /vscode-plugin/src/reopt-vcg-webview/entry-point.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import * as ReactDOM from 'react-dom' 3 | 4 | import * as Constants from '@shared/constants' 5 | import * as E2W from '@shared/extension-to-reopt-vcg-webview' 6 | import * as Interfaces from '@shared/interfaces' 7 | 8 | import { Webview } from './webview' 9 | 10 | interface WebviewWindow extends Window { 11 | [E2W.webviewInitialDataKey]: E2W.WebviewInitialData, 12 | } 13 | declare const window: WebviewWindow 14 | 15 | declare const acquireVsCodeApi: () => Interfaces.ReoptVCGViewVSCodeAPI 16 | const vscode = acquireVsCodeApi() 17 | 18 | const container = document.getElementById(Constants.activityWebviewId) as HTMLDivElement | null 19 | 20 | if (container === null) { 21 | console.log(`Webview container with id ${Constants.webviewId} is missing`) 22 | } else { 23 | ReactDOM.render( 24 | , 28 | container, 29 | ) 30 | } 31 | -------------------------------------------------------------------------------- /vscode-plugin/src/reopt-vcg-webview/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig-common.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "../../out", 6 | "paths": { 7 | "@shared/*": [ 8 | "../shared/*", 9 | ], 10 | }, 11 | "rootDir": "..", 12 | }, 13 | "include": [ 14 | ".", 15 | ], 16 | "references": [ 17 | { 18 | "path": "../shared", 19 | }, 20 | ], 21 | } 22 | -------------------------------------------------------------------------------- /vscode-plugin/src/shared/extension-to-activity-webview.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode' 2 | 3 | import * as Interfaces from './interfaces' 4 | 5 | /** 6 | * WARNING: make sure that all of the data you put in messages is serialized. In 7 | * particular, avoid using classes, since you will not get back the same object 8 | * on the other end! 9 | */ 10 | 11 | export const activityWebviewInitialDataKey = 'activityWebviewInitialData' 12 | export interface ActivityWebviewInitialData { 13 | readonly projectName?: string 14 | readonly symbols: Interfaces.SerializationOf[] 15 | } 16 | 17 | export type ExtensionToActivityWebview 18 | = ClosedProject 19 | | OpenedProject 20 | | SymbolList 21 | 22 | export const closedProjectTag = 'ClosedProject' 23 | export interface ClosedProject { 24 | readonly tag: typeof closedProjectTag 25 | } 26 | 27 | export const openedProjectTag = 'OpenedProject' 28 | export interface OpenedProject { 29 | readonly tag: typeof openedProjectTag 30 | readonly projectName: string 31 | } 32 | 33 | export const symbolListTag = 'SymbolList' 34 | export interface SymbolList { 35 | readonly tag: typeof symbolListTag 36 | readonly symbols: Interfaces.SerializationOf[] 37 | } 38 | -------------------------------------------------------------------------------- /vscode-plugin/src/shared/extension-to-reopt-vcg-webview.ts: -------------------------------------------------------------------------------- 1 | import * as Interfaces from './interfaces' 2 | 3 | /** 4 | * WARNING: make sure that all of the data you put in messages is serialized. In 5 | * particular, avoid using classes, since you will not get back the same object 6 | * on the other end! 7 | */ 8 | 9 | 10 | export const webviewInitialDataKey = 'webviewInitialData' 11 | export type WebviewInitialData = { 12 | entries: Interfaces.ReoptVCGEntry[] 13 | } 14 | 15 | 16 | export enum Tags { 17 | addReoptVCGEntry = 'AddReoptVCGEntry', 18 | setReoptVCGEntries = 'SetReoptVCGEntries', 19 | } 20 | 21 | export type ExtensionToReoptVCGWebview 22 | = AddReoptVCGEntry 23 | | SetReoptVCGEntries 24 | 25 | export type AddReoptVCGEntry = Readonly<{ 26 | tag: Tags.addReoptVCGEntry 27 | entry: Interfaces.ReoptVCGEntry 28 | }> 29 | 30 | export type SetReoptVCGEntries = { 31 | tag: Tags.setReoptVCGEntries 32 | entries: Interfaces.ReoptVCGEntry[] 33 | } 34 | -------------------------------------------------------------------------------- /vscode-plugin/src/shared/package.json: -------------------------------------------------------------------------------- 1 | ../../package.json -------------------------------------------------------------------------------- /vscode-plugin/src/shared/promisified.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | import * as util from 'util' 3 | 4 | export const close = util.promisify(fs.close) 5 | export const open = util.promisify(fs.open) 6 | export const read = util.promisify(fs.read) 7 | export const readFile = util.promisify(fs.readFile) 8 | export const stat = util.promisify(fs.stat) 9 | export const writeFile = util.promisify(fs.writeFile) 10 | -------------------------------------------------------------------------------- /vscode-plugin/src/shared/reopt-vcg-webview-to-extension.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * WARNING: make sure that all of the data you put in messages is serialized. In 3 | * particular, avoid using classes, since you will not get back the same object 4 | * on the other end! 5 | */ 6 | 7 | export type ReoptVCGWebviewToExtension 8 | = never 9 | -------------------------------------------------------------------------------- /vscode-plugin/src/shared/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig-common.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "../../out", 6 | "paths": { 7 | "@root/*": [ 8 | "../../*", 9 | ], 10 | }, 11 | "rootDir": "..", 12 | }, 13 | "include": [ 14 | ".", 15 | "./package.json", 16 | ], 17 | "references": [ 18 | { 19 | "path": "../..", 20 | }, 21 | ], 22 | } 23 | -------------------------------------------------------------------------------- /vscode-plugin/src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path' 2 | 3 | import { runTests } from 'vscode-test' 4 | 5 | export async function main(): Promise { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../') 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index') 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }) 17 | } catch (err) { 18 | console.error('Failed to run tests') 19 | process.exit(1) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vscode-plugin/src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert' 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode' 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.') 10 | 11 | test('Sample test', () => { 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)) 13 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /vscode-plugin/src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path' 2 | 3 | import * as glob from 'glob' 4 | import * as Mocha from 'mocha' 5 | 6 | export function run(): Promise { 7 | // Create the mocha test 8 | const mocha = new Mocha({ 9 | ui: 'tdd', 10 | color: true, 11 | }) 12 | 13 | const testsRoot = path.resolve(__dirname, '..') 14 | 15 | return new Promise((c, e) => { 16 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 17 | if (err) { 18 | return e(err) 19 | } 20 | 21 | // Add files to the test suite 22 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))) 23 | 24 | try { 25 | // Run the mocha test 26 | mocha.run(failures => { 27 | if (failures > 0) { 28 | e(new Error(`${failures} tests failed.`)) 29 | } else { 30 | c() 31 | } 32 | }) 33 | } catch (err) { 34 | console.error(err) 35 | e(err) 36 | } 37 | }) 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /vscode-plugin/tsconfig-common.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "declaration": true, 5 | "declarationMap": true, 6 | "jsx": "react", 7 | "moduleResolution": "Node", 8 | "noFallthroughCasesInSwitch": true, 9 | "noImplicitReturns": true, 10 | "noUnusedParameters": true, 11 | "resolveJsonModule": true, 12 | "sourceMap": true, 13 | "strict": true, 14 | /* There is currently a bug where ES2020+ does not handle 15 | * chaining operator correctly! */ 16 | "target": "ES2019", 17 | }, 18 | "exclude": [ 19 | "node_modules", 20 | ".vscode-test" 21 | ], 22 | } 23 | -------------------------------------------------------------------------------- /vscode-plugin/tsconfig.json: -------------------------------------------------------------------------------- 1 | // see https://www.typescriptlang.org/docs/handbook/project-references.html 2 | { 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "baseUrl": ".", 6 | "composite": true, 7 | "module": "CommonJS", 8 | "paths": { 9 | "@extension/*": [ 10 | "src/extension/*", 11 | ], 12 | "@shared/*": [ 13 | "src/shared/*", 14 | ], 15 | "@webview/*": [ 16 | "src/webview/*", 17 | ], 18 | }, 19 | "resolveJsonModule": true, 20 | "rootDirs": [ 21 | "src/extension", 22 | "src/shared", 23 | "src/activity-webview", 24 | "src/reopt-vcg-webview", 25 | ], 26 | }, 27 | "files": [ 28 | "package.json", 29 | "webpack.config.ts", 30 | ], 31 | } 32 | -------------------------------------------------------------------------------- /vscode-plugin/webview-static/activity-webview.css: -------------------------------------------------------------------------------- 1 | a { 2 | cursor: pointer; 3 | } 4 | 5 | body { 6 | height: 100%; 7 | } 8 | 9 | input { 10 | background-color: var(--vscode-button-background); 11 | border: 1px solid black; 12 | border-radius: 0.25em; 13 | color: var(--vscode-button-foreground); 14 | margin-top: 0.25em; 15 | min-width: 12em; 16 | padding: 0.25em; 17 | } 18 | 19 | input.red { 20 | background-color: #f44336; 21 | color: white; 22 | } 23 | input.red:hover { 24 | background-color: #e57373; 25 | } 26 | 27 | input:hover { 28 | background-color: var(--vscode-button-hoverBackground); 29 | } 30 | 31 | .column { 32 | display: flex; 33 | flex-direction: column; 34 | height: 100%; 35 | } 36 | 37 | .container { 38 | height: 100%; 39 | } 40 | 41 | .column-header { 42 | flex-shrink: 0; 43 | } 44 | 45 | .column-body { 46 | flex-grow: 1; 47 | overflow-y: auto; 48 | } 49 | 50 | html { 51 | height: 100%; 52 | } 53 | 54 | .row { 55 | display: flex; 56 | flex-direction: row; 57 | } 58 | -------------------------------------------------------------------------------- /vscode-plugin/webview-static/contents.html: -------------------------------------------------------------------------------- 1 | This is the -------------------------------------------------------------------------------- /vscode-plugin/webview-static/webview.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-left: 0px; 3 | font-family: var(--vscode-font-family); 4 | } 5 | --------------------------------------------------------------------------------