Static binary rewriting and dynamic binary rewriting hybrid method, system and application

By combining static and dynamic binary rewriting, the range of incompatible instructions is optimized, solving the compatibility problem between different generations of the same instruction set architecture, and realizing efficient execution and compatibility of binary programs on hardware.

CN121658014APending Publication Date: 2026-03-13EAST CHINA NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Compatibility issues between different generations of the same instruction set architecture prevent binary programs from executing on hardware. Existing static binary rewriting techniques cannot capture dynamic behavior, while dynamic binary rewriting techniques incur excessive overhead when a small percentage of hardware does not support the instructions.

Method used

By combining static binary rewriting and dynamic binary rewriting, incompatible instructions are statically and dynamically rewritten. The overhead model is used to optimize the range, reduce runtime overhead, and achieve 100% instruction compatibility.

Benefits of technology

It enables efficient and seamless execution of binary programs across different generations of instruction set architectures, reducing runtime overhead and improving compatibility and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure HDA0005042688270000011
    Figure HDA0005042688270000011
  • Figure HDA0005042688270000012
    Figure HDA0005042688270000012
  • Figure HDA0005042688270000013
    Figure HDA0005042688270000013
Patent Text Reader

Abstract

The invention discloses a static binary rewriting and dynamic binary rewriting hybrid method, which comprises the following steps of: analyzing a source binary executable file to obtain a file structure and instruction information, and analyzing and determining an incompatible instruction on a target platform; planning an optimal range interval for a part which does not support static rewriting in the incompatible instruction, and performing static rewriting on a part which supports static rewriting to generate a new binary executable file; executing the generated binary executable file, calling a dynamic binary rewriter to take over the control execution flow of the program and dynamically rewrite and execute the incompatible instructions in the marked range when the execution is within the incompatible instruction range, and after the marked range is ended, returning the control right to the original program to continue execution; and repeating the previous step according to the number of the marking instruction ranges in the binary executable file until the complete program is executed. The invention further discloses a system and application for implementing the method, and the system and the application have wide application value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of compiler optimization technology, and relates to a method, system and application for seamless and flexible execution of hardware-unsupported instructions by combining static rewriting and dynamic rewriting. Background Technology

[0002] Instruction set architecture (IRA) is the binary encoding method used by a processor to execute instructions, and it also serves as the interface specification between software and hardware. Currently, mainstream IRAs include x86, ARM, RISC-V, MIPS, POWER, and LONGARCH. To adapt to changing application workloads and enhance product competitiveness, major chip manufacturers expand, remove, and iterate on IRAs, leading to differences between different generations of the same IRA. These differences can cause compatibility issues, such as a binary source executable program from one generation of the same IRA failing to execute on hardware supporting another generation due to the lack of hardware support for certain instructions. For example, the Vectorized Instruction Set Extension (RVV) of the RISC-V instruction set is primarily used in versions RVV1.0 and RVV0.7.1. RVV1.0 redesigned many existing instructions from RVV0.7.1 and added a series of new instructions to support more complex vectorized operations. However, most chips available on the open market only support RVV0.7.1, while some applications and system software are built on RVV1.0. This results in many newer applications that include the vectorized extended instruction version RVV1.0 being unable to run on the vast majority of currently available chips.

[0003] Binary rewriting and binary translation technologies can translate programs from one instruction set architecture to another for execution without source code. This technology is a crucial means of resolving software compatibility issues after generational changes within the same instruction set architecture and migrating programs between different instruction set architectures. Binary rewriting analyzes and rewrites binary executable files, and can be categorized into two forms: static binary rewriting (SBR) and dynamic binary rewriting (DBR). Static binary rewriting is an offline compilation technique that completes all instruction rewriting before program execution, thus eliminating runtime overhead. Static binary rewriting has many important applications in software security and systems, such as program hardening, automatic repair, instrumentation, and debugging, providing strong support for software security, performance optimization, and reverse engineering. However, the drawback of static binary rewriting is that it relies solely on static analysis, specifically analyzing the static characteristics and code structure of the binary file. This analysis method cannot capture the dynamic behavior and contextual information of a program during its execution, which may result in a lack of complete understanding of the overall behavior of the program.

[0004] Dynamic binary rewriting is a dynamic compilation technique that overcomes the limitations of static compilation and analysis techniques in modern software by postponing code generation and optimization to the program loading or running stage. Dynamic binary rewriting can also achieve effective feedback-guided optimization, architecture-specific code transformation, program introspection, and other functions. The dynamic rewriting system rewrites the binary code of the program into code executable by the target platform during program execution, thereby enabling cross-platform execution of the program. Dynamic rewriters also have the following disadvantages: (1) When the program is first executed, the DBR (Dynamic Binary Rewriter) system needs to start up and prepare the DBR system and execution environment before rewriting the binary code and executing the rewritten code, which will bring a certain program startup delay; (2) The DBR system can improve program performance through optimization, but the real-time translation and optimization process itself will bring additional overhead; (3) The DBR system needs to maintain the rewritten code cache during runtime, which will increase memory usage. Especially when dealing with large applications, the code cache may occupy a lot of memory resources, resulting in high memory usage and affecting the overall performance of the system.

[0005] When a dynamic rewriter on a target platform runs a source binary program of a different generation with the same instruction set architecture, the proportion of instructions that are not supported by the hardware due to generational changes is relatively small. In this case, the strategy of dynamically rewriting the entire source binary program adopted by the current mainstream dynamic binary rewriters is too costly.

[0006] Currently, the use of static binary rewriting technology in the field of binary translation mainly focuses on improving the performance of executables within the same instruction set architecture, while the use of dynamic binary rewriting technology is primarily concentrated on solving cross-instruction set compatibility issues. The combined use of static and dynamic binary rewriting has only been explored in cross-instruction set architecture applications. However, a satisfactory solution remains elusive for the emerging problem of instruction compatibility between different generations of instruction sets within the same instruction set architecture. Summary of the Invention

[0007] To address the shortcomings of existing technologies, the present invention aims to provide a hybrid method and system for static binary rewriting and dynamic binary rewriting, so as to efficiently solve the compatibility problem between different generations of instruction sets with the same instruction set architecture.

[0008] This invention provides a hybrid method of static binary rewriting and dynamic binary rewriting, the method comprising the following steps:

[0009] Step 1: Parse the source binary executable file to obtain the file structure and instruction information, and analyze and determine the instructions that are incompatible with the target platform;

[0010] Step 2: For all target platform incompatible instructions obtained after Step 1, plan one or more optimal range intervals containing instructions that cannot be statically rewritten from the incompatible instructions, and mark the start and end positions of the intervals. Then, statically rewrite the instructions that can be statically rewritten from the incompatible instructions to generate a binary executable file that has been statically rewritten and marked with the instruction range that does not support static rewriting.

[0011] Step 3: Execute the binary executable file generated in Step 2. When the execution reaches the beginning of the instruction range that does not support static rewriting, call the dynamic binary rewriter to take over the control execution flow of the program, dynamically rewrite and execute the incompatible instructions in the marked range, and hand over control to the generated program to continue execution after the marked range ends.

[0012] Step 4: Repeat the dynamic binary rewriter rewriting and execution steps in Step 3 according to the number of marked instructions in the binary executable file until the complete program is executed.

[0013] In step one, the set of instructions that the current hardware platform cannot natively execute is obtained by decoding the instructions in the .text segment of the source binary executable file. These are incompatible instructions on the target platform, including instructions that support static rewriting and instructions that do not support static rewriting.

[0014] In step two, the optimal range interval containing one or more instructions that do not support static rewrite is planned using the overhead model to minimize the overhead after planning, and the start and end positions of the optimal range interval are obtained.

[0015] The overhead model is established by combining function boundary information, the distribution characteristics of instructions that cannot be statically rewritten in functions, and program control execution flow analysis.

[0016] Based on sampling statistics of real application loads, this invention shows that incompatible instructions between different generations of instruction sets with the same instruction set architecture account for a very small percentage of the total instructions in the binary source program of the application load. The scheme of using static rewriting combined with dynamic translation can minimize the runtime overhead of static binary translation, and can also use dynamic translation to perform semantically equivalent rewriting of instructions that cannot be rewritten by static rewriter at runtime to achieve 100% instruction compatibility. Furthermore, runtime information can be used to optimize the program.

[0017] The core of the system in this invention consists of the following two parts:

[0018] (1) A fully functional static binary rewriter that supports marking incompatible instruction ranges. This static binary rewriter includes an instruction rewriting module and a range marking module, which can rewrite incompatible instructions into semantically equivalent instruction sequences supported by the current platform, and mark the ranges of instructions that cannot be statically rewritten;

[0019] (2) A fully functional dynamic binary rewriter module that supports execution within a marked range. This dynamic binary rewriter includes a module that supports execution within a marked range and improves the instruction rewriting engine. The improved instruction rewriting engine has a range awareness function and only performs rewriting on the range marked range. According to the region marked by the static binary rewriter designed in (1), when the binary source program natively executes to the region, it can take over the program control execution flow, dynamically rewrite and execute the instructions within the range of this region, and return the program control execution flow to the source program for native execution after the region is executed, so as to minimize the overhead of dynamic translation.

[0020] In addition to the core modules and methods described above, this invention also includes a default deployment and usage scheme, such as... Figure 2As shown, the static binary rewriter that supports marking incompatible instruction ranges and the dynamic binary rewriter that supports execution within the marked range, designed by this invention, are used as default services of the operating system. They are automatically started when the operating system starts and continuously monitor the file system, so that any executable program containing target platform incompatible instructions in the file system of the operating system can be automatically rewritten without the user's notice and can be executed seamlessly on incompatible hardware.

[0021] This invention proposes a method and system that combines static and dynamic binary rewriting. When the target platform and the binary source program are on different generations of the same instruction set architecture, the system automatically performs static rewriting and marks the range of incompatible instructions in the binary source program. During runtime, it switches to a dynamic binary rewriter for execution as needed. This invention supports multiple instruction set architectures and target platforms. The invention consists of two modules: a static binary rewriter module that supports marking the range of incompatible instructions, and a dynamic binary rewriter module that supports execution within the marked region. The specific principles and workflows of each module are described below.

[0022] 5.1 Supports static binary rewriter modules that mark incompatible instruction ranges.

[0023] This invention designs a static binary rewriter that supports multi-platform and multi-instruction set architectures. The main functions of this static binary rewriter are: 1. To support the static rewriting of target platform-incompatible instructions that can be statically rewritten into semantically equivalent, efficient, and target platform-supported instruction sequences; 2. To support marking the range of target platform-incompatible instructions that cannot be statically rewritten. The static binary rewriter combines function boundary information, the distribution characteristics of instructions that cannot be statically rewritten within functions, and control flow analysis to establish a cost model to guide the division of optimal intervals and the start and end positions of the range markings. This ensures that each determined range interval is an optimal range interval (the range interval that minimizes the overhead of context switching), and inserts function call instructions that invoke the dynamic binary rewriter at the determined start and end positions.

[0024] In this invention, the overhead of a single instruction is defined as the overhead of rewriting a hardware-unsupported instruction into a semantically equivalent instruction sequence using a dynamic binary rewriter and then executing it natively.

[0025] The overhead model defines a state space by selecting static or dynamic rewrite for each incompatible instruction within a given instruction range. Within this space, methods including but not limited to hardware measurement estimation, dynamic programming selection, and machine learning-based estimation selection are used to select the option that minimizes the total runtime overhead for either static or dynamic rewrite of the incompatible instructions within that range.

[0026] The static binary rewriter workflow is as follows: Figure 3 As shown. A static binary rewriter that supports marking incompatible instruction ranges adds a separate range marking analysis module, and during the static binary rewriter's execution, it adds a Pass (a process used to transform, optimize, and analyze intermediate representations) to analyze where to add the start and end points of range markings. After startup, the binary executable file is parsed, and debugging information is read for function discovery. Next, the static binary rewriter uses a disassembler and a Control Flow Graph (CFG) building tool to disassemble the input executable file and construct a CFG representation, allowing the static binary rewriter to better understand the code structure and control flow. Based on this, the static binary rewriter runs a series of optimizations, including platform-dependent and / or platform-independent optimizations. Based on the optimized results, it marks the positions in the executable file containing basic blocks of non-statically rewriteable instructions according to the method described in Main Function 2 above. After marking the ranges, the statically rewriteable instructions are rewritten one by one into efficient, semantically equivalent instruction sequences supported by the current target platform. After rewriting incompatible instructions, the static binary rewriter uses the dynamic linker to re-output the optimized rewritten function and replaces the original input executable file with the newly generated executable file.

[0027] The platform-related optimizations include, but are not limited to: selection of the best semantically equivalent instruction after instruction rewriting, register allocation optimization, etc.; the platform-independent optimizations include, but are not limited to: code layout optimization, function rearrangement optimization, performance sampling information-guided optimization, post-linking optimization, etc.

[0028] 5.2 Supports dynamic binary rewriter modules that execute within a marked range

[0029] This invention designs a dynamic binary rewriter module that supports execution within a marked range, supporting multi-platform and multi-instruction set architectures. The main functions of this dynamic binary rewriter module are: 1. To support the runtime rewriting of incompatible instructions that cannot be statically rewritten into semantically equivalent, efficient instruction sequences supported by the target platform, and then execute them; 2. To support the takeover of the source program's execution flow when the executable program, after static rewriting, reaches the dynamic binary rewriter call instruction at the beginning of the marked range, and to dynamically rewrite and execute within the marked range until the end of the marked range. Upon reaching the end of the marked range, the execution flow is returned to the original execution.

[0030] The workflow of a dynamic binary rewriter is as follows: Figure 4 As shown, the source binary program rewritten by the static binary rewriter first runs in native execution mode until it reaches the dynamic rewriter call instruction at the start mark of the range generated by the static binary rewriter. This instruction executes a function that performs context switching and passes process information to the process where the dynamic binary rewriter resides, allowing the dynamic binary rewriter to obtain the state machine of the current execution state of the native program and take over program control from this state. After taking over program control, the dynamic binary rewriter dynamically rewrites and executes the instructions within the marked range, decoding them in units of basic blocks, converting the instruction sequence into an intermediate representation, and rewriting incompatible instructions that cannot be statically rewritten into efficient, semantically equivalent instruction sequences supported by the target platform. The dynamic binary rewriter performs code generation, code cache management, and native execution of code cache blocks in units of basic blocks. During execution, the dynamic binary rewriter optimizes the code cache blocks in the code cache, including but not limited to linking code cache blocks into execution paths (traces) that do not contain jump instructions to further reduce runtime overhead. When the dynamic rewriter reaches the function call instruction that exits the dynamic rewriter at the stop of the range marker, it uses this instruction to perform another context switch, passing the current execution state information back to the native execution process and returning program control to the original execution process. After this, the source binary program continues its native execution. When the source binary program reaches the start of the range marker instruction again, the above process is repeated until the source binary program has finished executing.

[0031] In addition to the above-mentioned function call methods, the takeover and exchange of programs in the control flow can also be achieved through methods including but not limited to the following: 1) Register a semaphore and trigger the semaphore when the source program executes an incompatible instruction. The dynamic binary rewriter captures the semaphore and obtains the state machine of the current execution state of the source binary program. It then takes over the program control execution flow from this state and returns the control execution flow to the source program after executing the instructions within the local marked range; 2) Inter-process communication method: The static rewrite adds instruction sequences with inter-process communication functions at the beginning and end of the marked range. When the program executes to the beginning of the incompatible instruction marked range, it notifies the dynamic binary rewriter process. After receiving the notification, the dynamic binary rewriter process obtains the state machine of the current execution state of the source binary program and takes over the program control execution flow from this state. After executing the instructions within the local marked range, it returns the control execution flow to the source program, etc.

[0032] However, the other methods mentioned above are relatively less effective compared to function calls.

[0033] This invention also provides the above-mentioned hybrid method of static binary rewriting and dynamic binary rewriting, or the above-mentioned hybrid system, for application in chip design optimization, cloud computing platform compatibility support, operating system upgrade and compatibility maintenance, embedded system hardware upgrade, cross-platform game development, etc.

[0034] The beneficial effects of this invention include: This invention proposes a method and system that combines static and dynamic binary rewriting. This invention includes a static binary rewriter module that supports marking incompatible instruction ranges and a dynamic binary rewriter module that supports execution within marked regions. The static binary rewriter module that supports marking incompatible instruction ranges leverages the advantage of static compilation not occupying runtime, completing the static binary rewriting of incompatible instructions and generating a rewritten binary file. Simultaneously, it specially marks instruction ranges that the static binary rewriter cannot rewrite, providing them for use by the dynamic binary rewriter module that supports execution within marked regions. The dynamic binary rewriter module that supports execution within marked regions, based on the special markings of instruction ranges generated by the static binary rewriter module, responds when the corresponding binary source program reaches a special mark and takes over program control execution flow, rewriting and executing this special range. After rewriting this range, it returns program control execution flow to the source binary program to continue native execution, repeating this process until the source binary program finishes execution.

[0035] This invention addresses the compatibility issues of binary programs with incompatible instructions across different generations within the same instruction set architecture by employing binary rewriting and compilation optimization techniques, while also reducing runtime overhead. This invention offers flexible usage options. For source binary programs where all instructions can be statically rewritten, the rewritten binary program, after being processed by a static binary rewriter module that supports marking incompatible instruction ranges, can be executed natively without incurring the runtime overhead of dynamic translation. Furthermore, the statically rewritten and compiled optimized binary program may even achieve some performance improvements. For source binary programs where some instructions cannot be statically rewritten, the static binary rewriter module, after analysis, generates special markers for the incompatible instruction ranges. When the rewritten binary program is executed natively, a dynamic binary rewriter module that supports execution within the marked region is automatically activated upon reaching the special marker. This invention combines the advantages of both static and dynamic binary rewriting. Compared to the limitations of traditional static binary rewriting and the excessive runtime overhead of dynamic binary rewriting, this invention's flexible execution methods and multiple deployment options enable efficient and seamless execution of source binary executable programs containing hardware-incompatible instructions on the target platform. Attached Figure Description

[0036] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0037] Figure 1 This is a schematic diagram of the workflow of a method and system that combines static rewriting and dynamic rewriting according to the present invention.

[0038] Figure 2 This is a schematic diagram illustrating the operation of a method and system combining static and dynamic rewriting according to the present invention, deployed in an operating system.

[0039] Figure 3 This is a flowchart of the static binary rewriter of the present invention.

[0040] Figure 4 This is a flowchart of the dynamic binary rewriter of the present invention.

[0041] Figure 5 This is a schematic diagram illustrating the workflow of the static binary rewriter that supports marking incompatible instruction ranges as a tool for independent deployment and use, as described in this invention.

[0042] Figure 6This is a schematic diagram illustrating the workflow of dynamically rewriting and executing a binary source program within a marked range on a single computing platform according to the present invention.

[0043] Figure 7 This is a flowchart illustrating the workflow of the present invention, which supports the joint deployment of a static binary rewriter that marks incompatible instruction ranges and a dynamic binary rewriter that supports execution within the marked range, in the form of a tool.

[0044] Figure 8 This is a schematic diagram illustrating the workflow of the present invention, which supports the deployment of static binary rewriters that mark incompatible instruction ranges and dynamic binary rewriters that support execution within marked ranges as services on a cloud server. Detailed Implementation

[0045] The present invention will be further described in detail below with reference to the specific embodiments and accompanying drawings. Except for the contents specifically mentioned below, the processes, conditions, and experimental methods for implementing the present invention are all common knowledge and general knowledge in the art, and the present invention does not have any particular limitations.

[0046] This invention provides a hybrid method of static binary rewriting and dynamic binary rewriting to minimize runtime overhead related to compatibility issues between different generations of instruction sets within the same instruction set architecture. First, the range of instructions in the binary source program that cannot be statically rewritten is specially marked. Instructions that can be statically analyzed and rewritten but are not supported by the source binary program due to generational changes in instruction set architecture are semantically rewritten to minimize runtime overhead associated with dynamic binary rewriting. Execution of instructions within the specially marked range requires the assistance of a dynamic binary rewriter, while execution of other instructions can be performed natively. Figure 1 As shown in the workflow diagram, specifically, when the native execution of the binary source program reaches the incompatible instruction marker position that the static rewriter cannot rewrite, the dynamic binary rewriter automatically takes over the control execution flow of the program and starts dynamic rewriting and execution from this instruction. When it reaches the point marked by the static rewriter where dynamic binary rewriting can stop, the control execution flow of the program is transferred back to the native execution of the source program.

[0047] Compared to cross-instruction set architecture binary rewriting, which requires rewriting every instruction in an executable file, intra-instruction set architecture rewriting only requires rewriting a portion of it. Since the number of instructions requiring rewriting is significantly reduced compared to cross-instruction set architecture binary rewriting, more instructions can be executed natively without rewriting. In this case, when to use static rewriting and when to use dynamic rewriting for different application workloads containing hardware-incompatible instructions, and what the "ratio" of static and dynamic rewriting should be, are questions that need special consideration for intra-instruction set architecture binary rewriting with a mix of static and dynamic methods. Static rewriting is not used for cross-instruction set architecture binary rewriting because static binary rewriting can only perform static analysis of the executable file and cannot capture the program's dynamic runtime information. The shortcomings of static binary rewriting across instruction set architectures include: 1) Mixed data and code: Static analysis cannot accurately determine which bytes are instructions and which are data, making it difficult to distinguish between data and code segments; 2) Indirect jumps and pointers: Pointer operations and indirect jumps used in the program complicate the determination of the program's control and data flow; 3) Dynamic link libraries and loading: Dynamic link libraries loaded at runtime and dependent external symbols are completely uncaptured during static analysis; 4) Self-modifying code: Self-modifying code is almost impossible to implement in static rewriting because the code differs between execution and analysis; 5) Rewriting efficiency issues: Static binary rewriting across instruction set architectures requires inserting a large amount of checking and patching code to cope with uncertainties, leading to code bloat. Due to these problems with static binary rewriters, dynamic binary rewriting is preferred for cross-instruction set architectures, as static binary rewriting is unacceptable in terms of performance and accuracy.

[0048] Figure 1 middle:

[0049] 1. Source binary executable file parsing and static rewriting

[0050] Source binary executable file: First, the source binary executable file will be parsed and analyzed.

[0051] Supports static binary rewriters that mark incompatible instruction ranges: The static binary rewriter marks incompatible instruction ranges in the source binary file that cannot be statically rewritten, and performs static rewriting on the parts that can be statically rewritten.

[0052] Static rewriting: Rewrites incompatible instructions that can be statically rewritten into instructions supported by the target platform, and generates a statically rewritten binary executable file.

[0053] 2. Execution process on the target hardware platform

[0054] Executing the statically rewritten code: On the target hardware platform, the statically rewritten binary executable is executed in a native manner.

[0055] Encountering the start of a marked range: When the program executes to the start of an incompatible instruction range marked by the static binary rewriter, the dynamic binary rewriter is invoked.

[0056] Invoking the dynamic binary rewriter: The dynamic binary rewriter takes over the program's control execution flow and begins to dynamically rewrite and execute incompatible instructions within the marked range.

[0057] Returning control to the program: When the dynamic binary rewriter reaches the end of the marked range, the dynamic binary rewriter stops and control is returned to the native program for execution.

[0058] 3. Execution process of dynamic binary rewriter

[0059] Dynamic rewrite execution: The dynamic binary rewriter rewrites and executes incompatible instructions within the marked range.

[0060] Range mark boundary handling: When the execution reaches the range mark boundary generated by the static binary rewriter, the dynamic binary rewriter will return program control to the native program for execution.

[0061] Looping execution: This process is repeated during program execution. Whenever the program reaches the beginning of a new marked range, the dynamic binary rewriter will be called again.

[0062] 4. Program execution complete

[0063] Program execution complete: When the program finishes execution, all rewriting and native execution processes will end.

[0064] This invention presents a hybrid method of static and dynamic binary rewriting. For chip manufacturers, designing instruction set architectures based on business needs and adding or removing instructions to improve performance is a common approach. However, this method can lead to compatibility issues between different generations of instruction sets within the same architecture, causing binary programs containing incompatible instructions to fail to run correctly. The solution provided by this invention addresses the incompatibility issues caused by hardware design at the software level and automatically, cost-effectively, efficiently, and seamlessly resolves this instruction set architecture fragmentation problem through various flexible usage and deployment methods. Compared to solutions that rely on hardware to ensure instruction compatibility, the solution provided by this invention offers advantages in terms of low cost and high flexibility.

[0065] For cloud service providers, providing compatibility support and performance optimization is crucial for their business development. Cloud service providers typically need to handle virtual machines and containers with different instruction set architectures, ensuring seamless operation on the cloud platform regardless of the instruction set used by the user. However, instruction set compatibility issues between different generations often cause user applications to malfunction, posing challenges to the stability and reliability of cloud services. This invention proposes a hybrid method and system of static and dynamic binary rewriting, which can solve this problem at the software level. The flexible operation mode and multiple deployment methods of this invention can efficiently solve the execution problem of source binary programs containing hardware-incompatible instructions, thereby avoiding performance losses and compatibility issues caused by differences in instruction set architecture. Compared to solutions that guarantee instruction compatibility through hardware, the solution of this invention has the advantages of low cost and high flexibility. It does not require expensive hardware upgrades or replacements; it only needs to be handled at the software level to automatically, cost-effectively, and efficiently solve the problem of instruction set architecture fragmentation. This allows cloud service providers to focus more on business development, improve service quality, and enhance market competitiveness.

[0066] For operating system developers, system updates and application compatibility are critical to their business development. Operating system developers typically need to support new instruction sets while ensuring compatibility with older instruction sets to provide a smooth transition experience. However, compatibility issues between different generations of instruction sets often cause older applications to malfunction on new operating systems, causing confusion and inconvenience for users. This invention proposes a method and system that combines static and dynamic binary rewriting to solve this problem at the software level. By combining static and dynamic rewriting, operating system developers can integrate this technology into system updates, ensuring compatibility with more older applications and reducing application malfunctions caused by system upgrades. This not only improves operating system compatibility and user experience but also enhances system stability and reliability.

[0067] For embedded system developers, device upgrades and real-time system performance optimization are crucial for business development. When upgrading hardware, embedded systems often need to ensure that the new hardware can still run older versions of software to avoid software incompatibility issues caused by the hardware upgrade. However, compatibility issues between different generations of instruction sets often prevent older software from running properly on new hardware, affecting device stability and functionality. This invention proposes a method and system that combines static and dynamic binary rewriting to solve this problem at the software level. By using this invention, embedded system developers can ensure that devices remain compatible with older software during hardware upgrades and maintain the system's high real-time performance requirements. This technology not only reduces runtime overhead and improves system response speed and stability but also flexibly responds to changes in hardware instruction sets, enhancing device performance and reliability. The flexible operation and multiple deployment methods of this invention can efficiently solve the execution problem of source binary programs containing hardware-incompatible instructions, thereby avoiding performance losses and compatibility issues caused by differences in instruction set architecture. This allows embedded system developers to focus more on device innovation and functional optimization, improving product competitiveness and increasing market share.

[0068] For game developers and publishers, cross-platform compatibility and performance optimization are crucial for business growth. Game developers often need to navigate different generations of hardware platforms, ensuring their games run seamlessly on various devices. However, compatibility issues between different generations of instruction sets often prevent games from functioning correctly on certain hardware platforms, impacting player experience and market reach. This invention allows game developers to ensure their games run seamlessly on different generations of hardware platforms, reducing the cost and complexity of developing multiple versions. This technology not only improves game speed and user experience but also flexibly adapts to changes in hardware instruction sets, optimizing game performance. Compared to solutions that rely on hardware to ensure instruction compatibility, this invention offers the advantages of low cost and high flexibility. It eliminates the need for expensive hardware upgrades or replacements, addressing instruction set architecture fragmentation automatically, cost-effectively, and efficiently at the software level. This allows game developers and publishers to focus more on game innovation and feature development, enhancing product competitiveness and increasing market share.

[0069] Example 1

[0070] A static binary rewriter that supports marking incompatible instruction ranges can be deployed independently as a tool. Processor model X supports instruction set architecture A1, while binary programs containing incompatible instructions use instruction set A2. A1 and A2 represent different generations of instruction sets within the same instruction set architecture. Example 1 provides the tool to users, enabling static binary rewriting, range marking, and optimization of binary source programs containing instructions incompatible with the current computing platform on a single computing platform.

[0071] The execution flow of Example 1 is as follows: Figure 5 As shown. When using the static binary rewriter, the user passes the source program as input. The static binary rewriter performs parsing, disassembly, control flow graph construction and analysis, structural information conversion, and code generation on the input source binary program. It statically rewrites target platform-incompatible instructions that can be statically rewritten into semantically equivalent, efficient, and target platform-supported instruction sequences, and marks the range of target platform-incompatible instructions that cannot be statically rewritten. After execution, the static binary rewriter automatically replaces the source binary program with the rewritten version. For source binary programs where all incompatible instructions can be statically rewritten, they can be executed natively on the target platform after static rewriting. For source binary programs containing some incompatible instructions that cannot be rewritten, they can be executed natively after static rewriting, and when the range is marked, the dynamic binary rewriter is invoked through the marked instructions to complete the execution.

[0072] Example 2

[0073] A dynamic binary rewriter supporting execution within a marked range is deployed independently as a tool. Processor model X supports instruction set architecture A1, while binary programs containing incompatible instructions support instruction set A2. A1 and A2 represent different generations of instruction sets within the same instruction set architecture. Example 2 provides the tool to users, enabling dynamic rewriting and execution of binary source programs within a marked range on a single computing platform.

[0074] The execution flow of Example 2 is as follows: Figure 6 As shown. After starting the dynamic binary rewriter, users have two options: Option 1 is to use the dynamic binary rewriter to execute code segments within the marked range of an executable file that has been statically rewritten; Option 2 is to use the dynamic binary rewriter to execute the original executable file that has not been rewritten by the static rewriter. When a user runs the rewritten executable file, the dynamic binary rewriter selects its function and execution mode to rewrite the code within the marked range until execution ends. Option 2 is a special case of Option 1, and can be equivalently considered as the case where the start and end points of the marked range are set at the program entry point and program end point of the executable file.

[0075] Example 3

[0076] A static binary rewriter that supports marking incompatible instruction ranges and a dynamic binary rewriter that supports execution within the marked range are deployed together as tools. Processor model X supports instruction set architecture A1, while the instruction set of the binary program containing incompatible instructions is A2, where A1 and A2 are different generations of instruction sets within the same instruction set architecture. Example 3 provides the tool to users, enabling static binary rewriting, range marking, and optimization of binary source programs containing instructions incompatible with the current computing platform on a single computing platform, as well as dynamic rewriting and execution of the statically rewritten binary source program within the marked range.

[0077] The execution flow of Example 3 is as follows: Figure 7 As shown in the diagram. When the user uses the program, both the static binary rewriter and the dynamic binary rewriter are activated. The user inputs an executable file containing incompatible instructions that cannot be executed natively into the static binary rewriter, which then rewrites the executable file and executes it natively. If the rewritten executable file contains incompatible instructions marked with a range, when the user executes the program natively to the range mark, the dynamic binary rewriter will execute it using a dynamic binary rewriter that supports execution within the marked range. After executing the marked range, native execution continues. If multiple range marks are encountered during continued execution, the above process is repeated until the program terminates. During this execution process, the user remains unaware of the dynamic binary rewriter's intervention. This achieves efficient and seamless execution of hardware-incompatible instructions.

[0078] Example 4

[0079] A static binary rewriter that marks incompatible instruction ranges is supported as a tool, while a dynamic binary rewriter that executes within the marked range is supported as a dynamic link library service. Processor model X supports instruction set architecture A1, while the instruction set of the binary program containing incompatible instructions is A2. A1 and A2 represent different generations of instruction sets within the same instruction set architecture. Example 4 provides the tool to users, enabling static binary rewriting of binary source programs containing instructions incompatible with the current computing platform on a single computing platform. During the rewriting process, dynamic link library function instructions are instrumented at the marked ranges, allowing users to directly execute the rewritten binary program natively without needing to separately enable the dynamic binary rewriter tool.

[0080] The execution flow of Example 4 is as follows. When the user uses the program, both the static binary rewriter and the dynamic binary rewriter are started. The user inputs an executable file containing incompatible instructions that cannot be executed natively into the static binary rewriter, obtaining a rewritten executable file that can be executed directly natively. During the rewriting process, dynamic link library function call instructions containing the functionality of the dynamic binary rewriter are inserted at the scope markers. The rewritten executable file can be executed directly natively without needing to start the dynamic binary rewriter separately, thus simplifying the user experience.

[0081] Example 5

[0082] Static binary rewriters supporting the marking of incompatible instruction ranges and dynamic binary rewriters supporting execution within the marked ranges are deployed as services in a single-machine operating system. Processor model X supports instruction set architecture A1, while the instruction set for binary programs containing incompatible instructions is A2, where A1 and A2 are different generations of the same instruction set architecture. Example 4 provides this as a service to users, enabling the static binary rewriter supporting the marking of incompatible instruction ranges and the dynamic binary rewriter supporting execution within the marked ranges as default services on a single computing platform. This automatically and seamlessly rewrites and executes executable programs containing incompatible instructions within the single-machine operating system's file system without the user's awareness.

[0083] The execution flow of Example 5 is as follows: Figure 2As shown, this deployment scheme is the default deployment method when the user does not specify a special usage method. The static binary rewriter and dynamic binary rewriter are deployed in a single-machine operating system to achieve automated, seamless rewriting and execution optimization of user-specified binary executable files. When the operating system starts, both the static and dynamic binary rewriter modules start as daemons and run continuously in the background, monitoring user-specified directories or paths. Using file system monitoring tools (including but not limited to inotify and fswatch), the system continuously monitors these directories or paths. When a new binary executable file is detected, the static binary rewriter module automatically rewrites the new binary executable file. After rewriting, the rewritten binary file replaces the original binary file. When any statically rewritten binary executable file is executed by the user, when it reaches a range marking instruction, the dynamic binary rewriter is activated to rewrite the execution. After executing the marked range, control is returned to continue native execution, repeating this process until the program terminates. Through a fully automated process, the system automatically monitors, rewrites, and optimizes binary files without user intervention. Utilizing a highly efficient system implementation, it ensures low latency and high performance during the rewriting process. Operating system permission management and isolation mechanisms are employed to isolate binary files from different users, guaranteeing the security of user data and the execution environment. By integrating system-level monitoring tools (including but not limited to Prometheus and Grafana), the system monitors the running status, performance metrics, and error logs of static and dynamic binary rewriter modules in real time, ensuring stable service operation and providing detailed logging and analysis tools to help users understand the entire binary file rewriting and execution process. Through this deployment method, the system can automatically and seamlessly resolve incompatibility issues between different generations of instruction sets within the same instruction set architecture, ensuring low runtime overhead and seamless operation of binary executables containing incompatible instructions on a single-machine operating system.

[0084] Example 6

[0085] Static binary rewriters that support incompatible instruction ranges and dynamic binary rewriters that support execution within a specified range can be deployed as services on cloud servers, such as... Figure 8 As shown. Processor model X supports instruction set architecture A1, while the instruction set for binary programs containing incompatible instructions is A2. A1 and A2 are different generations of instruction sets within the same instruction set architecture. Example 6 provides this service to users. On the cloud service platform, a static binary rewriter that supports marking incompatible instruction ranges and a dynamic binary rewriter that supports execution within the marked range are enabled by default as server daemons. This automatically and seamlessly rewrites and executes executable programs containing incompatible instructions in the cloud server's file system without the user's awareness.

[0086] The execution flow of Example 6 is as follows: Figure 8 As shown, the static and dynamic binary rewriters are deployed as SaaS (Software as a Service) to automate and seamlessly rewrite and optimize the execution of user-defined binary executables. Both modules are deployed on cloud servers to ensure high availability and scalability. Containerization technologies (including but not limited to Docker and Kubernetes) are used for management, ensuring flexible scaling during peak loads. Users can upload binary executables via API or web interface, specifying the monitored directory or path. When the cloud service starts, both modules start as daemons and run continuously in the background, monitoring the specified directory or path. File system monitoring tools (including but not limited to inotify and fswatch) continuously monitor the user-specified directory or path, triggering corresponding processing flows when a new binary executable is uploaded or added. The static binary rewriter module automatically rewrites the new binary executable, storing the rewritten binary file in the cloud file system or directly providing feedback to the user after completion. When any statically rewritten binary executable file is executed in the cloud, the dynamic binary rewriter module automatically starts and performs rewriting when it reaches a specific range marked by the static binary rewriter. Through a fully automated process, no user intervention is required; the system automatically monitors, rewrites, and optimizes the execution of binary files. Virtualization technologies (such as virtual machines and containers) are used to isolate binary files from different users, ensuring the security of user data and the execution environment. Encryption technologies (including but not limited to TLS / SSL) are used to protect the secure transmission of user-uploaded binary files and rewritten files. An integrated monitoring system (including but not limited to Prometheus and Grafana) monitors the running status, performance metrics, and error logs of the static and dynamic binary rewriter modules in real time, ensuring stable service operation and providing detailed logging and analysis tools to help users understand the entire process of binary file rewriting and execution. Through this SaaS deployment approach, the system can automatically and seamlessly resolve incompatibility issues between different generations of instruction sets within the same instruction set architecture, ensuring low runtime overhead and seamless operation of binary executables containing incompatible instructions on different platforms.

[0087] Example 7

[0088] Static binary rewriters supporting incompatible instruction ranges and dynamic binary rewriters supporting execution within the specified ranges are deployed as services in embedded devices. Processor model Y supports instruction set architecture A1, while the instruction set for binary programs containing incompatible instructions is A2, where A1 and A2 are different generations of the same instruction set architecture. Example 7 provides a solution for implementing binary rewriting and execution optimization on resource-constrained embedded devices.

[0089] When an embedded device boots up, both the static binary rewriter module and the dynamic binary rewriter module are loaded as system services. These modules continuously monitor specific directories in the device's file system, detecting binary executables containing incompatible instructions. When a new file is detected, the static binary rewriter module automatically rewrites it and replaces the original file with the rewritten binary. To optimize resource usage on the embedded device, the static rewriting process is performed when the device is idle, minimizing the impact on user experience. When a user executes a statically rewritten binary file, the dynamic binary rewriter module rewrites the marked instruction range in real time during program execution and returns control to the native program upon completion. This process is automatically managed by the system without user intervention. By integrating lightweight monitoring tools, the system can monitor the rewriter module's running status in real time, ensuring efficient device operation. To guarantee security and reliability on the embedded device, the rewriter module employs a device-level permission management mechanism during execution, ensuring the isolation and protection of binary files. Through a fully automated process, the embedded device can resolve incompatibility issues between different generations of instruction sets within the same instruction set architecture without impacting performance, ensuring seamless execution of binary programs.

[0090] Example 8

[0091] Static binary rewriters supporting the marking of incompatible instruction ranges and dynamic binary rewriters supporting execution within the marked ranges are deployed as services in the edge-cloud collaborative platform. Processor model Z supports instruction set architecture A1, while binary programs containing incompatible instructions use instruction set A2, where A1 and A2 are different generations of the same instruction set architecture. Example 8 provides an effective deployment method for binary rewriting and execution optimization in edge computing scenarios.

[0092] In the edge-cloud collaborative platform, static and dynamic binary rewriter modules are deployed on edge nodes and cloud servers. Through edge nodes, the system can quickly respond to user operations, uploading binary files for initial processing. The static binary rewriter module automatically rewrites the uploaded binary files on the edge nodes and synchronizes the processed files to the cloud server for storage or further processing. When a binary file needs to be executed on the cloud or edge node, the dynamic binary rewriter module performs real-time rewriting within a marked range and returns execution control to the native program upon completion. This collaborative processing mode ensures efficient and seamless execution across different computing platforms. By adopting containerization technologies and edge computing frameworks (including but not limited to Kubernetes and EdgeX Foundry), the platform achieves high availability and flexible scalability, adapting to different loads and network environments. The system integrates cross-platform monitoring tools to monitor the status and performance of the static and dynamic binary rewriter modules in real time, ensuring stable service operation. Employing distributed security management mechanisms and encryption technologies (including but not limited to TLS / SSL), the system ensures the security of user data transmission and storage across the edge-cloud platform. Through the above deployment method, the edge-cloud collaborative platform can solve the problem of incompatibility between different generations of instruction sets with the same instruction set architecture in a fully automated and user-unobtrusive manner, and achieve efficient binary file rewriting and execution optimization.

[0093] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The solutions in the embodiments of this application can be implemented in various computer languages, such as the object-oriented programming language Java and the interpreted scripting language JavaScript.

[0094] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1A device that provides the functions specified in one or more boxes.

[0095] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0096] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0097] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.

[0098] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

[0099] The scope of protection of this invention is not limited to the above embodiments. Any variations and advantages that can be conceived by those skilled in the art without departing from the spirit and scope of this invention are included in this invention and are protected by the appended claims.

Claims

1. A hybrid method of static binary rewriting and dynamic binary rewriting, characterized in that, The method includes the following steps: Step 1: Parse the source binary executable file to obtain the file structure and instruction information, and analyze and determine the instructions that are incompatible with the target platform; Step 2: For all target platform incompatible instructions obtained after Step 1, plan one or more optimal range intervals containing instructions that do not support static rewriting in the incompatible instructions, and mark the start and end positions of the intervals. Then, statically rewrite the instructions that can be statically rewritten in the incompatible instructions to generate a binary executable file that has been statically rewritten and marked with the instruction range that does not support static rewriting. Step 3: Execute the binary executable file generated in Step 2. When the execution reaches the beginning of the instruction range that does not support static rewriting, call the dynamic binary rewriter to take over the control execution flow of the program, dynamically rewrite and execute the incompatible instructions in the marked range, and hand over control to the generated program to continue execution after the marked range ends. Step 4: Repeat the dynamic binary rewriter rewriting and execution steps in Step 3 according to the range and number of marked instructions in the binary executable file until the complete program is executed.

2. The method as described in claim 1, characterized in that, In step one, the set of instructions that the current hardware platform cannot natively execute is obtained by decoding the instructions in the .text segment of the source binary executable file, which are referred to as incompatible instructions; the incompatible instructions include instructions that support static rewriting and instructions that do not support static rewriting.

3. The method as described in claim 1, characterized in that, In step two, the optimal range interval, including one or more instructions that do not support static rewrite, is planned using the overhead model, and the start and end positions of the optimal range interval are obtained. The overhead model is established by combining function boundary information, the distribution characteristics of instructions that cannot be statically rewritten in functions, and program control execution flow analysis.

4. The method as described in claim 1, characterized in that, In step two, the parts of the incompatible instructions on the target platform that can be statically rewritten are subjected to semantically equivalent static rewriting, generating a statically rewritten instruction sequence; and / or, Insert function call instructions that invoke the dynamic binary rewriter at the beginning and end of the instruction range that does not support static rewriting; and / or, The static binary rewriter uses a disassembler and a control flow graph to disassemble the input source binary executable file and construct a control flow graph representation.

5. The method as described in claim 1, characterized in that, The static binary rewriter is optimized through platform-specific and / or platform-independent optimizations; The platform-related optimizations include the selection of the optimal semantically equivalent instruction after instruction rewriting and register allocation optimization. The platform-independent optimizations include code layout optimization, function rearrangement optimization, performance sampling information-guided optimization, and post-linking optimization.

6. The method as described in claim 1, characterized in that, In step three, for instructions within the marked range, decoding is performed on a block-by-block basis, converting the instruction sequence into an intermediate representation, and rewriting incompatible instructions that do not support static rewriting into semantically equivalent instruction sequences supported by the target platform; and / or, Function call instructions are inserted at the beginning and end of the marked range, and the takeover and exchange of program control in the control flow are achieved by executing function calls; the function calls perform context switching and pass process information to the process where the dynamic binary rewriter resides; and / or, The dynamic binary rewriter performs code generation, code cache management, and native execution of code cache blocks on a basic block basis.

7. The method as described in claim 1, characterized in that, It automatically starts when the operating system boots and monitors the file system, automatically parsing, statically rewriting, and dynamically rewriting incoming executable files; and / or, During the execution of the dynamic binary rewriter, code cache blocks are linked into execution paths that do not contain jump instructions.

8. A hybrid system of static binary rewriting and dynamic binary rewriting, characterized in that, The system includes: a static binary rewriter and a dynamic binary rewriter; The static binary rewriter performs static rewriting on the parts of incompatible instructions that support static rewriting, and marks the range of the parts that do not support static rewriting. The dynamic binary rewriter takes over the control execution flow of the source program and dynamically rewrites and executes instructions within the marked range that cannot be statically rewritten.

9. The application of the static binary rewriting and dynamic binary rewriting hybrid method as described in any one of claims 1-7 or the hybrid system as described in claim 8 in chip design optimization, cloud computing platform compatibility support, operating system upgrade and compatibility maintenance, embedded system hardware upgrade, and cross-platform game development.