Stratified Synthesis: Automatically Learning the X86-64 Instruction

Stratified Synthesis: Automatically Learning the X86-64 Instruction

Stratified Synthesis: Automatically Learning the x86-64 Instruction Set Stefan Heule Eric Schkufza Rahul Sharma Stanford University, USA VMware, USA Stanford University, USA [email protected] [email protected] [email protected] Alex Aiken Stanford University, USA [email protected] Abstract Categories and Subject Descriptors I.2.2 [Automatic Pro- The x86-64 ISA sits at the bottom of the software stack of gramming]: Program synthesis; F.3.1 [Specifying and Verify- most desktop and server software. Because of its importance, ing and Reasoning about Programs]: Specification techniques many software analysis and verification tools depend, either Keywords ISA specification, program synthesis, x86-64 explicitly or implicitly, on correct modeling of the semantics of x86-64 instructions. However, formal semantics for the 1. Introduction x86-64 ISA are difficult to obtain and often written manually The various x86 instruction sets have been ubiquitous for through great effort. We describe an automatically synthe- decades, and currently the Haswell family of processors is sized formal semantics of the input/output behavior for a widely used for server and desktop machines. Because of large fraction of the x86-64 Haswell ISA’s many thousands the importance of x86, many software analysis tools have of instruction variants. The key to our results is stratified been built that reason about programs written in x86 directly synthesis, where we use a set of instructions whose semantics (e.g., [2, 9, 24]) or that reason about programs in high-level are known to synthesize the semantics of additional instruc- languages that are then translated to x86 (e.g., [17]). All tions whose semantics are unknown. As the set of formally such tools require a precise formal semantics of the x86 described instructions increases, the synthesis vocabulary ISA. One might assume, then, that a formal semantics of the expands, making it possible to synthesize the semantics of current 64-bit x86 ISA (known as x86-64) would be readily increasingly complex instructions. available, but one would be wrong. In fact, the only published Using this technique we automatically synthesized for- description of the x86-64 ISA is the Intel manual [14] with mal semantics for 1,795 instruction variants of the x86-64 over 3,800 pages written in an ad-hoc combination of English Haswell ISA. We evaluate the learned semantics against man- and pseudo-code. There are two primary barriers to producing ually written semantics (where available) and find that they a formal specification of x86-64. First, the instruction set is are formally equivalent with the exception of 50 instructions, huge: x86-64 contains 981 unique mnemonics and a total of where the manually written semantics contain an error. We 3,684 instruction variants. Second, many of the instructions further find the learned formulas to be largely as precise as have complex semantics. For example, the rotate instruction manually written ones and of similar size. implicitly truncates its integer argument, modifies an implicit register operand, and depending on its input either changes the value of multiple condition registers or leaves them undefined. Many instructions have comparable edge cases Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed and variations, and the behaviors are often inconsistent with for profit or commercial advantage and that copies bear this notice and the full citation other, related instructions. on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to For those who need a formal semantics of x86-64, a com- republish, to post on servers, or to redistribute to lists, contact the Owner/Author. mon though necessarily inefficient approach is to generate Request permissions from [email protected] or Publications Dept., ACM, Inc., fax +1 (212) 869-0481. Copyright 2016 held by Owner/Author. Publication Rights formal specifications by hand on demand: whenever progress Licensed to ACM. requires the semantics of an instruction i, someone writes a PLDI ’16 June 13–17, 2016, Santa Barbara, CA, USA Copyright c 2016 ACM 978-1-4503-4261-2/16/06. $15.00 formula for i. Many software research groups have taken this DOI: http://dx.doi.org/10.1145/2908080.2908121 approach, and ours is no exception. However, our personal experience is that it is nearly impossible to write and maintain counterexamples discovered along the way). When we are correct specifications solely by hand—x86-64 is just too big done, we choose one p^ 2 P and return the formula for p^ as and complicated. As a result, we gradually built an elaborate the semantics of i. infrastructure to support developing a formal semantics, in- Even given that we search for multiple programs until no cluding templates to describe the semantics of families of further inconsistencies can be discovered, there is no guar- closely related instructions and testing tools to compare the antee that the program p^ correctly implements i. This uncer- formal descriptions with the behavior of the actual hardware. tainty is unavoidable: we do not start with a formal specifica- Wherever we added automation, we found additional bugs tion of i’s behavior, and so the best we can possibly do is to in the human written specifications. Eventually we came to produce a semantics that is consistent with whatever informa- ask whether we could eliminate the problematic human effort tion is available. However, we have carefully compared our entirely and generate a useful formal description of most of automatically generated semantics to previously developed x86-64 from a small “proto specification”. formulas for x86-64 and found a number of discrepancies. In The most successful previous attempt to automatically every case, the automatically generated semantics was correct generate a formal semantics for x86-64 is a template-based and the hand-written semantics was wrong. Furthermore, as method for explaining input-output examples that are derived a result of this effort we discovered a number of new bugs from hardware executions. This approach has been used to and inconsistencies in the Intel manual (see Section 5). generate formulas for 534 instruction variants [12]. These Because we want to automate the production of the formal variants cover the core of 32-bit x86, but do not include any semantics as much as possible, we must minimize the size of the more recent extensions of x86-64 (e.g., vector instruc- of the base set of instructions that is the input to the process. tions). The templates are written by hand and must satisfy However, many of the instructions that we consider can only certain structural restrictions. It seems unlikely that these be characterized by programs that are so long that no currently requirements are expressive enough to cover the remainder available program synthesis technique can produce them if of the instruction set. they are written using only instructions in the initial base set. In this paper we demonstrate a new technique that can To address this problem, we introduce the idea of stratified automatically synthesize a formal semantics for a large synthesis: whenever we learn a program p for an instruction fraction of the x86-64 ISA. Our approach uses program i, we add the formula for p to the base set as the semantics synthesis to learn bit-vector formulas that can be consumed of i. Thus, as we learn the semantics of simpler instructions, by SMT solvers such as Z3 [32] or CVC4 [6]. We begin our vocabulary for expressing the semantics of more complex by choosing a small set of x86-64 instructions that we call instructions expands. We have implemented the approach in the base set. Our approach expects a formal semantics for a tool called STRATA and we empirically observe that the every instruction in the base set as input and then generates use of stratified synthesis is both effective and necessary— formulas for the remaining instructions automatically. The there are many instructions that are learned only after other, effort required to produce the formulas for the base set is intermediate, instructions have been learned. small—they can either be written by hand or generated using This paper makes the following contributions: some other approach (including [12]). • We introduce a stratified program synthesis technique that At a high level, our approach works as follows. We execute enables us to learn complex programs in small steps and an instruction i for which the formal semantics is not known show how it can be used to synthesize a formal semantics yet on a set of test inputs T to obtain an initial description of for the x86-64 ISA. its behavior. We then search for a program p that matches the behavior of i on the tests T , where p only uses instructions • We contribute SMT formulas for a subset of the x86-64 drawn from the base set S. However, there is little reason to ISA that is significantly larger than previous automatically 1 have confidence that one program that happens to match an synthesized semantics . instruction’s behavior on a set of test cases actually captures • We evaluate these formulas for correctness and usability; the behavior of that instruction for all possible inputs, so we in doing so, we identify several important errors in pre- perform the search multiple times to find a set of programs P existing formalizations. that match the behavior of i on T and use only instructions from S. Given two programs p; p0 2 P , we test whether 2.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    14 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us