Executable and linkable file analysis method and electronic equipment
By optimizing ELF file parsing through multi-level caching and parallel parsing technology, the low efficiency problem in the existing technology is solved, and efficient file parsing is achieved, which is suitable for ELF files in Unix and Linux systems.
Patent Information
- Application Number
- CN202511203667.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-26
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2045-08-26
AI Technical Summary
The ELF file parsing method in the existing technology is inefficient, especially when parsing large files or a large number of files in batches. It cannot fully utilize the advantages of multi-core CPUs and there is an I/O bottleneck, which leads to a decrease in system performance.
It adopts a multi-level cache mechanism and parallel parsing technology. By identifying the data structure of ELF files, it uses multi-level cache to store parsing results, skips repeated parsing, combines multi-core processors to parse non-dependent sections in parallel, and uses intelligent preloading strategies to optimize cache usage.
It improves the efficiency of ELF file parsing, reduces memory usage and I/O operation frequency, avoids operating system performance degradation, and significantly reduces parsing time and resource consumption in embedded systems and large-scale software analysis scenarios.
Smart Images

Figure CN120723339A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an executable and linkable file parsing method and electronic device. Background Art
[0002] ELF (Executable and Linkable Format) file is a common executable file format, widely used in Unix and Linux systems. It has a multi-layer data structure with interrelated parts and a complex structure.
[0003] The ELF file parsing method in the related art usually adopts the method of sequential reading and segment-by-segment parsing. When faced with large files or batch parsing tasks of a large number of ELF files, the efficiency is not high. When the same part of the same ELF file is accessed multiple times, the parsing will be repeated, resulting in low ELF file parsing efficiency. Summary of the Invention
[0004] The present application provides a method for parsing executable and linkable files to at least solve the problem of low parsing efficiency of executable and linkable files in related technologies.
[0005] The present application provides a method for parsing executable and linkable files, comprising the following steps: responding to a parsing instruction of an executable and linkable file, identifying a data structure of the executable and linkable file, wherein the data structure includes multi-level data; querying whether multi-level data is stored in a multi-level cache according to the data structure; if current-level data is stored in a current-level cache, skipping the parsing of the current-level data; if current-level data is not stored in the current-level cache, loading the current-level data from a hard disk into the current-level cache; and reading the parsing results of the executable and linkable files from the multi-level cache.
[0006] The present application also provides an executable and linkable file parsing device, including: a response module, used to respond to the parsing instructions of the executable and linkable files, and identify the data structure of the executable and linkable files, wherein the data structure includes multi-level data; a query module, used to query whether the multi-level cache stores multi-level data according to the data structure; if the current level data is stored in the current level cache, the parsing of the current level data is skipped; if the current level data is not stored in the current level cache, the current level data is loaded from the hard disk to the current level cache; a reading module, used to read the parsing results of the executable and linkable files from the multi-level cache.
[0007] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any one of the above-mentioned executable and linkable file parsing methods when executing the computer program.
[0008] The present application also provides a non-volatile computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the above-mentioned executable and linkable file parsing methods are implemented.
[0009] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned executable and linkable file parsing methods when executed by a processor.
[0010] Through the present application, the data structure of executable and linkable files can be identified, and whether multi-level data is stored in the multi-level cache can be queried based on the data structure. When the current-level data is stored in the current-level cache, the parsing of the current-level data is skipped, and the executable and linkable file results are directly obtained from the cache. If the current-level data is not stored in the current-level cache, the current-level data is loaded from the hard disk to the current-level cache. By storing the parsed multi-level data of executable and linkable files in the multi-level cache, it is possible to parse the same executable and linkable files without repeated parsing, reduce memory usage, and thus improve the parsing efficiency of executable and linkable files. There is no need to load the data of executable and linkable files from the hard disk through frequent I / O (Input / Output) operations, thereby avoiding affecting the performance of the operating system. Therefore, the technical problem of low parsing efficiency of executable and linkable files in related technologies can be solved, and the technical effect of improving parsing efficiency can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0012] Figure 1 A flowchart of an executable and linkable file parsing method provided according to an embodiment of the present application; Figure 2 A structural diagram of an executable and linkable file parsing system provided according to an embodiment of the present application; Figure 3 A diagram of the overall processing architecture for executable and linkable file parsing provided according to an embodiment of the present application; Figure 4 A specific execution flow chart of the executable and linkable file parsing method provided according to an embodiment of the present application; Figure 5 A schematic diagram of an executable and linkable file parsing device provided according to an embodiment of the present application; Figure 6 A schematic diagram of the structure of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0013] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0014] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0015] Before describing the solution of this application, the relevant contents of this application are first introduced to assist in understanding the solution of this application.
[0016] ELF file is a common executable file format, widely used in Unix and Linux systems. It has a multi-layer data structure including file header (ELF Header), program header table (Program Header Table), section (Section), section header table (Section Header Table), symbol table, relocation table, etc. Each part is interrelated and has a complex structure.
[0017] There are three main types of ELF files: executable files, object files, and dynamic library files. Executable files are read from the hard disk by the loader in the operating system and loaded into memory for execution; object files are read by the linker to generate an executable file or dynamic library file; dynamic library files, when an executable file depends on certain dynamic libraries, are read by the interpreter when loading the executable file.
[0018] Related ELF file parsing methods typically use sequential reading and segment-by-segment parsing, which can lead to slow reading speeds, inability to fully utilize the advantages of multi-core CPUs, and significant I / O bottlenecks. When faced with batch parsing of large files or large numbers of ELF files, these methods often struggle to meet the requirements of high-speed parsing and real-time response, limiting system performance and response efficiency.
[0019] In addition, the parsing method for ELF files in the related art mainly includes: 1. Sequential parsing: that is, reading the ELF header, program header table, and section header table step by step, and then processing each section one by one.
[0020] 2. On-demand resolution of the dynamic linker: On-demand resolution of the dynamic linker is a delayed binding technology. Its core goal is to resolve only the necessary symbol addresses when the program is running, avoiding the performance loss caused by resolving all external symbols at once at startup.
[0021] 3. Static parsing: Tools such as readelf and objdump use static parsing of ELF files to extract features.
[0022] Although the sequential parsing method is intuitive, it is not efficient, especially when processing large files. Layer-by-layer parsing takes a significant amount of time, and frequent I / O operations lead to performance degradation. Dynamic linkers or debugging tools may need to access different parts of the same ELF file multiple times, and each time they need to be re-parsed, which consumes a lot of memory. The static parsing method uses a command line tool, and the output format is usually text, which is difficult to integrate into the application for processing.
[0023] To this end, the present application provides an executable and linkable file parsing to solve at least one of the above technical problems.
[0024] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0025] The embodiments of the present application provide an executable and linkable file parsing method, and the method is described in detail in conjunction with the execution process of the executable and linkable file parsing method.
[0026] like Figure 1 As shown, the executable and linkable file parsing method includes the following steps: In step S101 , in response to a parsing instruction of an executable and linkable file, a data structure of the executable and linkable file is identified, wherein the data structure includes multi-level data.
[0027] Among them, the executable and linkable files can be ELF files. ELF files are a common executable file format, widely used in Unix and Linux systems. There are three main types of ELF files, namely executable files, object files, and dynamic library files.
[0028] It is understandable that the embodiments of the present application can respond to parsing instructions of executable and linkable files and identify the data structures of the executable and linkable files so as to subsequently parse the executable and linkable files.
[0029] In some embodiments of the present application, the multi-level data includes a file header, a program header table, and section data.
[0030] It can be understood that the executable and linkable files of the embodiment of the present application include multi-level data, specifically a file header, a program header table and section data.
[0031] In step S102, whether multi-level data is stored in the multi-level cache is queried according to the data structure. If the current-level data is stored in the current-level cache, the parsing of the current-level data is skipped. If the current-level data is not stored in the current-level cache, the current-level data is loaded from the hard disk to the current-level cache.
[0032] Among them, the multi-level cache includes the first-level cache, the second-level cache and the third-level cache. Among them, the first-level cache is used to store the file header, the second-level cache is used to store the program header table, and the third-level cache is used to store the section data; the multi-level cache can be understood as an area in the memory that is divided out to store the file data of executable and linkable files.
[0033] It can be understood that the embodiment of the present application can query whether multi-level data of executable and linkable files are stored in the multi-level cache according to the data structure. If the current-level data is stored in the current-level cache, the parsing of the current-level data is skipped. If the current-level data is not stored in the current-level cache, the current-level data is loaded from the hard disk to the current-level cache, thereby realizing that when the data of executable and linkable files are stored in the multi-level cache, it is directly read from the multi-level cache without loading from the hard disk, avoiding repeated parsing, and improving the parsing efficiency of executable and linkable files.
[0034] For example, the current level data of the parsing process of executable and linkable files is the file header. If the file header of the executable and linkable files is stored in the first-level cache, the parsing of the file header is skipped. If the file header of the executable and linkable files is not stored in the first-level cache, the file header data is loaded from the hard disk to the first-level cache.
[0035] In step S103, the parsing results of the executable and linkable files are read from the multi-level cache.
[0036] It can be understood that the embodiments of the present application can read the parsing results of executable and linkable files from the multi-level cache, and store the multi-level data of the parsed executable and linkable files in the multi-level cache, so that the next time the executable and linkable files are parsed, there is no need for repeated parsing, thereby reducing memory usage, and thus improving the parsing efficiency of executable and linkable files, and there is no need to load the data of executable and linkable files from the hard disk through frequent I / O operations, thereby avoiding performance degradation of the operating system.
[0037] In some embodiments of the present application, before loading the current level data from the hard disk to the current level cache, it also includes: if the current level data is section data, identifying the section relationship in the section data; parsing the section data loaded from the hard disk according to the section relationship; and storing the parsed file of the section data to the third level cache.
[0038] Among them, the section relationship includes the first relationship and the second relationship. The first relationship indicates that there is a dependency relationship between sections, and the second relationship indicates that there is no dependency relationship between sections. For example, the sections with dependency relationships are the code reference chain (.text → .rodata), the symbol table chain (.symtab → .strtab), etc., and the sections without dependency relationships are .data, .bss, etc. Sections without dependency relationships can also be called independent sections.
[0039] It can be understood that before loading the current level data from the hard disk to the current level cache, the embodiment of the present application identifies the section relationship in the section data if the current level data is section data, loads the section data from the hard disk according to the section relationship for parsing, and stores the parsed file of the section data to the third-level cache, so that when the section data of the executable and linkable file is parsed again later, it can be read directly from the third-level cache, avoiding repeated parsing and improving parsing efficiency.
[0040] Specifically, the process of obtaining the section relationship in the embodiment of the present application includes: finding the program header table through the file header of the ELF file, and finding .Dynamic through the program header table, and the section relationship is stored in .Dynamic.
[0041] In some embodiments of the present application, the section data loaded from the hard disk is parsed according to the section relationship, including: assigning the sections of the first relationship to the target cores of the processor for sequential parsing; assigning the sections of the second relationship to different cores of the processor for parallel parsing.
[0042] The processor may be a multi-core central processing unit, and the target core may be an idle core.
[0043] It is understandable that the embodiment of the present application can assign the sections of the first relationship to the target core of the processor for sequential parsing, and assign the sections of the second relationship to different cores of the processor for parallel parsing, thereby improving the parsing speed of the sections.
[0044] Specifically, the embodiment of the present application can allocate independent sections without dependencies to different cores of a processor for parallel parsing, and allocate sections with dependencies to target cores of a processor for sequential parsing.
[0045] In some embodiments of the present application, before allocating the sections of the first relationship to the target cores of the processor for sequential parsing, it also includes: obtaining the load rates of multiple cores on the processor; calculating the idle rates of the cores based on the load rates of the multiple cores; and determining the target core from the multiple cores based on the idle rates.
[0046] It can be understood that the embodiment of the present application can calculate the idle rate of each core based on the load rate of each core on the processor, and then determine the target core from multiple cores based on the idle rate, so as to select a core with the highest idle rate as the target core, and parse the independent section with the target core to improve the parsing speed.
[0047] In some embodiments of the present application, the parsed file of the section data is stored in the third-level cache, including: obtaining the system's free memory and the size of the parsed file; setting a preloading threshold according to the size of the parsed file, if the free memory is less than the preloading threshold, the parsed file of the section data is stored in the third-level cache; if the free memory is greater than or equal to the preloading threshold, part of the parsed file is preloaded into the third-level cache.
[0048] The preloading threshold is set according to the parsing, and is not specifically limited thereto. It can be set to a multiple of the size of the parsed file, such as 3 or 4 times the size.
[0049] It can be understood that, in the embodiment of the present application, when the free memory is less than the preloading threshold, it indicates that the memory space is relatively tight at this time, and the parsed file of the section data is stored in the third-level cache without preloading. When the free memory is greater than or equal to the preloading threshold, it indicates that there is more space in the system memory at this time, and part of the parsed file is preloaded into the third-level cache for direct use in subsequent executable and linkable file parsing, thereby reducing the waiting time for subsequent executable and linkable file parsing.
[0050] In some embodiments of the present application, part of the parsed file is preloaded into the third-level cache, including: determining a target preloading method based on the size of the parsed file; and loading part of the parsed file into the third-level cache according to the target preloading method.
[0051] It is understandable that the embodiment of the present application can determine the target preloading method according to the size of the parsed file, and load part of the parsed file into the third-level cache according to the target loading method.
[0052] In addition, it should be noted that the system memory in the embodiment of the present application refers to the operating system, that is, the computer system, and the memory refers to the actual physical memory, that is, the random access memory.
[0053] In some embodiments of the present application, the target preloading mode is determined according to the size of the parsed file, including: if the size of the parsed file is greater than or equal to the first preset threshold, the target preloading mode is the first preloading mode; if the size of the parsed file is greater than the second preset threshold and less than the first preset threshold, the target preloading mode is the second preloading mode; if the size of the parsed file is less than or equal to the second preset threshold, the target preloading mode is the third preloading mode.
[0054] Among them, the first preset threshold and the second preset threshold can be set according to the specific situation, and there is no specific limitation on this. For example, the first preset threshold can be set to 10MB, and the second preset threshold can be set to 1MB; the first preloading method can load the first 30% of the content of the parsed file, the second preloading method can load the first 60% of the content of the parsed file, and the third preloading method can load all the content of the parsed file.
[0055] It is understandable that the embodiment of the present application can determine the target preload file based on the size of the parsed file, including: If the size of the parsed file is greater than or equal to the first preset threshold, the target preloading mode is the first preloading mode; If the size of the parsed file is greater than the second preset threshold and less than the first preset threshold, the target preloading mode is the second preloading mode; If the size of the parsed file is less than or equal to the second preset threshold, the target preloading mode is the third preloading mode.
[0056] For example, taking the first preset threshold as 10MB and the second preset threshold as 1MB as an example, the embodiment of the present application may not preload if the free memory is less than three times the file size, that is, the L3 section data cache is not updated; if the free memory is greater than three times the file size and the file is greater than 10MB, a small amount of preloading is performed, that is, the first 30% of the parsed file content is updated to the L3 cache; if the free memory is greater than three times the file size and the file is between 1MB and 10MB, medium preloading is performed, that is, the first 60% of the parsed file content is updated to the L3 cache; if the free memory is greater than three times the file size and the file is less than 1MB, full preloading is performed, that is, the entire parsed file content is loaded.
[0057] In some embodiments of the present application, after preloading part of the files in the parsed file into the third-level cache, it also includes: obtaining the cache hit rate in the third-level cache; if the cache hit rate is less than the hit rate threshold, increasing the size of the part of the files in the parsed file stored in the third-level cache.
[0058] Among them, the hit rate threshold can be set according to the specific situation, such as 60% or 70%; the cache hit rate is the probability that the executable and linkable files can query the section in the third-level cache, which can be calculated by the number of cache misses cache_misses and the total number of accesses total_accesses. The calculation formula is cache hit rate = (total_accesses - cache_misses) / total_accesses * 100%.
[0059] It can be understood that the embodiment of the present application can obtain the cache hit rate in the third-level cache; if the cache hit rate is less than the hit rate threshold, the size of some of the parsed files stored in the third-level cache is increased to optimize the use of subsequent caches and thereby optimize the parsing efficiency.
[0060] This article uses the parsing of a 20MB large executable file (large_app.exe) as an example to illustrate the cache hit rate calculation process and how to optimize the size of some files in the parsed files stored in the third-level cache.
[0061] 1. Initial preloading and hit rate calculation.
[0062] The file size is 20MB, the L3 cache free memory is 70MB (>3×20MB=60MB), and a small amount of preloading is performed according to the rules (the first 30% of the core sections .text and .data, about 6MB).
[0063] 2. After the first parsing, count 100 L3 cache accesses.
[0064] total_accesses = 100, cache_misses = 50 (50 accesses to section data that were not within the 30% preload range).
[0065] Cache hit rate = (100-50) / 100×100% = 50%, which is lower than the hit rate threshold of 60%.
[0066] 3. Since the cache hit rate is 50% < 60%, the preload range is increased from 30% to 50% (20% of the core section content is added, the total preload amount is about 10MB, which is still less than the L3 cache capacity of 8MB. 30%~40% of the core section content is added to the L3 cache, and the total preload amount is 8MB).
[0067] 4. Calculate the cache hit rate again.
[0068] Count 100 L3 cache accesses again: total_accesses = 200 (cumulative), cache_misses = 60 (only 10 misses among the new accesses).
[0069] Cache hit rate = (200-60) / 200×100% = 70%, reaching the threshold of 60%, and optimization stops.
[0070] In some embodiments of the present application, before preloading part of the parsed file into the third-level cache, it also includes: obtaining the file type of the executable and linkable files; determining the preload section according to the file type, and preloading part of the parsed file in the preload section into the third-level cache.
[0071] Among them, file types include executable files, target files, dynamic library files, etc.
[0072] Since different types of executable and linkable files may require different sections to be parsed, the embodiment of the present application can obtain the file type of the executable and linkable files, and determine the preload section based on the file type, and preload part of the parsed file of the preload section into the third-level cache, thereby accurately determining the preload section based on the file type, thereby improving the hit rate of the subsequent third-level cache and improving the parsing speed.
[0073] For example, the preload section of the executable file can be set to .text, .data, and .init_array; the core preload section of the target file can be set to .symtab, .text, and .strtab.
[0074] In addition, it should be noted that the solution of the embodiment of the present application can be integrated into the application for processing.
[0075] Based on the above-mentioned executable and linkable file parsing method, the embodiment of the present application also provides an executable and linkable file parsing system, the structure of which is as follows: Figure 2 As shown, it includes: ELF file input module, parallel parsing module, preloading module, dynamic adjustment module and result output module.
[0076] Among them, the ELF file input module is used to input ELF files from the system; the multi-level cache module includes a first-level cache, a second-level cache, and a third-level cache to reduce the overhead of repeated parsing; The parallel parsing module divides the ELF file parsing task into multiple subtasks and uses the advantages of multi-core processors to parse each subtask in parallel, thereby improving the overall parsing speed; Preloading module predicts and preloads segments and sections that may be accessed, reducing waiting time; Dynamic adjustment module monitors system performance in real time and dynamically adjusts cache size based on monitoring data to optimize parsing efficiency; The result output module stores the parsing results in a database or file system for subsequent use.
[0077] Based on the above executable and linkable file parsing system, the embodiment of the present application also provides an overall processing architecture diagram for executable and linkable file parsing, such as Figure 3 As shown, it includes an ELF file storage device, a multi-core processor device, a system memory device, a fast parsing device and a parsing result storage device.
[0078] Specifically, the executable and linkable file parsing method of the embodiment of the present application has the following specific process: Figure 4 As shown, the following steps are included: Step 1: Create and initialize L1 (first level cache), L2 (second level cache), and L3 (third level cache) cache.
[0079] Set the L1 cache to 32KB for storing ELF file headers; set the L2 cache to 256KB for storing program header tables; set the L3 cache to 8MB for storing section data.
[0080] Step 2: Input the ELF file.
[0081] That is, input an ELF file and start the fast parsing process of the ELF file.
[0082] Step 3: L1 cache check.
[0083] Check whether the header of the ELF file is in the L1 cache. If not, load the header of the ELF file from the disk into the L1 cache; otherwise, proceed to step 4.
[0084] Step 4: L2 cache check.
[0085] Check whether the program header table of the ELF file is in the L2 cache. If not, load the program header table of the ELF file from the disk into the L2 cache; otherwise, proceed to step 5.
[0086] Step 5: L3 cache check.
[0087] Check whether the section data of the ELF file is in the L3 cache. If so, read the section data from the L3 cache; if not, proceed to step 6.
[0088] Step 6: Build section dependencies.
[0089] After parsing the ELF header, identify dependencies between sections. For example, dependent sections include the code reference chain (.text → .rodata), the symbol table chain (.symtab → .strtab), and independent sections include .data and .bss.
[0090] Step 7: Task group division and analysis.
[0091] Assign independent sections without dependencies to different CPU cores for parallel parsing; assign sections with dependencies to an idle CPU core for sequential parsing.
[0092] Step 8: Get the file type and determine the preload section.
[0093] For example, the core preload section of the executable file is set to .text, .data, and .init_array; the core preload section of the target file is set to .symtab, .text, and .strtab.
[0094] Step 9: Get the free memory size and file size.
[0095] If the free memory is less than three times the file size, no preloading is performed, that is, the L3 section data cache is not updated; if the free memory is greater than three times the file size and the file is greater than 10MB, a small preloading is performed, that is, the first 30% of the core section content is updated to the L3 cache; if the free memory is greater than three times the file size and the file is between 1M and 10MB, a medium preloading is performed, that is, the first 60% of the core section content is updated to the L3 cache; if the free memory is greater than three times the file size and the file is less than 1MB, a full preloading is performed, that is, the entire core section content is loaded.
[0096] Step 11: Determine the cache hit rate.
[0097] The cache hit rate is (total_accesses - cache_misses) / total_accesses * 100%. If the cache hit rate is too low, you can increase the size of the L3 cache appropriately.
[0098] In summary, the above method aims to improve the parsing efficiency of ELF files, particularly in embedded systems and large-scale software analysis scenarios. By introducing a multi-level caching mechanism, parallel parsing technology, and an intelligent preloading strategy, this method significantly reduces the time and resource consumption of ELF file parsing. Furthermore, the system provides the ability to dynamically adjust the parsing strategy to adapt to different hardware environments and application requirements.
[0099] The following describes the executable and linkable file parsing method of the embodiment of the present application through a specific embodiment, taking the parsing of a 5MB ELF file as an example.
[0100] Step 1: Initialize the cache.
[0101] L1 cache: 32KB, dedicated to storing ELF file headers (usually the ELF file header size is 64 bytes to 128 bytes, 32KB is completely sufficient); L2 cache: 256KB, used to store the program header table (the program header table of a 5MB executable file is usually no more than 10KB, and 256KB is sufficient redundancy); L3 cache: 8MB, used to store section data (such as .text, .data, etc.). The total section data of a 5MB file is approximately 4.8MB.
[0102] Step 2: Input ELF file.
[0103] The user triggers the parsing command, the target file is app.exe (executable file, size 5MB), and the system starts the fast parsing process.
[0104] Step 3: L1 cache check.
[0105] Check whether the ELF file header of app.exe exists in the L1 cache: If the cache does not hit during the first parsing, the ELF file header (64 bytes) of app.exe is loaded from the disk into the L1 cache.
[0106] Step 4: L2 cache check.
[0107] Check whether the program header table of app.exe exists in the L2 cache: If the cache does not hit during the first parsing, the program header table (containing 8 program segment descriptions, a total of 8×56 bytes = 448 bytes) is loaded from the disk to the L2 cache.
[0108] Step 5: L3 cache check.
[0109] Check if the section data of app.exe exists in the L3 cache: first parsing, cache miss; Update statistics: total_accesses = 1 (this L3 access), cache_misses = 1 (misses).
[0110] Step 6: Construct section dependency data.
[0111] After parsing the ELF header and program header table, identify section dependencies.
[0112] Dependent sections: .text (code segment) → .rodata (read-only data, constants referenced in the code); .symtab (symbol table) → .strtab (string table, storing symbol names); Independent sections: .data (initialized data), .bss (uninitialized data), .init_array (initialization function array).
[0113] Step 7: Task group division and analysis.
[0114] Parallel parsing task: Allocate independent sections .data and .bss to CPU core 1 and core 2, and parse their data formats (such as variable initialization values in .data and the size of .bss) at the same time.
[0115] Sequential parsing task: Assign the dependency chains .text→.rodata and .symtab→.strtab to CPU core 3. Parse .text first, then .rodata. After that, parse .symtab and then .strtab.
[0116] Step 8: Determine the preload section.
[0117] Because app.exe is an executable file, according to the rules, the core preload sections are: .text (code), .data (data), and .init_array (initialization function).
[0118] Step 9: Get resource information.
[0119] The size of app.exe is 5MB, and the current L3 cache free space is 20MB (which is 3 times the file size, 5MB × 3 = 15MB, meeting the preloading conditions).
[0120] Step 10: Update the L3 cache.
[0121] Because "free memory (20MB) > 3 × file size (15MB)" and "file size (5MB) is between 1MB and 10MB", medium preloading is performed.
[0122] Load the first 60% of the contents of the core sections .text, .data, and .init_array into the L3 cache (the total preloaded amount is approximately 5MB×60%=3MB, which is much smaller than the L3 capacity of 8MB).
[0123] Step 11: Determine the cache hit rate.
[0124] After the first parse, total_accesses = 1, cache_misses = 1, and the hit rate is (1-1) / 1×100% = 0%. Because the first parse will inevitably miss, the L3 cache size is not adjusted for now (8MB already meets the 5MB file requirement).
[0125] When app.exe is parsed again, the L1 cache directly hits the ELF file header and the L2 cache directly hits the program header table, without requiring disk I / O. 60% of the core section data is already in the L3 cache. If the accessed section is within the preload range, the cache hits, total_accesses increases, but cache_misses remains unchanged, significantly improving the hit rate.
[0126] According to the executable and linkable file parsing method proposed in the embodiment of the present application, the data structure of the executable and linkable files can be identified, and whether multi-level data is stored in the multi-level cache based on the data structure is queried. When the current-level data is stored in the current-level cache, the parsing of the current-level data is skipped, and the executable and linkable file results are directly obtained from the cache. If the current-level data is not stored in the current-level cache, the current-level data is loaded from the hard disk to the current-level cache. By storing the parsed multi-level data of the executable and linkable files in the multi-level cache, it is possible to parse the same executable and linkable files without repeated parsing, thereby reducing memory usage and improving the parsing efficiency of the executable and linkable files. There is no need to load the data of the executable and linkable files from the hard disk through frequent I / O operations, thereby avoiding affecting the performance of the operating system.
[0127] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0128] The embodiments of the present application also provide an executable and linkable file parsing device.
[0129] Figure 5 A schematic diagram of an executable and linkable file parsing device provided according to an embodiment of the present application.
[0130] like Figure 5 As shown, the executable and linkable file parsing device 10 includes: a response module 100 , a query module 200 and a reading module 300 .
[0131] Among them, the response module 100 is used to respond to the parsing instructions of executable and linkable files, and identify the data structure of executable and linkable files, wherein the data structure includes multi-level data; the query module 200 is used to query whether multi-level data is stored in the multi-level cache according to the data structure. If the current level data is stored in the current level cache, the parsing of the current level data is skipped; if the current level data is not stored in the current level cache, the current level data is loaded from the hard disk to the current level cache; the reading module 300 is used to read the parsing results of executable and linkable files from the multi-level cache.
[0132] In some embodiments of the present application, multi-level data includes file headers, program header tables and section data, and multi-level cache includes first-level cache, second-level cache and third-level cache, wherein the first-level cache is used to store file headers, the second-level cache is used to store program header tables, and the third-level cache is used to store section data.
[0133] In some embodiments of the present application, the executable and linkable file parsing device 10 of the present application further includes: a parsing module.
[0134] Among them, the parsing module is used to identify the section relationship in the section data before loading the current level data from the hard disk to the current level cache, if the current level data is section data; parse the section data loaded from the hard disk according to the section relationship; and store the parsed file of the section data to the third-level cache.
[0135] In some embodiments of the present application, the section relationship includes a first relationship and a second relationship, the first relationship indicates that there is a dependency relationship between the sections, and the second relationship indicates that there is no dependency relationship between the sections.
[0136] In some embodiments of the present application, the parsing module is further configured to: allocate the sections of the first relationship to the target cores of the processor for sequential parsing; and allocate the sections of the second relationship to different cores of the processor for parallel parsing.
[0137] In some embodiments of the present application, the executable and linkable file parsing device 10 of the present application further includes: a computing module.
[0138] Among them, the calculation module is used to obtain the load rate of multiple cores on the processor before allocating the sections of the first relationship to the target cores of the processor for sequential parsing; calculate the idle rate of the cores based on the load rate of the multiple cores; and determine the target core from the multiple cores based on the idle rate.
[0139] In some embodiments of the present application, the parsing module is further used to: obtain the system's free memory and the size of the parsed file; set a preloading threshold based on the size of the parsed file, and if the free memory is less than the preloading threshold, store the parsed file of the section data in the third-level cache; if the free memory is greater than or equal to the preloading threshold, preload part of the parsed file into the third-level cache.
[0140] In some embodiments of the present application, the parsing module is further used to: determine a target preloading method based on the size of the parsed file; and load part of the parsed file into the third-level cache according to the target preloading method.
[0141] In some embodiments of the present application, the parsing module is further used to: if the size of the parsed file is greater than or equal to a first preset threshold, the target preloading mode is the first preloading mode; if the size of the parsed file is greater than a second preset threshold and less than the first preset threshold, the target preloading mode is the second preloading mode; if the size of the parsed file is less than or equal to the second preset threshold, the target preloading mode is the third preloading mode.
[0142] In some embodiments of the present application, the executable and linkable file parsing device 10 of the embodiment of the present application further includes: an adding module.
[0143] Among them, the adding module is used to obtain the cache hit rate in the third-level cache after preloading part of the files in the parsed file into the third-level cache; if the cache hit rate is less than the hit rate threshold, the size of part of the files in the parsed file stored in the third-level cache is increased.
[0144] It should be noted that, for the description of the features in the embodiment corresponding to the executable and linkable file parsing apparatus, reference can be made to the relevant description of the embodiment corresponding to the executable and linkable file parsing method, which will not be repeated here.
[0145] According to the executable and linkable file parsing device proposed in the embodiment of the present application, the data structure of the executable and linkable files can be identified, and whether multi-level data is stored in the multi-level cache based on the data structure is queried. When the current-level data is stored in the current-level cache, the parsing of the current-level data is skipped, and the executable and linkable file results are directly obtained from the cache. If the current-level data is not stored in the current-level cache, the current-level data is loaded from the hard disk to the current-level cache. By storing the parsed multi-level data of the executable and linkable files in the multi-level cache, it is possible to parse the same executable and linkable files without repeated parsing, thereby reducing memory usage and improving the parsing efficiency of the executable and linkable files. There is no need to load the data of the executable and linkable files from the hard disk through frequent I / O operations, thereby avoiding affecting the performance of the operating system.
[0146] An embodiment of the present application also provides an electronic device.
[0147] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device may include: A memory 601 , a processor 602 , and a computer program stored in the memory 601 and executable on the processor 602 .
[0148] When the processor 602 executes the program, the executable and linkable file parsing method provided in the above embodiment is implemented.
[0149] Furthermore, the electronic device further includes: The communication interface 603 is used for communication between the memory 601 and the processor 602 .
[0150] The memory 601 is used to store computer programs that can be run on the processor 602 .
[0151] The memory 601 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0152] If the memory 601, processor 602, and communication interface 603 are implemented independently, the communication interface 603, memory 601, and processor 602 can be interconnected via a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0153] Optionally, in a specific implementation, if the memory 601, the processor 602 and the communication interface 603 are integrated on a chip, the memory 601, the processor 602 and the communication interface 603 can communicate with each other through an internal interface.
[0154] The processor 602 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0155] An embodiment of the present application further provides a non-volatile computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned executable and linkable file parsing method embodiments when running.
[0156] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0157] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of any one of the above-mentioned executable and linkable file parsing method embodiments are implemented.
[0158] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0159] The above is a detailed introduction to an executable and linkable file parsing method and electronic device provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A method for parsing executable and linkable files, characterized in that: The following steps are involved: In response to a parsing instruction of an executable and linkable file, identifying a data structure of the executable and linkable file, wherein the data structure includes multiple levels of data; querying whether the multi-level data is stored in the multi-level cache according to the data structure, skipping parsing of the current-level data if the current-level data is stored in the current-level cache, and loading the current-level data from the hard disk into the current-level cache if the current-level data is not stored in the current-level cache; The parsing results of the executable and linkable files are read from the multi-level cache.
2. The executable and linkable file parsing method according to claim 1, wherein: The multi-level data includes a file header, a program header table and section data, and the multi-level cache includes a first-level cache, a second-level cache and a third-level cache, wherein the first-level cache is used to store the file header, the second-level cache is used to store the program header table, and the third-level cache is used to store the section data.
3. The executable and linkable file parsing method according to claim 2, characterized in that: Before loading the current-level data from the hard disk into the current-level cache, the method further includes: If the current level data is the section data, identifying the section relationship in the section data; parsing the section data loaded from the hard disk according to the section relationship; The parsed file of the section data is stored in the third-level cache.
4. The executable and linkable file parsing method according to claim 3, characterized in that: The section relationship includes a first relationship and a second relationship, wherein the first relationship indicates that there is a dependency relationship between sections, and the second relationship indicates that there is no dependency relationship between sections. Parsing the section data loaded from the hard disk according to the section relationship includes: Allocating the sections of the first relationship to the target cores of the processor for sequential parsing; The sections of the second relation are distributed to different cores of a processor for parallel parsing.
5. The executable and linkable file parsing method according to claim 4, characterized in that: Before allocating the sections of the first relationship to the target cores of the processor for sequential parsing, the method further includes: Obtaining load rates of multiple cores on the processor; Calculating a core idle rate according to the load rates of the plurality of cores; The target core is determined from the plurality of cores according to the idle rate.
6. The executable and linkable file parsing method according to claim 3, characterized in that: Storing the parsed file of the section data in the third-level cache includes: Obtaining the free memory of the system and the size of the parsed file; Setting a preloading threshold according to the size of the parsed file, and storing the parsed file of the section data in the third-level cache if the free memory is less than the preloading threshold; If the free memory is greater than or equal to the preloading threshold, a portion of the parsed files is preloaded into the third-level cache.
7. The executable and linkable file parsing method according to claim 6, characterized in that: The preloading of part of the parsed file into the third-level cache includes: Determining a target preloading mode according to the size of the parsed file; Load part of the parsed files into the third-level cache according to the target preloading method.
8. The executable and linkable file parsing method according to claim 6, wherein: The determining of the target preloading mode according to the size of the parsed file includes: If the size of the parsed file is greater than or equal to a first preset threshold, the target preloading mode is the first preloading mode; If the size of the parsed file is greater than the second preset threshold and less than the first preset threshold, the target preloading mode is the second preloading mode; If the size of the parsed file is less than or equal to a second preset threshold, the target preloading mode is the third preloading mode.
9. The executable and linkable file parsing method according to claim 6, wherein: After preloading some files in the parsed file into the third-level cache, the method further includes: Obtaining a cache hit rate in the third-level cache; If the cache hit rate is less than the hit rate threshold, the size of some of the parsed files stored in the third-level cache is increased.
10. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the executable and linkable file parsing method according to any one of claims 1 to 9 when executing the computer program.
Citation Information
Patent Citations
Code caching system
CN107408055A
Memory execution method and device for ELF file under Linux, equipment and storage medium
CN115794244A
Function positioning method and device in instruction cache, equipment and medium
CN117033260A
File processing method and device and computer equipment
CN119645534A
Extensible command line parsing
US20050289525A1