CN112527303B - GOT table management method based on dynamic library and oriented to just-in-time compilation - Google Patents

GOT table management method based on dynamic library and oriented to just-in-time compilation Download PDF

Info

Publication number
CN112527303B
CN112527303B CN201910885728.XA CN201910885728A CN112527303B CN 112527303 B CN112527303 B CN 112527303B CN 201910885728 A CN201910885728 A CN 201910885728A CN 112527303 B CN112527303 B CN 112527303B
Authority
CN
China
Prior art keywords
engine
dynamic link
link library
compiling
time
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910885728.XA
Other languages
Chinese (zh)
Other versions
CN112527303A (en
Inventor
周文浩
王飞
沈莉
肖谦
武文浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuxi Jiangnan Computing Technology Institute
Original Assignee
Wuxi Jiangnan Computing Technology Institute
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuxi Jiangnan Computing Technology Institute filed Critical Wuxi Jiangnan Computing Technology Institute
Priority to CN201910885728.XA priority Critical patent/CN112527303B/en
Publication of CN112527303A publication Critical patent/CN112527303A/en
Application granted granted Critical
Publication of CN112527303B publication Critical patent/CN112527303B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • G06F9/45516Runtime code conversion or optimisation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a real-time compiling-oriented GOT table management method based on a dynamic library, which comprises the following steps: s1, creating a dynamic link library containing a GOT table, wherein the GOT table is positioned in the data section of the dynamic link library; s2, before the instant compiling engine analyzes and relocates, dynamically loading the GOT table into a memory space, and acquiring the initial address of the GOT table; s3, the instant compiling engine overwrites the GOT table and refills the repositioning according to the repositioning type of the program code segment; s4, dynamically releasing the dynamic link library containing the GOT list after the instant compiling and executing of the program are finished; and S42, quitting the just-in-time compiling. The invention reduces the support difficulty of the LLVM just-in-time compilation engine on the GOT table in the back end of the newly added hardware, improves the transplantation efficiency of the LLVM just-in-time compilation engine, and quickly realizes the GOT table management based on the dynamic library in the LLVM just-in-time compilation engine based on the domestic processor.

Description

GOT table management method based on dynamic library and oriented to just-in-time compilation
Technical Field
The invention relates to a GOT table management method based on a dynamic library and oriented to just-in-time compilation, and belongs to the technical field of compilation optimization.
Background
Just-In-Time (Just-In-Time) is a way to dynamically compile intermediate code, translating the code into machine code and executing as needed during program execution. Just-in-time compilation technology is widely used by compilers of emerging languages such as Java language,. net platform, LuaJIT, and the like. Just-in-time compilation combines the advantages of static compilation and interpreted execution, can produce efficient machine code, and has sufficient flexibility.
LLVM (lower Level Virtual machine) is a very popular compiler basic framework today, and the just-in-time compiling function is considered at the beginning of the design. It employs a self-created code optimization mechanism, and has a clear architectural hierarchy and detailed development documentation, which are being used by more and more scientific research institutions and business projects. Just-in-time compilation of LLVM is adopted by more and more compiling platforms as a new compiling technology, combining the advantages of static compilation and interpreted execution.
The domestic processor adopts an architecture and an instruction set design which are completely different from the existing architecture, so that the real-time compiling engine of the LLVM cannot be directly reused. In the process space of the file in the ELF format, a Global Offset Table (GOT) stores global offset values of all global variable addresses, the global offset table can position the addresses which are independent of positions to absolute addresses, and the global offset table plays a very important role in reference and relocation of global variables. The current MIPS of LLVM and the just-in-time compilation engine of ARM back end generate program GOT table through memory manager, which realizes the complex logic and the tight coupling with the hardware back end, and is difficult to be transplanted to the back end of the domestic processor.
Disclosure of Invention
The invention aims to provide a GOT table management method facing to just-in-time compilation and based on a dynamic library, which reduces the support difficulty of an LLVM (Linear object model) just-in-time compilation engine on a GOT table in the rear end of a newly added hardware, improves the transplantation efficiency of the LLVM just-in-time compilation engine, and quickly realizes the GOT table management based on the dynamic library in the LLVM just-in-time compilation engine based on a domestic processor.
In order to achieve the purpose, the invention adopts the technical scheme that: a GOT table management method based on a dynamic library and oriented to just-in-time compilation comprises the following steps:
s1, the compiler creates a dynamic link library including a GOT table in the compiling stage of the just-in-time compiling engine, where the GOT table is located in a data segment of the dynamic link library, which is as follows:
s11, defining a GOT table array of unsigned integer type in a source file of the instant compiling engine, storing data of the GOT table in an array form, and declaring that the size of the GOT table array is 64K;
s12, compiling the source file containing the GOT table array defined in the step S11 by using a shared object creation option-shared and an address-independent code generation option-fPIC of the linker, and constructing a dynamic link library containing the GOT table;
s2, before the just-in-time compilation engine parses and relocates the program code segments of the user program, the just-in-time compilation engine dynamically loads the dynamic link library containing the GOT table, which is constructed in step S1, into the memory space of the computer using a load dynamic library function dlopen, and obtains the initial address of the GOT table, which is specifically as follows:
s21, the just-in-time compilation engine loads a dynamic link library containing the GOT table to the memory space by using a function dlopen for loading a dynamic library;
s22, the just-in-time compilation engine acquires the initial address of the GOT table from the dynamic link library loaded in the step S21 by using the dynamic library symbol address acquisition function dlsym;
s3, the just-in-time compilation engine obtains the relocation type by analyzing the variable access instruction of the program code segment using the GOT table, and performs GOT table overwriting and relocation backfilling on the GOT table in the dynamic link library loaded in the step S2 according to the relocation type, which specifically includes the following steps:
s31, if the relocation type of the program code segment is GPREL, namely the GOT table first address offset addressing mode, firstly obtaining the actual address of the variable in the memory space in the program code segment through the just-in-time compiling engine, then filling the difference value of the actual address of the variable and the first address of the GOT table into the offset bit of the variable access instruction, and completing relocation backfilling;
s32, if the relocation type of the program code segment is LITERAL, namely a GOT table indirect addressing mode, firstly obtaining the actual address of the variable in the memory space in the program code segment through the just-in-time compiling engine, then filling the actual address of the variable into the GOT table entry in the dynamic link library loaded in the step S2 to complete the overwriting of the GOT table, and finally filling the offset of the GOT table entry in the GOT table into the offset bit of the variable access instruction to complete the relocation refilling;
s4, after the instant compilation execution of the program is finished, the instant compilation engine dynamically releases the dynamic link library containing the GOT table loaded in step S2, which is specifically as follows:
s41, the just-in-time compiling engine dynamically releases the memory space where the dynamic link library containing the GOT list is located by using a function dlclose of closing the dynamic link library;
and S42, exiting the just-in-time compiling engine.
Due to the application of the technical scheme, compared with the prior art, the invention has the following advantages:
the invention relates to a GOT table management method based on a dynamic library for just-in-time compilation, which is characterized in that a GOT table of a user program is placed in a data section of the dynamic library, the GOT table is managed in the just-in-time compilation process in a dynamic loading mode, the dynamic GOT table is overwritten according to the relocation type of a global variable, rapid and light global address offset calculation and relocation backfill are realized, the supporting difficulty of a LLVM (low level virtual machine) just-in-time compilation engine on the GOT table in the rear end of newly-added hardware is reduced, the transplantation efficiency of the LLVM just-in-time compilation engine is improved, and the GOT table management based on the dynamic library is rapidly realized in the LLVM just-in-time compilation engine based on a domestic processor.
Drawings
FIG. 1 is a schematic flow chart of a GOT table management method based on a dynamic library for just-in-time compilation.
Detailed Description
The embodiment is as follows: a GOT table management method based on a dynamic library and oriented to just-in-time compilation comprises the following steps:
s1, the compiler creates a dynamic link library including a GOT table at the compiling stage of the instant compiling engine, where the GOT table is located in a data segment of the dynamic link library, which is as follows:
s11, defining a GOT table array of unsigned integer type in a source file of the instant compiling engine, storing data of the GOT table in an array form, and declaring that the size of the GOT table array is 64K;
s12, compiling the source file containing the GOT table array defined in the step S11 by using a shared object creation option-shared and an address-independent code generation option-fPIC of the linker, and constructing a dynamic link library containing the GOT table;
s2, before the just-in-time compilation engine parses and relocates the program code segments of the user program, the just-in-time compilation engine dynamically loads the dynamic link library containing the GOT table, which is constructed in step S1, into the memory space of the computer using a load dynamic library function dlopen, and obtains the initial address of the GOT table, which is specifically as follows:
s21, the just-in-time compilation engine loads a dynamic link library containing the GOT table to the memory space by using a function dlopen for loading a dynamic library;
s22, the just-in-time compilation engine acquires the initial address of the GOT table from the dynamic link library loaded in the step S21 by using the dynamic library symbol address acquisition function dlsym;
s3, the just-in-time compilation engine obtains the relocation type by analyzing the variable access instruction of the program code segment using the GOT table, and performs GOT table overwriting and relocation backfilling on the GOT table in the dynamic link library loaded in the step S2 according to the relocation type, which specifically includes the following steps:
s31, if the relocation type of the program code segment is GPREL, namely the GOT table first address offset addressing mode, firstly obtaining the actual address of the variable in the memory space in the program code segment through the just-in-time compiling engine, then filling the difference value of the actual address of the variable and the first address of the GOT table into the offset bit of the variable access instruction, and completing relocation backfilling;
s32, if the relocation type of the program code segment is LITERAL, namely a GOT table indirect addressing mode, firstly obtaining the actual address of the variable in the memory space in the program code segment through the just-in-time compiling engine, then filling the actual address of the variable into the GOT table entry in the dynamic link library loaded in the step S2 to complete the overwriting of the GOT table, and finally filling the offset of the GOT table entry in the GOT table into the offset bit of the variable access instruction to complete the relocation refilling;
s4, after the instant compilation execution of the program is finished, the instant compilation engine dynamically releases the dynamic link library containing the GOT table loaded in step S2, which is specifically as follows:
s41, the just-in-time compiling engine dynamically releases the memory space where the dynamic link library containing the GOT list is located by using a function dlclose of closing the dynamic link library;
and S42, exiting the just-in-time compiling engine.
The examples are further explained below:
the specific process of the invention is shown in figure 1.
The method mainly comprises four steps of dynamically creating a GOT table, dynamically loading the GOT table, overwriting the GOT table according to the relocation type, relocating and backfilling the GOT table, and dynamically releasing the GOT table.
(1) Firstly, a dynamic link library containing a GOT table is created, and the GOT table is located in a data segment of the dynamic library, which is as follows:
1. defining a GOT table array of unsigned integer type in a source file and declaring a GOT table size of 64K;
Figure BDA0002207250730000041
2. a dynamic link library containing GOT tables is built using the-shared-fPIC option of the linker.
(2) Secondly, before the instant compiling engine analyzes and relocates, dynamically loading the GOT table into a memory space, and acquiring a GOT table head address, which is as follows:
1. loading a dynamic link library containing a GOT table by using a dlopen function;
2. the GOT table header address is obtained from the dynamic link library using the dlsym function.
(3) Thirdly, the just-in-time compilation engine performs GOT table overwriting and relocation backfilling according to the relocation type of the program code segment, which specifically comprises the following steps:
1. if the relocation type is GPREL, carrying out relocation backfill according to the actual address of the variable and the GOT table head address;
2. if the relocation type is LITERAL, performing GOT table item overwriting and relocation backfilling according to the actual address of the variable.
(4) Finally, after the instant compilation execution of the program is finished, dynamically releasing the dynamic link library containing the GOT table, which specifically comprises the following steps:
1. dynamically releasing a dynamic link library containing the GOT table by using a dlclose function;
2. and exiting the just-in-time compilation.
When the instant compiling-oriented dynamic library-based GOT table management method is adopted, the GOT table of the user program is placed in the data section of the dynamic library, the GOT table is managed in the instant compiling process in a dynamic loading mode, the dynamic GOT table is overwritten according to the relocation type of the global variable, rapid and light-weight global address offset calculation and relocation backfill are achieved, the supporting difficulty of the LLVM instant compiling engine on the GOT table in the rear end of the newly added hardware is reduced, the transplanting efficiency of the LLVM instant compiling engine is improved, and the GOT table management based on the dynamic library is rapidly achieved in the LLVM instant compiling engine based on the domestic processor.
To facilitate a better understanding of the invention, the terms used herein will be briefly explained as follows:
LLVM: lower Level Virtual Machine, an open source compiler project developed by university of illinois, usa.
And (3) just-in-time compiling: Just-In-Time Compilation, a Compilation mode that translates code into machine code when a program is executed.
Static compilation: Ahead-Of-Time Compilation, a Compilation Of code that translates into machine code before program execution.
The explanation executes: the execution mode of the computer language is interpreted and executed by the interpreter in the field, and a target program is not generated.
ELF: a format for binary files, executable files, object code, shared libraries, and core dump files.
The above embodiments are only for illustrating the technical idea and features of the present invention, and the purpose of the present invention is to enable those skilled in the art to understand the content of the present invention and implement the present invention, and not to limit the protection scope of the present invention by this means. All equivalent changes and modifications made according to the spirit of the present invention should be covered within the protection scope of the present invention.

Claims (1)

1. A GOT table management method based on a dynamic library and oriented to just-in-time compilation is characterized by comprising the following steps: the method comprises the following steps:
s1, the compiler creates a dynamic link library including a GOT table in the compiling stage of the just-in-time compiling engine, where the GOT table is located in a data segment of the dynamic link library, which is as follows:
s11, defining a GOT table array of unsigned integer type in a source file of the instant compiling engine, storing data of the GOT table in an array form, and declaring that the size of the GOT table array is 64K;
s12, compiling the source file containing the GOT table array defined in the step S11 by using a shared object creation option-shared and an address-independent code generation option-fPIC of the linker, and constructing a dynamic link library containing the GOT table;
s2, before the just-in-time compilation engine parses and relocates the program code segments of the user program, the just-in-time compilation engine dynamically loads the dynamic link library containing the GOT table, which is constructed in step S1, into the memory space of the computer using a load dynamic library function dlopen, and obtains the initial address of the GOT table, which is specifically as follows:
s21, the just-in-time compilation engine loads a dynamic link library containing the GOT table to the memory space by using a function dlopen for loading a dynamic library;
s22, the just-in-time compilation engine acquires the initial address of the GOT table from the dynamic link library loaded in the step S21 by using the dynamic library symbol address acquisition function dlsym;
s3, the just-in-time compilation engine obtains the relocation type by analyzing the variable access instruction of the program code segment using the GOT table, and performs GOT table overwriting and relocation backfilling on the GOT table in the dynamic link library loaded in the step S2 according to the relocation type, which specifically includes the following steps:
s31, if the relocation type of the program code segment is GPREL, namely the GOT table first address offset addressing mode, firstly obtaining the actual address of the variable in the memory space in the program code segment through the just-in-time compiling engine, then filling the difference value of the actual address of the variable and the first address of the GOT table into the offset bit of the variable access instruction, and completing relocation backfilling;
s32, if the relocation type of the program code segment is LITERAL, namely a GOT table indirect addressing mode, firstly obtaining the actual address of the variable in the memory space in the program code segment through the just-in-time compiling engine, then filling the actual address of the variable into the GOT table entry in the dynamic link library loaded in the step S2 to complete the overwriting of the GOT table, and finally filling the offset of the GOT table entry in the GOT table into the offset bit of the variable access instruction to complete the relocation refilling;
s4, after the instant compilation execution of the program is finished, the instant compilation engine dynamically releases the dynamic link library containing the GOT table loaded in step S2, which is specifically as follows:
s41, the just-in-time compilation engine dynamically releases the memory space where the dynamic link library containing the GOT list is located by using a function dlclose of closing the dynamic link library;
and S42, exiting the just-in-time compiling engine.
CN201910885728.XA 2019-09-19 2019-09-19 GOT table management method based on dynamic library and oriented to just-in-time compilation Active CN112527303B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910885728.XA CN112527303B (en) 2019-09-19 2019-09-19 GOT table management method based on dynamic library and oriented to just-in-time compilation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910885728.XA CN112527303B (en) 2019-09-19 2019-09-19 GOT table management method based on dynamic library and oriented to just-in-time compilation

Publications (2)

Publication Number Publication Date
CN112527303A CN112527303A (en) 2021-03-19
CN112527303B true CN112527303B (en) 2022-09-13

Family

ID=74974036

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910885728.XA Active CN112527303B (en) 2019-09-19 2019-09-19 GOT table management method based on dynamic library and oriented to just-in-time compilation

Country Status (1)

Country Link
CN (1) CN112527303B (en)

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105095762B (en) * 2015-07-31 2017-10-10 中国人民解放军信息工程大学 Based on random and section isolation the global offset table guard method in address
CN109814939B (en) * 2017-11-20 2021-10-15 华为技术有限公司 Dynamic loading method, and target file manufacturing method and device

Also Published As

Publication number Publication date
CN112527303A (en) 2021-03-19

Similar Documents

Publication Publication Date Title
US20140165035A1 (en) Expansion and reduction of source code for code refactoring
JP3706065B2 (en) Porting various source languages to execution media
CN111770116B (en) Method for executing intelligent contract, block chain node and storage medium
CN109739508B (en) Source code compiling method, device, system and storage medium
US9134973B2 (en) Dynamic compiling and loading at runtime
CN111815310B (en) Method for executing intelligent contract, block chain node and storage medium
US10809985B2 (en) Instrumenting program code
CN111770204B (en) Method for executing intelligent contract, block chain node and storage medium
WO2022237590A1 (en) Smart contract upgrading method and blockchain system
CN111768183A (en) Method for executing intelligent contract, block chain node and storage medium
WO2011116113A1 (en) Loop transformation for compiler optimization
CN112527303B (en) GOT table management method based on dynamic library and oriented to just-in-time compilation
US20100083238A1 (en) Binary manipulation of intermediate-language code
CN111770202B (en) Method for executing intelligent contract, block chain node and storage medium
WO2019168693A1 (en) Compiler-generated asynchronous enumerable object
CN114115964B (en) Hot updating method and device for Unity, computing equipment and computer-readable storage medium
JP2006163686A (en) Compiling method, compiling program, compiling device and recording medium for compile
Sánchez Cuadrado et al. The program is the model: Enabling transformations@ run. time
US20170083298A1 (en) Resilient format for distribution of ahead-of-time compiled code components
CN114443052A (en) Dynamic specialization method and device during IL instruction operation
Gregersen et al. Towards a Dynamic-update-enabled JVM
CN115048184A (en) Method and device for optimizing execution of interpreter instruction
CN113220327A (en) Intelligent contract upgrading method and block chain system
CN114594981B (en) Method and device for solving generic compatibility problem during hot update
KR100763199B1 (en) Method for calling a method in virtual machine environment and system including a virtual machine processing the method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant