Recherche Images Maps Play YouTube Actualités Gmail Drive Plus »
Connexion
Les utilisateurs de lecteurs d'écran peuvent cliquer sur ce lien pour activer le mode d'accessibilité. Celui-ci propose les mêmes fonctionnalités principales, mais il est optimisé pour votre lecteur d'écran.

Brevets

  1. Recherche avancée dans les brevets
Numéro de publicationUS20090133005 A1
Type de publicationDemande
Numéro de demandeUS 12/206,578
Date de publication21 mai 2009
Date de dépôt8 sept. 2008
Date de priorité15 nov. 2007
Autre référence de publicationUS7430733
Numéro de publication12206578, 206578, US 2009/0133005 A1, US 2009/133005 A1, US 20090133005 A1, US 20090133005A1, US 2009133005 A1, US 2009133005A1, US-A1-20090133005, US-A1-2009133005, US2009/0133005A1, US2009/133005A1, US20090133005 A1, US20090133005A1, US2009133005 A1, US2009133005A1
InventeursYaakov Yaari
Cessionnaire d'origineInternational Business Machines Corporation
Exporter la citationBiBTeX, EndNote, RefMan
Liens externes: USPTO, Cession USPTO, Espacenet
Method for validation of binary code transformations
US 20090133005 A1
Résumé
A method of validating binary code transformation in one aspect includes analyzing original program and transform program. Control flow graphs are generated for both programs. The two graphs are traversed to create respective linear invariant representations. The linear representations are compared to identify incorrect transformations.
Images(3)
Previous page
Next page
Revendications(1)
1. A program storage device readable by a machine, tangibly embodying a program of instructions executable by the machine to perform a method for validating binary code transformations, comprising:
analyzing binary code of an executable program to produce a sequence of basic units comprising smallest elements of the executable program that stay intact under every reordering;
generating control flow graph associated with the sequence of basic units;
generating invariant linear fiction representation based on the control flow graph;
analyzing optimized transformation of the executable program to produce a second sequence of basic units;
generating second control flow graph associated with the second sequence of basic units;
generating second invariant linear function representation based on the second control flow graph;
comparing the invariant linear function representation and the second invariant linear function representation; and
identifying one or more incorrect transformations in the optimized transformation,
wherein the invariant linear function representation and the second invariant linear function representation are invariants under a set of predefined optimization transformation and include a sequence of strips comprising a path through a trace of non-branch instructions executing sequentially when the executable program runs.
Description
    CROSS-REFERENCE TO RELATED APPLICATIONS
  • [0001]
    This application is a continuation of U.S. patent application Ser. No. 11/940,750 filed on Nov. 15, 2007.
  • FIELD OF THE INVENTION
  • [0002]
    The present disclosure relates to optimizing computer executable codes, and particularly to a method for validating binary code transformation.
  • BACKGROUND OF THE INVENTION
  • [0003]
    Optimizing executable code is a known technique to improve the performance of code that has already been linked and is ready for execution. It is typically performed using a runtime profile of the code. Different optimization techniques are available such as inlining and code restructuring, which transform the code to functionally equivalent form. If the code optimization does not correctly transform the code to functionally equivalent form, unpredictable consequences may result, such as a program crash.
  • [0004]
    While there are existing technologies that perform validations on program source code, semantics of compiler's internal representation of a code, or even hardware level code, those technologies are incapable of handling the kind of transformations performed on the binary applications. Thus, what is desirable is a method that helps to validate the correctness of binary code transformations.
  • BRIEF SUMMARY OF THE INVENTION
  • [0005]
    A method for validating binary code transformations is provided In one aspect, the method may comprise analyzing binary code of an executable program to produce a sequence of basic units; generating control flow graph associated with the sequence of basic units; generating invariant linear function representation based on the control flow graph; analyzing optimized transformation of the executable program to produce a second sequence of basic units; generating second control flow graph associated with the second sequence of basic units; generating second invariant linear function representation based on the second control flow graph; comparing the invariant linear function representation and the second invariant linear function representation; and identifying one or more incorrect transformations in the optimized transformation.
  • [0006]
    A program storage device readable by a machine, tangibly embodying a program of instructions executable by the machine to perform the above method may also be provided.
  • [0007]
    Further features as well as the structure and operation of various embodiments are described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers indicate identical or functionally similar elements.
  • BRIEF DESCRIPTION OF THE DRAWINGS
  • [0008]
    FIG. 1 is a flow diagram illustrating a method for validating binary code transformation in one embodiment of the present disclosure.
  • [0009]
    FIG. 2 shows an example sequence of three basic blocks.
  • [0010]
    FIG. 3 shows the FCG for the basic blocks in FIG. 2.
  • DETAILED DESCRIPTION
  • [0011]
    The binary code of the original program and the transformed program are analyzed, using various available techniques such as static techniques using relocation information and/or dynamic techniques by intercepting execution and recognizing the accessed basic units, and a control flow graph for both programs is generated. For each validated function, the two graphs are both traversed in consistent fashion, creating their linear invariant textual representations. These linear representations can be compared as simple text strings in order to identify incorrect transformation.
  • [0012]
    FIG. 1 is a flow diagram illustrating a method for validating binary code transformation in one embodiment of the present disclosure. Steps 102, 104 and 106 are performed for both the original and the transformed codes. At 102, program analysis begins. The executable program is analyzed using the FDPR (Feedback Directed Program Restructuring) technology. Briefly, FDPR optimizes the executable image of a program by collecting information on the behavior of the program while the program is used for some typical workload, and then creating a new version of the program that is optimized for that workload. The principal output of this analysis is a sequence of basic units. Basic units are the smallest elements of the program that stay intact under every reordering. In this embodiment of the disclosure, the basic units include two types, basic blocks and data objects. The basic blocks type includes instructions. The data objects type includes data, for example, read-only and writable. Data objects correspond to the high-level data objects defined in the source program, for examples arrays, structures, or scalars. A basic block is a sequence of instructions that can be entered only at its beginning and exited only at its end. FIG. 2 shows an example sequence of three basic blocks 202, 204, 206, of which two 202, 204 are adjacent.
  • [0013]
    Referring back to FIG. 1, at 104, building a program control flow graph (CFG) begins. In one embodiment, building the CFG is done by connecting, with a directed edge, the exit point of each basic block A to the entry points of the basic blocks according to the way A terminates. For instance, if A terminates by a simple branch, connect to the target of the branch. If A terminates by a conditional branch, connect to both the target of the branch, as well as the following basic block (called the fall-through basic block). If A terminates by an indirect branch keep A unconnected at the moment, as the target is not known at this moment. FIG. 3 shows the CFG for the basic blocks in FIG. 2.
  • [0014]
    An edge in the CFG carries an execution count, that is, the number of times control passed along that edge when the program was executed. This information can be collected by various means, for example, the “pixie” tool, or the basic block profiling provided by standard compilers like GCC. An edge that carries relatively high execution count is termed hot edge. A basic block that executes many times relative to the average count is termed hot basic block.
  • [0015]
    Referring back to FIG. 1, at 106, invariant linear function representation is created by consistently traversing the CFC. This step forms an invariant linear representation for a given function. Invariant representation refers to one or more invariants under a set of predefined optimization transformations of the function. An optimization transformation is a transformation of the code that preserves the semantics of the function while providing some potential improvement, typically in execution time.
  • [0016]
    The basic set of transformations includes at least code restructuring, function inlining, and hot-cold code motion. Code restructuring is an optimization, which places basic blocks close to each other if they are connected by relatively hot edges. For example, basic block A (shown in FIG. 2 and FIG. 3) ends with a BNE branch (branch of not equal), following basic block B, for the EQ condition. Under code restructuring, if the edge A-C is much hotter then A-B, the condition that ends A might be changed to EQ (that is, BEQ) so that basic block C will be the fall-through basic block A. Similarly, basic blocks that connect by edges with cold branches may be placed far from each other, sometimes requiring an additional intermediate branch in between if the distance is too great for the original branch to be performed in one hop.
  • [0017]
    Function inlining replaces the call instruction by a copy of the fiction in places where the call instruction is very hot. Hot-cold code motion optimization moves instructions from hot basic block to a colder one, making sure these instructions are properly replicated to preserve the semantics.
  • [0018]
    The following algorithm is used to create an invariant linear representation of a function in one embodiment. The representation is in a form of a sequence of strips. A strip is a possible path through the program CFG, that is, a trace of non-branch instructions that may execute sequentially when the program runs.
  • [0000]
    Function CreateInvariantRepresentation (ControlFlowGraph cfg
    Function f)
      // Control Flow Graph cfgis the CFG of the program
      // Node f is the entry point of the give
      Stack returnStack= <empty> // a stack of nodes in cfg
      Stack entryPointStack = <empty> // a stack of nodes in cfg
      List stripList = <empty> // the output list of strips.
      Node epf = EntryPoint(f)
    Push(epf, entryPointStack)
      While entryPointStackis not empty do
        ep = Pop(entryPointStack)
        If ep has not been traversed then
          strip = Traverse(ep, returnStack, entryPointStack)
          Add( strip, stripList)
        End if
      End while
      Return stripList
    End function
    Function Traverse (Node entry, InputOutput Stack returnStack,
    InputOutput Stack entryPointStack )
      List Strip = <empty> // output strip (list of instructions)
      Node bb = entry, firstBB, secondBB
      While bb is not <empty> do
        // add basic block to strip
        Foreach Instruction instr in BasicBlock(bb) do
          Add(instr, Strip)
        End foreach
        Mark bb as traversed
        // sechedule BBs at edges of bb
        Bool firstIsCall = (Edge(bb, First) is a call)
        firstBB = RetrieveNode(Edge(bb, First), returnStack)
        If firstBB is not <empty> then
          secondBB = RerieveNode(Edge(bb, Second), returnStack)
        Else
          firstBB = RetrieveNode(Edge(bb, Second), returnStack)
          secondBB = <empty>
        End if
        If firstBB is not <empty> then
          if secondBB is not <empty> then
            // schedule second node. If this is a call edge, push
          called function's entry point node on return stack
            // else push node on entry point stack
            Stack stack = firstIsCall? returnStack: entryPointStack;
            Push(secondBB, stack)
          End if
        End if
        bb = firstBB
      End while
      // reached a traversed node or end of function
      Return strips
    End function
    Function RetrieveNode(Edge edge, InputOutput Stack returnStack)
      Node retrievedBB = <empty>
      If edge exists and is direct then
        // continue traversing this function
        retrievedBB = Node(edge)
      Else if edge is a return instruction (e.g. ‘blr’ in POWER arch.) then
        // traverse back to caller
        retrievedBB = Pop(returnStack)
      End if
      // do not proceed in this direction if node has been traversed already
      If retievedBB is not <empty> and retriebedBB is not traversed then
        Return retrievedBB
      Else
        Return <empty>
      End if
    End function
  • [0019]
    An example strip follows. In the example, the branch instructions, which are not part of the strips, are commented out.
  • [0000]
    Strip 6:
    #13b2b29c ...
    # 41 86 00 48 beq- cr1,13b2b2e4 <.pevm_EXECC+0x504>
    #13b2b2e4 ...
    e8 7d 00 08 ld r3,8(r29)
    28 9b 05 7b cmplwi cr1,r27,1403
    e8 63 00 c8 ld r3,200(r3)
    80 03 00 9c lwz r0,156(r3)
    70 00 00 40 andi. r0,r0,64
    # 41 82 00 14 beq- 13b2b30c <.pevm_EXECC+0x52c>
    #13b2b30c ...
    a0 1c 00 34 lhz r0,52(r28)
    70 03 00 40 andi. r3,r0,64
    # 40 82 00 34 bne- 13b2b348 <.pevm_EXECC+0x568>
    80 bc 00 50 lwz r5,80(r28)
    e8 dc 00 56 lwa r6,84(r28)
    e8 7d 00 08 ld r3,8(r29)
    e8 9d 00 88 ld r4,136(r29)
    39 20 00 00 li r9,0
    e8 63 00 00 ld r3,0(r3)
    38 e0 00 00 li r7,0
    39 00 00 00 li r8,0
    e8 84 00 00 ld r4,0(r4)
    # 4b 9f ed 45 bl 1352a080 <.kgicls>
    60 00 00 00 nop
    a0 1c 00 34 lhz r0,52(r28)
    54 00 04 3c rlwinm r0,r0,0,16,30
    80 7c 00 58 lwz r3,88(r28)
    2c 23 00 00 cmpdi r3,0
    b0 1c 00 34 sth r0,52(r28)
    # 41 82 00 0c beq- 13b2b364 <.pevm_EXECC+0x584>
    #13b2b364 ...
    7f a3 eb 78 mr r3,r29
    7f 64 db 78 mr r4,r27
    # 4b fe 8b b5 bl 13b13f20 <.pevm_handle_external_error>
    60 00 00 00 nop
    # 48 00 01 34 b 13b2b4a8 <.pevm_EXECC+0x6c8>
    Strip 7:
    #13b2b35c ...
    e8 7d 00 b0 ld r3,176(r29)
    93 c3 00 98 stw r30,152(r3)
    Strip 8:
    #13b2b2fc ...
    # 40 86 00 10 bne- cr1,13b2b30c <.pevm_EXECC+0x52c>
    7f a3 eb 78 mr r3,r29
    # 4b fe 9e 9d bl 13b151a0 <.pfrfoe_flush_oci_error>
    60 00 00 00 nop
  • [0020]
    At 108, the generated strips of two implementations of a function are compared. The comparison can be a textual or character-by-character comparison. Incorrect transformations are identified from the comparison. For example, the strip or strips corresponding to the transformed or optimized code that do not match the strip or strips of the original code are identified as being incorrect.
  • [0021]
    The system and method of the present disclosure may be implemented and run on a general-purpose computer or computer system. The computer system may be any type of known or will be known systems and may typically include a processor, memory device, a storage device, input/output devices, internal buses, and/or a communications interface for communicating with other computer systems in conjunction with communication hardware and software, etc.
  • [0022]
    The terms “computer system” and “computer network” as may be used in the present application may include a variety of combinations of fixed and/or portable computer hardware, software, peripherals, and storage devices. The computer system may include a plurality of individual components that are networked or otherwise linked to perform collaboratively, or may include one or more stand-alone components. The hardware and software components of the computer system of the present application may include and may be included within fixed and portable devices such as desktop, laptop, and server. A module may be a component of a device, software, program, or system that implements some “functionality”, which can be embodied as software, hardware, firmware, electronic circuitry, or etc.
  • [0023]
    The embodiments described above are illustrative examples and it should not be construed that the present invention is limited to these particular embodiments. Thus, various changes and modifications may be effected by one skilled in the art without departing from the spirit or scope of the invention as defined in the appended claims.
Citations de brevets
Brevet cité Date de dépôt Date de publication Déposant Titre
US5371747 *5 juin 19926 déc. 1994Convex Computer CorporationDebugger program which includes correlation of computer program source code with optimized object code
US5450575 *7 mars 199112 sept. 1995Digital Equipment CorporationUse of stack depth to identify machine code mistakes
US5758051 *5 nov. 199626 mai 1998International Business Machines CorporationMethod and apparatus for reordering memory operations in a processor
US5790867 *2 janv. 19964 août 1998International Business Machines CorporationCompiler with extended redundant copy elimination
US5802373 *29 janv. 19961 sept. 1998Digital Equipment CorporationMethod for providing a pipeline interpreter for a variable length instruction set
US5889999 *15 mai 199630 mars 1999Motorola, Inc.Method and apparatus for sequencing computer instruction execution in a data processing system
US5966539 *3 nov. 199712 oct. 1999Digital Equipment CorporationLink time optimization with translation to intermediate program and following optimization techniques including program analysis code motion live variable set generation order analysis, dead code elimination and load invariant analysis
US5966541 *4 déc. 199712 oct. 1999Incert Software CorporationTest protection, and repair through binary-code augmentation
US6035123 *8 nov. 19957 mars 2000Digital Equipment CorporationDetermining hardware complexity of software operations
US6075942 *4 mai 199813 juin 2000Sun Microsystems, Inc.Encoding machine-specific optimization in generic byte code by using local variables as pseudo-registers
US6226789 *29 janv. 19961 mai 2001Compaq Computer CorporationMethod and apparatus for data flow analysis
US6275981 *12 nov. 199814 août 2001Hewlett-Packard CompanyMethod and system for correlating profile data dynamically generated from an optimized executable program with source code statements
US6289505 *18 nov. 199711 sept. 2001Sun Microsystems, Inc.Method, apparatus and computer programmed product for binary re-optimization using a high level language compiler
US6292938 *2 déc. 199818 sept. 2001International Business Machines CorporationRetargeting optimized code by matching tree patterns in directed acyclic graphs
US6530079 *2 juin 19994 mars 2003International Business Machines CorporationMethod for optimizing locks in computer programs
US6598221 *13 avr. 200022 juil. 2003Koninklijke Philips Electronics N.V.Assembly code performance evaluation apparatus and method
US6748584 *29 déc. 19998 juin 2004Veritas Operating CorporationMethod for determining the degree to which changed code has been exercised
US6829733 *7 mai 20017 déc. 2004National Instruments CorporationSystem and method for graphically detecting differences between test executive sequence files
US7185328 *30 mai 200227 févr. 2007Microsoft CorporationSystem and method for improving a working set
US7207038 *29 août 200317 avr. 2007Nokia CorporationConstructing control flows graphs of binary executable programs at post-link time
US20040098710 *14 nov. 200220 mai 2004Jim RadiganSystems and methods to read, optimize, and verify byte codes for a multiplatform jit
US20040128659 *31 déc. 20021 juil. 2004Intel CorporationRun-time behavior preserving partial redundancy elimination
US20050257202 *14 mai 200417 nov. 2005Daniel KaestnerData-flow based post pass optimization in dynamic compilers
US20050268293 *20 mai 20051 déc. 2005International Business Machines CorporationCompiler optimization
US20060080645 *21 nov. 200513 avr. 2006Miguel MirandaSystem and method for optimizing source code
US20060130016 *23 nov. 200515 juin 2006Wagner John RMethod of kernal-mode instruction interception and apparatus therefor
US20060282807 *3 juin 200614 déc. 2006Nec Laboratories America, Inc.Software verification
Référencé par
Brevet citant Date de dépôt Date de publication Déposant Titre
US20150143342 *15 nov. 201321 mai 2015Microsoft CorporationFunctional validation of software
Classifications
Classification aux États-Unis717/143
Classification internationaleG06F9/45
Classification coopérativeG06F8/443, G06F8/75