Executable and linkable file parsing methods and electronic devices
By optimizing ELF file parsing through multi-level caching and parallel parsing techniques, the inefficiency of existing technologies is solved, achieving high-efficiency ELF file parsing suitable for Unix and Linux systems.
Patent Information
- Application Number
- CN202511203667.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-26
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2045-08-26
AI Technical Summary
Existing ELF file parsing methods are inefficient, especially when parsing large files or batches of large files. They cannot fully utilize the advantages of multi-core CPUs, resulting in I/O bottlenecks and a decline in system performance.
Employing a multi-level caching mechanism and parallel parsing technology, this approach identifies the data structure of ELF files, utilizes multi-level caching to store parsed data, skips redundant parsing, combines multi-core processors to parse dependent sections in parallel, and employs an intelligent preloading strategy to optimize cache usage.
It improves ELF file parsing efficiency, reduces redundant parsing and frequent I/O operations, lowers memory usage, avoids operating system performance degradation, and adapts to different hardware environments and application requirements.
Smart Images

Figure CN120723339B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an executable and linkable file parsing method and electronic device. Background Technology
[0002] ELF (Executable and Linkable Format) files are a common executable file format widely used in Unix and Linux systems. They have a multi-layered data structure with interconnected parts, making them complex.
[0003] ELF file parsing methods in related technologies typically employ sequential reading and segment-by-segment parsing. This approach is inefficient when dealing with large files or batch parsing of a large number of ELF files. Furthermore, when accessing the same part of the same ELF file multiple times, the parsing process is repeated, resulting in low ELF file parsing efficiency. Summary of the Invention
[0004] This application provides a method for parsing executable and linkable files, which at least solves the problem of low parsing efficiency for executable and linkable files in related technologies.
[0005] This application provides a method for parsing executable and linkable files, comprising the following steps: responding to a parsing instruction for an executable and linkable file, identifying the data structure of the executable and linkable file, wherein the data structure includes multi-level data; querying whether multi-level data is stored in the multi-level cache according to the data structure; if the current-level cache stores the current-level data, skipping the parsing of the current-level data; if the current-level cache does not store the current-level data, loading the current-level data from the hard disk into the current-level cache; and reading the parsing result of the executable and linkable file from the multi-level cache.
[0006] This application also provides an executable and linkable file parsing apparatus, comprising: a response module, configured to respond to parsing instructions for 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, configured to query whether multi-level data is stored in the multi-level cache according to the data structure; if the current-level cache stores the current-level data, the parsing of the current-level data is skipped; if the current-level cache does not store the current-level data, the current-level data is loaded from the hard disk into the current-level cache; and a reading module, configured to read the parsing results of the executable and linkable files from the multi-level cache.
[0007] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the steps of any of the above-described executable and linkable file parsing methods when executing the computer program.
[0008] This application also provides a non-volatile computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the above-described executable and linkable file parsing methods.
[0009] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described executable and linkable file parsing methods.
[0010] This application identifies the data structure of executable and linkable files, queries the multi-level cache to determine if multi-level data is stored, and skips the parsing of the current-level data in the current-level cache, directly retrieving the executable and linkable file results 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 into the current-level cache. By storing the parsed multi-level data of executable and linkable files in the multi-level cache, repeated parsing of the same executable and linkable files is avoided, reducing memory usage and improving the parsing efficiency of executable and linkable files. Furthermore, it avoids frequent I / O (Input / Output) operations to load executable and linkable file data from the hard disk, thus preventing impact on operating system performance. Therefore, it solves the problem of low parsing efficiency for executable and linkable files in related technologies, achieving the technical effect of improving parsing efficiency. Attached Figure Description
[0011] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of an executable and linkable file parsing method provided according to an embodiment of this application;
[0013] Figure 2 This is a structural diagram of the executable and linkable file parsing system provided according to an embodiment of this application;
[0014] Figure 3 This is a diagram illustrating the overall processing architecture for parsing executable and linkable files according to embodiments of this application.
[0015] Figure 4 This is a flowchart illustrating the specific execution process of the executable and linkable file parsing method provided in the embodiments of this application.
[0016] Figure 5 This is a schematic diagram of an executable and linkable file parsing apparatus provided according to an embodiment of this application;
[0017] Figure 6 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0019] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0020] Before describing the solution of this application, the relevant content of this application will be introduced to aid in understanding the solution of this application.
[0021] ELF files are a common executable file format widely used in Unix and Linux systems. They have a multi-layered data structure, including an ELF header, a program header table, sections, section header tables, a symbol table, and a relocation table. These parts are interconnected and have a complex structure.
[0022] There are three main types of ELF files: executable files, object files, and dynamic library files. Executable files are read from the hard drive by the operating system's loader and loaded into memory for execution; object files are read by the linker to generate an executable file or a dynamic library file; and dynamic library files are read by the interpreter when the executable file depends on certain dynamic libraries.
[0023] ELF file parsing methods in related technologies typically employ sequential reading and segment-by-segment parsing, which suffers from slow reading speeds, inability to fully utilize the advantages of multi-core CPUs, and significant I / O bottlenecks. When faced with large files or batch parsing tasks involving a large number of ELF files, these methods often fail to meet the requirements for high-speed parsing and real-time response, thus limiting system performance and response efficiency.
[0024] In addition, the main methods for parsing ELF files in related technologies include:
[0025] 1. Sequential parsing: This means reading the ELF header, program header table, and section header table step by step, and then processing each section one by one.
[0026] 2. On-demand resolution of dynamic linkers: On-demand resolution of dynamic linkers is a lazy binding technique. Its core goal is to resolve only the necessary symbol addresses at runtime, avoiding the performance loss caused by resolving all external symbols at once at startup.
[0027] 3. Static parsing: Tools such as readelf and objdump use static parsing of ELF files to extract features.
[0028] While sequential parsing is intuitive, it is inefficient, especially when processing large files. Parsing layer by layer is time-consuming, and frequent I / O operations can lead to performance degradation. Dynamic linkers or debugging tools may need to access different parts of the same ELF file multiple times, requiring re-parsing each time, resulting in high memory consumption. Static parsing methods use command-line tools, and the output format is usually text, making it difficult to integrate into applications for processing.
[0029] To address this, this application provides an executable and linkable file parser to resolve at least one of the above-mentioned technical problems.
[0030] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0031] The embodiments of this application provide a method for parsing executable and linkable files. The method is described in detail below, taking into account the execution flow of the executable and linkable file parsing method.
[0032] like Figure 1 As shown, this executable and linkable file parsing method includes the following steps:
[0033] In step S101, in response to the parsing instructions of executable and linkable files, the data structure of executable and linkable files is identified, wherein the data structure includes multi-level data.
[0034] Among them, 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: executable files, object files, and dynamic library files.
[0035] It is understood that the embodiments of this application can respond to the parsing instructions of executable and linkable files and identify the data structure of executable and linkable files so as to parse the executable and linkable files subsequently.
[0036] In some embodiments of this application, multi-level data includes a file header, a program header table, and section data.
[0037] It is understood that the executable and linkable files in the embodiments of this application include multi-level data, specifically a file header, a program header table, and section data.
[0038] In step S102, the multi-level cache is queried according to the data structure to see if multi-level data is stored. If the current level cache stores the current level data, the parsing of the current level data is skipped. If the current level cache does not store the current level data, the current level data is loaded from the hard disk into the current level cache.
[0039] The multi-level cache includes a first-level cache, a second-level cache, and a third-level cache. 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 section data. The multi-level cache can be understood as a region in memory that is allocated to store the file data of executable and linkable files.
[0040] It is understood that the embodiments of this application can query whether the multi-level cache contains multi-level data of executable and linkable files according to the data structure. If the current level cache contains the current level data, the parsing of the current level data is skipped. If the current level cache does not contain the current level data, the current level data is loaded from the hard disk into the current level cache. This enables the direct reading from the multi-level cache when the multi-level cache contains the data of executable and linkable files, without loading from the hard disk, avoiding repeated parsing and improving the parsing efficiency of executable and linkable files.
[0041] For example, the current level data in the parsing process of executable and linkable files is the file header. If the file header of the executable and linkable file is stored in the first level cache, the parsing of the file header is skipped. If the file header of the executable and linkable file is not stored in the first level cache, the file header data is loaded from the hard disk into the first level cache.
[0042] In step S103, the parsing results of executable and linkable files are read from the multi-level cache.
[0043] It is understood that the embodiments of this application can read the parsing results of executable and linkable files from a multi-level cache. By storing the multi-level data of the parsed executable and linkable files in the multi-level cache, the next parsing of executable and linkable files does not require repeated parsing, thereby reducing memory usage and improving the parsing efficiency of executable and linkable files. Furthermore, it avoids loading the data of executable and linkable files from the hard disk through frequent I / O operations, thus preventing a decline in operating system performance.
[0044] In some embodiments of this application, 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 segment data, identifying the segment relationships in the segment data; parsing the segment data loaded from the hard disk according to the segment relationships; and storing the parsed file of the segment data into the third-level cache.
[0045] The section relationships include first relationships and second relationships. First relationships indicate that there are dependencies between sections, while second relationships indicate that there are no dependencies between sections. For example, sections with dependencies are code reference chains (.text → .rodata), symbol table chains (.symtab → .strtab), etc., while sections without dependencies are .data, .bss, etc. Sections without dependencies can also be called independent sections.
[0046] It is understood that, in this embodiment of the application, before loading the current-level data from the hard disk into the current-level cache, if the current-level data is section data, the section relationship in the section data is identified, the section data is loaded from the hard disk according to the section relationship, parsed, and the parsed file of the section data is stored in the third-level cache, so that when the section data of the executable and linkable file is parsed again in the future, it can be read directly from the third-level cache, avoiding repeated parsing and improving parsing efficiency.
[0047] Specifically, the process of obtaining the section relationship in this application embodiment includes: finding the program header table through the ELF file header, finding .Dynamic through the program header table, and storing the section relationship in .Dynamic.
[0048] In some embodiments of this application, parsing the segment data loaded from the hard disk according to the segment relationship includes: sequentially parsing the segments of the first relationship to the target cores of the processor; and parsing the segments of the second relationship to different cores of the processor in parallel.
[0049] The processor can be a multi-core central processing unit, and the target core can be an idle core.
[0050] It is understood that, in the embodiments of this application, the sections of the first relation can be allocated to the target core of the processor for sequential parsing, and the sections of the second relation can be allocated to different cores of the processor for parallel parsing, thereby improving the parsing speed of the sections.
[0051] Specifically, in this application embodiment, independent sections without dependencies can be assigned to different cores of the processor for parallel parsing, while dependent sections can be assigned to the target core of the processor for sequential parsing.
[0052] In some embodiments of this application, before allocating the section of the first relation to the target core of the processor in sequence, the method further includes: obtaining the load rate of multiple cores on the processor; calculating the idle rate of the cores based on the load rate of the multiple cores; and determining the target core from the multiple cores based on the idle rate.
[0053] It is understood that, in the embodiments of this application, the idle rate of each core can be calculated based on the load rate of each core on the processor, and then the target core can be determined from multiple cores based on the idle rate, so as to select the core with the highest idle rate as the target core, and the independent section is parsed by the target core to improve the parsing speed.
[0054] In some embodiments of this application, storing the parsed file of the segment data to the third-level cache includes: obtaining the system's free memory and the size of the parsed file; setting a preloading threshold based on the size of the parsed file; if the free memory is less than the preloading threshold, storing the parsed file of the segment data to the third-level cache; if the free memory is greater than or equal to the preloading threshold, preloading a portion of the parsed file to the third-level cache.
[0055] The preloading threshold is set according to the parsing settings and is not specifically limited. It can be set to a multiple of the parsed file size, such as 3 or 4 times the size.
[0056] It is understood that in this embodiment of the application, when the free memory is less than the preloading threshold, it indicates that the memory space is relatively tight. Therefore, 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 the system memory has more space. Therefore, some files in the parsed file are preloaded into the third-level cache so that they can be directly used for subsequent parsing of executable and linkable files, thereby reducing the parsing waiting time of subsequent executable and linkable files.
[0057] In some embodiments of this application, preloading a portion of the parsed file into the third-level cache includes: determining a target preloading method based on the size of the parsed file; and loading a portion of the parsed file into the third-level cache according to the target preloading method.
[0058] It is understood that, in this embodiment of the application, the target preloading method can be determined based on the size of the parsed file, and a portion of the parsed file can be loaded into the third-level cache according to the target loading method.
[0059] In addition, it should be noted that the "system" in the system memory of this application embodiment refers to the operating system, that is, the computer system, and the "memory" refers to the actual physical memory, that is, random access memory.
[0060] In some embodiments of this application, determining the target preloading method based on 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 method is a first preloading method; if the size of the parsed file is greater than a second preset threshold and less than the first preset threshold, the target preloading method is a second preloading method; if the size of the parsed file is less than or equal to the second preset threshold, the target preloading method is a third preloading method.
[0061] The first and second preset thresholds can be set according to specific circumstances, without any specific limitations. 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 parsed file, the second preloading method can load the first 60% of the parsed file, and the third preloading method can load the entire parsed file.
[0062] It is understood that embodiments of this application can determine the target preload file based on the size of the parsed file, including:
[0063] If the size of the parsed file is greater than or equal to the first preset threshold, then the target preloading method is the first preloading method;
[0064] If the size of the parsed file is greater than the second preset threshold but less than the first preset threshold, then the target preloading method is the second preloading method;
[0065] If the size of the parsed file is less than or equal to the second preset threshold, the target preloading method is the third preloading method.
[0066] For example, taking a first preset threshold of 10MB and a second preset threshold of 1MB as an example, in this embodiment of the application, 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 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, a 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, a full preloading is performed, that is, the entire parsed file content is loaded.
[0067] In some embodiments of this application, after preloading a portion of the parsed file into the third-level cache, the method further 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 portion of the parsed file stored in the third-level cache.
[0068] The hit rate threshold can be set according to specific circumstances, such as 60% or 70%; the cache hit rate is the probability that executable and linkable files can be found in the third-level cache. Specifically, it 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%.
[0069] It is understood that the embodiments of this 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 files in the parsing file stored in the third-level cache is increased to optimize the use of subsequent caches and thus optimize parsing efficiency.
[0070] Taking the parsing of a large 20MB executable file (large_app.exe) as an example, this explains the process of calculating the cache hit rate and how to optimize the size of some files in the parsed file stored in the third-level cache.
[0071] 1. Initial preloading and hit rate calculation.
[0072] The file size is 20MB, and the L3 cache has 70MB of free memory (>3×20MB=60MB). A small portion of the preload is performed according to the rules (the first 30% of the core section .text and .data, about 6MB).
[0073] 2. After the initial parsing, count 100 L3 cache accesses.
[0074] total_accesses = 100, cache_misses = 50 (50 accesses to the section data are not within the 30% preload range).
[0075] Cache hit rate = (100-50) / 100×100% = 50%, which is lower than the hit rate threshold of 60%.
[0076] 3. Since the cache hit rate is 50% < 60%, the preload range is increased from 30% to 50% (20% more content is added to the core section, the total preload is about 10MB, which is still less than the L3 cache capacity of 8MB, so 30%~40% of the content of the core section is added to the L3 cache, the total preload is 8MB).
[0077] 4. Calculate the cache hit rate again.
[0078] Another count of 100 L3 cache accesses: total_accesses = 200 (cumulative), cache_misses = 60 (only 10 cache misses among the new accesses).
[0079] Cache hit rate = (200-60) / 200×100% = 70%, reaching the threshold of 60%, so optimization stops.
[0080] In some embodiments of this application, before preloading a portion of the parsed file into the third-level cache, the method further includes: obtaining the file types of executable and linkable files; determining the preloaded section based on the file type; and preloading a portion of the parsed file in the preloaded section into the third-level cache.
[0081] The file types include executable files, object files, dynamic library files, etc.
[0082] Since different types of executable and linkable files may require different parsing sections, this application embodiment can obtain the file type of the executable and linkable files, determine the preloaded sections based on the file type, and preload a portion of the parsed file in the preloaded sections into the third-level cache, thereby achieving accurate determination of the preloaded sections based on the file type, so as to improve the hit rate of the subsequent third-level cache and improve the parsing speed.
[0083] For example, the preload section of an executable file can be set to .text, .data, or .init_array; the core preload section of an object file can be set to .symtab, .text, or .strtab.
[0084] Furthermore, it should be noted that the solutions in this application embodiment can be integrated into an application for processing.
[0085] Based on the above-described executable and linkable file parsing method, this application also provides an executable and linkable file parsing system, the structure of which is as follows: Figure 2 As shown, it includes: an ELF file input module, a parallel parsing module, a preloading module, a dynamic adjustment module, and a result output module.
[0086] The ELF file input module is used to input ELF files from the system; the multi-level caching module includes a first-level cache, a second-level cache, and a third-level cache to reduce the overhead of repeated parsing.
[0087] The parallel parsing module divides the ELF file parsing task into multiple subtasks and leverages the advantages of multi-core processors to parse each subtask in parallel, thereby improving the overall parsing speed.
[0088] Preload modules predict and preload potentially accessed segments and sections, reducing waiting time;
[0089] The dynamic adjustment module monitors system performance in real time and dynamically adjusts the cache size based on monitoring data, thereby optimizing parsing efficiency.
[0090] The results output module stores the parsed results in a database or file system for later use.
[0091] Based on the aforementioned executable and linkable file parsing system, embodiments of this application also provide 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.
[0092] Specifically, the executable and linkable file parsing method of this application embodiment has the following specific process: Figure 4 As shown, it includes the following steps:
[0093] Step 1: Create and initialize L1 (first-level cache), L2 (second-level cache), and L3 (third-level cache) caches.
[0094] Set the L1 cache to 32KB to store ELF file headers; set the L2 cache to 256KB to store program header tables; and set the L3 cache to 8MB to store section data.
[0095] Step 2: Input the ELF file.
[0096] This means inputting an ELF file and starting the fast parsing process for the ELF file.
[0097] Step 3: L1 cache check.
[0098] Check if the header of the ELF file is in the L1 cache. If it is not in the L1 cache, load the header of the ELF file from the disk into the L1 cache; otherwise, proceed to step 4.
[0099] Step 4: L2 cache check.
[0100] Check if the program header table of the ELF file is in the L2 cache. If it is not in the L2 cache, load the program header table of the ELF file from the disk into the L2 cache; otherwise, proceed to step 5.
[0101] Step 5: L3 cache check.
[0102] Check if the section data of the ELF file is in the L3 cache. If it is in the L3 cache, read the section data from the L3 cache; if it is not in the L3 cache, proceed to step 6.
[0103] Step 6: Build section dependencies.
[0104] After parsing the ELF header, the dependencies between sections are identified. For example, dependent sections include code reference chains (.text → .rodata) and symbol table chains (.symtab → .strtab). Independent sections include .data and .bss.
[0105] Step 7: Task group division and analysis.
[0106] Independent sections without dependencies are assigned to different CPU cores for parallel parsing; sections with dependencies are assigned to a specific idle CPU core for sequential parsing.
[0107] Step 8: Obtain the file type and determine the preloaded section.
[0108] For example, the core preload sections of an executable file are set to .text, .data, and .init_array; the core preload sections of an object file are set to .symtab, .text, and .strtab.
[0109] Step 9: Obtain the free memory size and file size.
[0110] If the free memory is less than three times the file size, no preloading is performed, meaning the L3 section data cache is not updated. If the free memory is greater than three times the file size and the file is larger than 10MB, a small preloading is performed, updating the first 30% of the core section content to the L3 cache. If the free memory is greater than three times the file size and the file is between 1MB and 10MB, a medium preloading is performed, updating the first 60% of the core section content 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, loading the entire core section content.
[0111] Step 11: Determine the cache hit rate.
[0112] The cache hit rate is (total_accesses - cache_misses) / total_accesses * 100%. If the cache hit rate is too low, the size of the L3 cache can be increased appropriately.
[0113] In summary, the above methods aim to improve the parsing efficiency of ELF files, especially in embedded systems and large-scale software analysis scenarios. By introducing a multi-level caching mechanism, parallel parsing technology, and intelligent preloading strategies, this method significantly reduces the time and resource consumption of ELF file parsing. Furthermore, the system provides the function of dynamically adjusting the parsing strategy to adapt to different hardware environments and application requirements.
[0114] The executable and linkable file parsing method of this application is described below through a specific embodiment, taking the parsing of a 5MB ELF file as an example.
[0115] Step 1: Initialize the cache.
[0116] L1 cache: 32KB, dedicated to storing ELF file headers (typically, ELF file headers are 64 to 128 bytes in size, so 32KB is more than enough);
[0117] 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, 256KB is sufficient for redundancy);
[0118] L3 cache: 8MB, used to store section data (such as .text, .data, etc., the total section data of a 5MB file is about 4.8MB).
[0119] Step 2: Input the ELF file.
[0120] The user triggers a parsing command, the target file is app.exe (an executable file, 5MB in size), and the system begins a fast parsing process.
[0121] Step 3: L1 cache check.
[0122] Check if the ELF header of app.exe exists in the L1 cache: If the cache is not found on the first parsing, the ELF header (64 bytes) of app.exe is loaded from the disk into the L1 cache.
[0123] Step 4: L2 cache check.
[0124] Check if the program header table for app.exe exists in the L2 cache: If the cache is not found on the first parsing, the program header table (containing 8 program segment descriptions, totaling 8 × 56 bytes = 448 bytes) is loaded from the disk into the L2 cache.
[0125] Step 5: L3 cache check.
[0126] Check if section data for app.exe exists in the L3 cache: First parsing, cache miss;
[0127] Updated statistics: total_accesses = 1 (this L3 access), cache_misses = 1 (missed).
[0128] Step 6: Construct section dependency data.
[0129] After parsing the ELF header and program header table, section dependencies are identified.
[0130] Dependency sections: .text (code segment) → .rodata (read-only data, constants referenced in the code); .symtab (symbol table) → .strtab (string table, storing symbol names);
[0131] Independent sections: .data (initialized data), .bss (uninitialized data), .init_array (array of initialization functions).
[0132] Step 7: Task group division and analysis.
[0133] Parallel parsing task: Allocate independent sections .data and .bss to CPU core 1 and core 2, and parse their data format (such as variable initialization values in .data and the size of .bss).
[0134] Sequential parsing task: Assign the dependency chains .text→.rodata and .symtab→.strtab to CPU core 3, parse .text first, then .rodata, and finally parse .symtab and then .strtab.
[0135] Step 8: Determine the preloaded section.
[0136] Since app.exe is an executable file, according to the rules, the core preload sections are: .text (code), .data (data), and .init_array (initialization functions).
[0137] Step 9: Obtain resource information.
[0138] The app.exe file is 5MB in size, and the current L3 cache free space is 20MB (greater than 3 times the file size, 5MB × 3 = 15MB, which meets the preloading condition).
[0139] Step 10: Update L3 cache.
[0140] Medium preloading is performed because "free memory (20MB) > 3 × file size (15MB)" and "file size (5MB) is between 1MB and 10MB".
[0141] The first 60% of the contents of the core section .text, .data, and .init_array are loaded into the L3 cache (the total preload is about 5MB × 60% = 3MB, which is much smaller than the L3 capacity of 8MB).
[0142] Step 11: Determine the cache hit rate.
[0143] After the initial parsing, total_accesses = 1, cache_misses = 1, and the hit rate is (1-1) / 1×100% = 0%. Since the initial parsing will inevitably result in a miss, the L3 cache size will not be adjusted for the time being (8MB is sufficient for a 5MB file).
[0144] 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 disk I / O. The L3 cache already contains 60% of the data in the core section. If the accessed section is within the preload range, the cache hits, total_accesses increases but cache_misses remains unchanged, and the hit rate is significantly improved.
[0145] The executable and linkable file parsing method proposed in this application can identify the data structure of the executable and linkable file, query whether multi-level data is stored in the multi-level cache based on the data structure, and skip the parsing of the current level data in the current level cache and directly obtain the executable and linkable file result from the cache if the current level data is stored in the current level cache. If the current level data is not stored in the current level cache, the current level data is loaded from the hard disk into the current level cache. By storing the parsed multi-level data of the executable and linkable file in the multi-level cache, the same executable and linkable file can be parsed without repeated parsing, reducing memory usage and improving the parsing efficiency of the executable and linkable file. Moreover, it avoids loading the data of the executable and linkable file from the hard disk through frequent I / O operations, thus avoiding impacting the performance of the operating system.
[0146] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0147] Embodiments of this application also provide an executable and linkable file parsing apparatus.
[0148] Figure 5 This is a schematic diagram of an executable and linkable file parsing apparatus provided according to an embodiment of this application.
[0149] 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.
[0150] 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 cache stores the current level data, the parsing of the current level data is skipped. If the current level cache does not store the current level data, the current level data is loaded from the hard disk into 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.
[0151] In some embodiments of this application, 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 section data.
[0152] In some embodiments of this application, the executable and linkable file parsing device 10 of this application further includes a parsing module.
[0153] The parsing module is used to identify the segment relationships in the segment data if the current level data is segment data before loading the current level data from the hard disk into the current level cache; parse the segment data loaded from the hard disk according to the segment relationships; and store the parsed file of the segment data into the third level cache.
[0154] In some embodiments of this application, the node relationship includes a first relationship and a second relationship. The first relationship indicates that there is a dependency relationship between the nodes, and the second relationship indicates that there is no dependency relationship between the nodes.
[0155] In some embodiments of this application, the parsing module is further configured to: sequentially parse the sections of the first relation to the target cores of the processor; and parallelly parse the sections of the second relation to different cores of the processor.
[0156] In some embodiments of this application, the executable and linkable file parsing device 10 of this application further includes a computing module.
[0157] The calculation module is used to obtain the load rate of multiple cores on the processor before the first relation is assigned to the target core of the processor in sequence 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.
[0158] In some embodiments of this application, the parsing module is further configured to: obtain the system's free memory and the size of the parsing file; set a preloading threshold based on the size of the parsing file; if the free memory is less than the preloading threshold, store the parsing file of the section data in the third-level cache; if the free memory is greater than or equal to the preloading threshold, preload a portion of the parsing file into the third-level cache.
[0159] In some embodiments of this application, the parsing module is further configured to: determine the target preloading method based on the size of the parsed file; and load a portion of the parsed file into the third-level cache according to the target preloading method.
[0160] In some embodiments of this application, the parsing module is further configured to: if the size of the parsed file is greater than or equal to a first preset threshold, then the target preloading method is the first preloading method; if the size of the parsed file is greater than a second preset threshold and less than the first preset threshold, then the target preloading method is the second preloading method; if the size of the parsed file is less than or equal to the second preset threshold, then the target preloading method is the third preloading method.
[0161] In some embodiments of this application, the executable and linkable file parsing device 10 of this application embodiment further includes: an addition module.
[0162] The module adds a feature to obtain the cache hit rate in the third-level cache after preloading some files from the parsed file into the third-level cache. If the cache hit rate is less than the hit rate threshold, the size of some files from the parsed file stored in the third-level cache is increased.
[0163] It should be noted that the description of the features in the embodiments corresponding to the executable and linkable file parsing device can be found in the relevant descriptions of the embodiments corresponding to the executable and linkable file parsing method, and will not be repeated here.
[0164] The executable and linkable file parsing apparatus proposed in the embodiments of this application can identify the data structure of executable and linkable files, query whether multi-level data is stored in the multi-level cache based on the data structure, and if 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 result is 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 into the current level cache. By storing the parsed multi-level data of executable and linkable files in the multi-level cache, the same executable and linkable files can be parsed without repeated parsing, reducing memory usage and improving the parsing efficiency of executable and linkable files. Furthermore, it avoids loading the data of executable and linkable files from the hard disk through frequent I / O operations, thus avoiding impacting the performance of the operating system.
[0165] Embodiments of this application also provide an electronic device.
[0166] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device may include:
[0167] The memory 601, the processor 602, and the computer program stored on the memory 601 and capable of running on the processor 602.
[0168] When the processor 602 executes the program, it implements the executable and linkable file parsing method provided in the above embodiments.
[0169] Furthermore, electronic devices also include:
[0170] Communication interface 603 is used for communication between memory 601 and processor 602.
[0171] The memory 601 is used to store computer programs that can run on the processor 602.
[0172] The memory 601 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0173] If the memory 601, processor 602, and communication interface 603 are implemented independently, then the communication interface 603, memory 601, and processor 602 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0174] Optionally, in a specific implementation, if the memory 601, processor 602, and communication interface 603 are integrated on a single chip, then the memory 601, processor 602, and communication interface 603 can communicate with each other through an internal interface.
[0175] 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 this application.
[0176] Embodiments of this application also provide a non-volatile computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described embodiments of the executable and linkable file parsing method when it runs.
[0177] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0178] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above embodiments of the executable and linkable file parsing method.
[0179] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can 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.
[0180] The foregoing has provided a detailed description of the executable and linkable file parsing method and electronic device provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A method for parsing executable and linkable files, characterized in that, Includes the following steps: In response to parsing instructions for executable and linkable files, the system identifies the data structure of the executable and linkable files, wherein the data structure includes multi-level data, including a file header, a program header table, and section data, and a multi-level cache including 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; The system queries whether the 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 into the current-level cache. Before loading the current-level data from the hard disk into the current-level cache, the system further includes: if the current-level data is the section data, identifying the section relationships in the section data; parsing the section data loaded from the hard disk according to the section relationships; and storing the parsed file of the section data into the third-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, characterized in that, The segment relationships include a first relationship and a second relationship. The first relationship indicates that there is a dependency between segments, and the second relationship indicates that there is no dependency between segments. Parsing the segment data loaded from the hard disk according to the segment relationships includes: The first relation's section is assigned to the processor's target core for sequential parsing; The sections of the second relationship are allocated to different cores of the processor for parallel parsing.
3. The executable and linkable file parsing method according to claim 2, characterized in that, Before allocating the sections of the first relation to the processor's target core sequentially, the process also includes: Obtain the load rate of multiple cores on the processor; The idle rate of the cores is calculated based on the load rate of the multiple cores; The target core is determined from the plurality of cores based on the idle rate.
4. The executable and linkable file parsing method according to claim 1, characterized in that, Storing the parsed file of the section data into the third-level cache includes: Obtain the system's free memory and the size of the parsed file; A preloading threshold is set based on 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 preload threshold, then a portion of the files in the parsed file will be preloaded into the third-level cache.
5. The executable and linkable file parsing method according to claim 4, characterized in that, The step of preloading a portion of the parsed file into the third-level cache includes: The target preloading method is determined based on the size of the parsed file; A portion of the files in the parsed file is loaded into the third-level cache according to the target preloading method.
6. The executable and linkable file parsing method according to claim 4, characterized in that, The step of determining the target preloading method based on the size of the parsed file includes: If the size of the parsed file is greater than or equal to the first preset threshold, then the target preloading method is the first preloading method; If the size of the parsed file is greater than the second preset threshold and less than the first preset threshold, then the target preloading method is the second preloading method; If the size of the parsed file is less than or equal to the second preset threshold, then the target preloading method is the third preloading method.
7. The executable and linkable file parsing method according to claim 4, characterized in that, After preloading a portion of the parsed files into the third-level cache, the process also includes: Obtain the cache hit rate in the third-level cache; If the cache hit rate is less than the hit rate threshold, then the size of some files in the parsed files stored in the third-level cache is increased.
8. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the executable and linkable file parsing method as described in any one of claims 1 to 7 when executing the computer program.
Citation Information
Patent Citations
Execution of dynamic languages via metadata extraction
US20110173597A1