Dynamic loading method and electronic device
By preloading processes to parse the files to be parsed and saving the results, dynamic libraries can be shared and loaded in parallel. This solves the problems of wasted computing resources and slow startup speed in multi-process scenarios, thus improving application startup speed and user experience.
Patent Information
- Application Number
- PCT/CN2024/079257
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-06-30
- Filing Date
- 2024-02-29
- Publication Date
- 2025-01-02
AI Technical Summary
In existing technologies, dynamic libraries need to be loaded separately and completely in multi-process scenarios, which leads to a waste of computing resources and a slow startup speed.
By preloading the file to be parsed and saving the parsing results, the dynamic library can be shared and loaded in parallel, thus optimizing the dynamic library loading process.
It optimizes application startup speed, saves computing resources and memory space, and improves user experience.
Smart Images

Figure CN2024079257_02012025_PF_FP_ABST
Abstract
Description
Dynamic loading method and electronic device
[0001] This application claims priority to the Chinese patent application with application number 202310808428.8 filed with the State Intellectual Property Office of China on June 30, 2023, and priority to the Chinese patent application with the invention name “A method and electronic device for dynamic loading”, all contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computers, and more particularly, to a dynamic loading method and electronic device. Background Art
[0003] Dynamic loading technology involves dynamically loading one or more library files into memory while a program is running. This technology then maps the functions and variables within the library files into the program's process address space for easy access. This technology allows a program to load required library files as needed during runtime, eliminating the need to link all library files into the program during compilation. This saves memory space and increases application flexibility.
[0004] However, dynamic library loading of different applications is independent of each other. Every time a new application is started, a complete dynamic loading may be required, which slows down the startup speed and causes a lot of redundant calculations.
[0005] Summary of the Invention
[0006] The present application provides a dynamic loading method and electronic device that can realize the sharing of one or more analysis results, which is conducive to optimizing the application startup speed, saving computing resources, saving memory space, and improving the performance of the electronic device, thereby improving the user experience.
[0007] In a first aspect, a dynamic loading method is provided, the method comprising: parsing one or more target files and saving one or more first parsing results, the one or more first parsing results corresponding one-to-one to the one or more target files, the one or more target files including a first target file, the first target file being an executable file or a dynamic library file; searching for a first parsing result of a dynamic library file that the first executable file depends on in the one or more first parsing results; and mapping the dynamic library file that the first executable file depends on to the process address space where the first executable file is located based on the first parsing result of the dynamic library file that the first executable file depends on.
[0008] It should be understood that the one or more target files may include a first target file, and the first target file may be an executable file or a dynamic library file.
[0009] It should be understood that there may or may not be a dependency relationship between one or more target files, and the embodiments of the present application are not limited to this.
[0010] It should be noted that the first executable file may be, for example, an executable file of an application loaded in a user process, and the process address space is a memory space allocated by the system to the user process.
[0011] It should be noted that the first parsing result may be, for example, the format parsing result in the embodiment shown in FIG. 4 , and one or more first parsing results may be saved in the form of a global target file list in the embodiment shown in FIG. 4 .
[0012] In an embodiment of the present application, when a target file is parsed, the first parsing result of the target file can be saved. These first parsing results will be used in the loading process of the dynamic library, thereby realizing the decoupling of the parsing process and the loading process of the target file, which is conducive to optimizing the application startup speed and improving the user experience. On the other hand, the first parsing result of a target file can be used in the loading process of multiple different executable files, thereby realizing the sharing of the one or more first parsing results, which is conducive to saving computing resources and saving memory space. In addition, the user can perform operations such as adding, deleting, and modifying the saved one or more first parsing results, thereby improving the flexibility of dynamic loading.
[0013] In combination with the first aspect, in some implementations of the first aspect, the one or more target files include a first dynamic library file, and the first parsing result includes a path, a mapping interval, and dependency information of the first dynamic library file.
[0014] It should be understood that the first parsed result of the first dynamic library file may include the name, path, mapping interval, and dependency information of the first dynamic library file. The path of the first dynamic library file may indicate the location where the first dynamic library file is stored on disk; the dependency information of the first dynamic library file may indicate the dynamic library files that the first dynamic library file depends on, including the dynamic library files that the first dynamic library file directly depends on and the dynamic library files that the first dynamic library file indirectly depends on; and the mapping interval of the first dynamic library file may indicate the file range that the first dynamic library file needs to map to the process address space, that is, the content that the first dynamic library file needs to load.
[0015] In an embodiment of the present application, one or more first parsing results may include the path, mapping interval, and dependency information of one or more target files, thereby quickly finding dynamic library files and the dynamic library files on which they depend, and determining the mapping intervals of these dynamic library files, which is beneficial for improving the startup speed of the application. In addition, because the one or more first parsing results can be shared, it is beneficial to save computing resources.
[0016] In combination with the first aspect, in certain implementations of the first aspect, the dynamic library file that the first executable file depends on includes the first dynamic library file, wherein, based on the first parsing result of the dynamic library file that the first executable file depends on, mapping the dynamic library file that the first executable file depends on to the process address space where the first executable file is located includes: obtaining the first dynamic library file according to the path of the first dynamic library file; and mapping the first dynamic library file to the process address space according to the mapping interval of the first dynamic library file.
[0017] In combination with the first aspect, in some implementations of the first aspect, the first target file is a file in a list of files to be parsed, and the files in the list of files to be parsed are files that need to be parsed before the first executable file is loaded into the process address space.
[0018] It should be noted that the files in the list of files to be parsed may be files configured by the user or may be default files that need to be pre-parsed.
[0019] It should be noted that one or more target files may be files in the list of files to be parsed or may not be files in the list of files to be parsed. For example, when the second executable file is started, the dynamic loader may need to parse the second executable file and the dynamic library files that the second executable file depends on. In this case, the first parsing result of the second executable file and the first parsing result of the dynamic library files that the second executable file depends on can be saved so that other executable files can find the first parsing result of the dynamic library files they need when loading.
[0020] In an embodiment of the present application, by pre-parsing the files in the list of files to be parsed, the first parsing results of the files in the list of files to be parsed and the first parsing results of the dynamic libraries that these files depend on can be obtained and saved. These first parsing results will be used in the loading process of the dynamic library, thereby achieving the decoupling of the parsing process and the loading process of the target file, which is beneficial to optimizing the startup speed of the application and improving the user experience. On the other hand, the first parsing result of a target file can be used in the loading process of multiple different executable files, thereby achieving the sharing of one or more first parsing results, which is beneficial to saving computing resources and saving memory space.
[0021] In combination with the first aspect, in certain implementations of the first aspect, the first parsing results of the second dynamic library file and the dynamic library file on which the second dynamic library file depends are searched for in the one or more first parsing results, where the second dynamic library file is the designated dynamic library file requested to be loaded by the process where the first executable file is located; based on the first parsing results of the second dynamic library file and the dynamic library file on which the second dynamic library file depends, the second dynamic library file and the dynamic library file on which the second dynamic library file depends are mapped to the process address space.
[0022] In an embodiment of the present application, the loading of the specified dynamic library file can be achieved based on the first parsing result of the specified dynamic library file and the dynamic library file on which the specified dynamic library file depends, which is beneficial to optimizing the application startup speed and improving the user experience.
[0023] In combination with the first aspect, in some implementations of the first aspect, if the first parsing result of the dynamic library file that the first executable file depends on is not found, the first executable file is parsed, and the first parsing result of the first executable file and the first parsing result of the dynamic library file that the first executable file depends on are saved; and / or,
[0024] If the parsing result of the second dynamic library file is not found, the second dynamic library file is parsed, and the first parsing result of the second dynamic library file and the first parsing result of the dynamic library file on which the second dynamic library file depends are saved.
[0025] It should be understood that the dynamic library file that the first executable file depends on and the specified dynamic library are both dynamic libraries required when the first executable file is running.
[0026] In an embodiment of the present application, if the dynamic library required for the runtime of the first executable file has not been parsed, the dynamic library required for the runtime of the first executable file can be parsed according to traditional methods, and the corresponding first parsing result can be saved, thereby optimizing the startup speed of subsequent applications that rely on these dynamic library files, which is beneficial to improving the user experience.
[0027] In combination with the first aspect, in certain implementations of the first aspect, parsing one or more target files and saving one or more first parsing results includes: using multiple threads to parse the one or more target files in parallel and saving the one or more first parsing results.
[0028] In an embodiment of the present application, by parsing one or more target files in parallel through multi-threading, the parsing speed can be accelerated, which is conducive to fully utilizing computing resources.
[0029] In combination with the first aspect, in certain implementations of the first aspect, the dynamic library files that the first executable file depends on include a third dynamic library file and a fourth dynamic library file, wherein, mapping the dynamic library files that the first executable file depends on to the process address space where the first executable file is located according to the first parsing result of the dynamic library files that the first executable file depends on includes: a first thread mapping the third dynamic library file to the process address space where the first executable file is located according to the first parsing result of the third dynamic library file;
[0030] The second thread maps the fourth dynamic library file to the process address space according to the first parsing result of the fourth dynamic library file, and the first thread and the second thread are different.
[0031] In an embodiment of the present application, multiple dynamic library files can also be loaded in parallel through multi-threading, thereby speeding up the loading speed, which is beneficial to optimizing the startup speed of the application and improving the user experience.
[0032] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes:
[0033] The one or more target files are parsed and information of one or more symbols is saved, where the one or more symbols are symbols defined in the one or more target files, and the one or more symbols include a first symbol, and the information of the first symbol includes the name of the target file to which the first symbol belongs and the position information of the first symbol in the target file to which the first symbol belongs.
[0034] In an embodiment of the present application, when file target is parsed, the information of the symbol defined in the file target can be preserved. When symbol to be relocated is relocated, the position of symbol to be relocated in the process address space can be quickly found, thereby accelerating the relocation process, helping to optimize the application startup speed, helping to promote the user's experience. On the other hand, the information of one or more symbols can be used in the relocation process of a plurality of different executable files, thereby realizing the sharing of the information of these one or more symbols, helping to save computing resources, helping to save memory space.
[0035] In combination with the first aspect, in certain implementations of the first aspect, the dynamic library file that the first executable file depends on includes a fifth dynamic library file, and the relocation table of the fifth dynamic library file includes a second symbol. The method also includes: after mapping the dynamic library file that the first executable file depends on to the process address space where the first executable file is located, searching for information of the second symbol in the information of the one or more symbols, and the information of the second symbol is used to relocate the second symbol.
[0036] In combination with the first aspect, in certain implementations of the first aspect, the method further includes: obtaining the address of the second symbol in the process address space based on the information of the second symbol; and relocating the second symbol based on the address of the second symbol in the process address space.
[0037] In combination with the first aspect, in certain implementations of the first aspect, the method further includes: when the first executable file and the dynamic library file on which the first executable file depends are not in the resolved file list, parsing the first executable file and the dynamic library file on which the first executable file depends, and saving information about symbols defined in the first executable file and the dynamic library file on which the first executable file depends, the resolved file list is used to store the name of the resolved executable file or dynamic library file.
[0038] In combination with the first aspect, in certain implementations of the first aspect, parsing the one or more target files and saving information of one or more symbols includes: using multiple threads to parse the one or more target files in parallel and saving information of the one or more symbols.
[0039] In a second aspect, a dynamic loading method is provided, which includes: parsing one or more target files and saving information of one or more symbols, wherein the one or more symbols are symbols defined in the one or more target files, and the one or more symbols include a first symbol, and the information of the first symbol includes the name of the target file to which the first symbol belongs and the position information of the first symbol in the target file to which the first symbol belongs, and the one or more target files include the first target file, and the first target file is an executable file or a dynamic library file; in the information of the one or more symbols, searching for information of a second symbol, wherein the second symbol is a symbol in a relocation table of a dynamic library file that the first executable file depends on, and the information of the second symbol is used to relocate the second symbol.
[0040] It should be understood that the one or more target files may include a first target file, and the first target file may be an executable file or a dynamic library file.
[0041] It should be understood that there may or may not be a dependency relationship between one or more target files, and the embodiments of the present application are not limited to this.
[0042] In an embodiment of the present application, one or more symbols are symbols defined in one or more target files, including all symbols defined in each target file.
[0043] It should be noted that the first executable file may be, for example, an executable file of a program loaded in a user process, and the process address space is a memory space allocated by the system to the user process.
[0044] It should be noted that the information of each symbol may be, for example, the symbol parsing result in the embodiment shown in FIG. 4 , and the information of one or more symbols may be stored in the form of a global symbol table in the embodiment shown in FIG. 4 .
[0045] In an embodiment of the present application, when file target is parsed, the information of the symbol defined in the file target can be preserved. When symbol to be relocated is relocated, the position of symbol to be relocated in the process address space can be quickly found, thereby accelerating the relocation process, helping to optimize the application startup speed, helping to promote the user's experience. On the other hand, the information of one or more symbols can be used in the relocation process of a plurality of different executable files, thereby realizing the sharing of the information of these one or more symbols, helping to save computing resources, helping to save memory space.
[0046] In conjunction with the second aspect, in certain implementations of the first aspect, the method further includes:
[0047] According to the information of the second symbol, an address of the second symbol in the process address space where the first executable file is located is obtained; and according to the address of the second symbol in the process address space, the second symbol is relocated.
[0048] In combination with the second aspect, in certain implementations of the first aspect, the first target file is a file in a list of files to be parsed, and the files in the list of files to be parsed are files that need to be parsed before the first executable file is loaded into the process address space.
[0049] It should be noted that the files in the list of files to be parsed may be files configured by the user or may be default files that need to be pre-parsed.
[0050] It should be noted that the one or more target files may be files in the list of files to be parsed, or may not be files in the list of files to be parsed.
[0051] In combination with the second aspect, in certain implementations of the first aspect, the method further includes: when the first executable file or the dynamic library file on which the first executable file depends is not in the resolved file list, parsing the first executable file and the dynamic library file on which the first executable file depends, and saving information about symbols defined in the first executable file and the dynamic library file on which the first executable file depends, the resolved file list is used to store the name of the resolved executable file or dynamic library file.
[0052] In combination with the second aspect, in certain implementations of the first aspect, parsing the one or more target files and saving information of one or more symbols includes: using multiple threads to parse the one or more target files in parallel and saving information of the one or more symbols.
[0053] The third aspect is an electronic device according to an embodiment of the present application, which includes one or more processors; one or more memories; the one or more memories store one or more computer programs, and the one or more computer programs include instructions. When the instructions are executed by the one or more processors, the above aspects or any possible implementation of the above aspects are executed.
[0054] In a fourth aspect, a chip is provided, comprising a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the method described in the first aspect and any possible implementation of the first aspect is executed, or the method described in the second aspect and any possible implementation of the second aspect is executed.
[0055] In a fifth aspect, a computer-readable storage medium is provided, characterized in that it includes computer instructions, which, when the computer instructions are run on an electronic device, enable the electronic device to execute the method described in the first aspect and any possible implementation of the first aspect, or execute the method described in the second aspect and any possible implementation of the second aspect.
[0056] In the sixth aspect, a computer program product is provided, characterized in that the computer program product includes: computer program code, which, when the computer program code is run, implements the method described in the first aspect and any possible implementation of the first aspect, or implements the method described in the second aspect and any possible implementation of the second aspect.
[0057] The seventh aspect is an electronic device according to an embodiment of the present application, which includes modules / units for executing the above aspects or any possible design method of the above aspects; these modules / units can be implemented through hardware, or corresponding software can be implemented through hardware. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] FIG1 is a schematic structural diagram of an electronic device provided by this embodiment.
[0059] FIG2 is a block diagram of the software structure of the electronic device according to an embodiment of the present application.
[0060] FIG3 is a schematic diagram of a system architecture for dynamic loading provided in an embodiment of the present application.
[0061] FIG4 is a schematic flow chart of a dynamic loading method provided in an embodiment of the present application.
[0062] FIG5 is a schematic flow chart of a dynamic loading method provided in an embodiment of the present application.
[0063] FIG6 is a schematic flowchart of a dynamic loading method provided in an embodiment of the present application.
[0064] FIG7 is a schematic flowchart of a dynamic loading method provided in an embodiment of the present application.
[0065] FIG8 is a schematic diagram of the hardware structure of the device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0066] The terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification of this application and the appended claims, the singular expressions "a", "an", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one, two or more. The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships can exist; for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship.
[0067] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in yet other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0068] The technical solution in this application will be described below with reference to the accompanying drawings.
[0069] The following describes electronic devices and embodiments for using such electronic devices. In some embodiments, the electronic device may be a portable electronic device that also includes other functions such as a personal digital assistant and / or a music player, such as a mobile phone, a tablet computer, a wearable electronic device with wireless communication functions (such as a smart watch), etc. Exemplary embodiments of portable electronic devices include but are not limited to those equipped with The portable electronic device may be a portable electronic device running OpenHarmony or other operating systems. The portable electronic device may also be other portable electronic devices, such as a laptop computer. It should also be understood that in some other embodiments, the electronic device may not be a portable electronic device, but a desktop computer.
[0070] 1 shows a schematic structural diagram of an electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a compass 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195.
[0071] It should be understood that the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0072] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent components or integrated into one or more processors. In some embodiments, the electronic device 100 may also include one or more processors 110. The controller may generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution. In other embodiments, the processor 110 may also include a memory for storing instructions and data. For example, the memory in the processor 110 may be a high-speed cache memory. This memory may store instructions or data that have just been used or are being recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can directly call it from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the electronic device 100 in processing data or executing instructions.
[0073] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a SIM card interface, and / or a USB interface. Among them, the USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and peripheral devices. The USB interface 130 can also be used to connect headphones to play audio through the headphones.
[0074] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present application is merely an illustrative illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0075] The charging management module 140 is configured to receive charging input from a charger. The charger can be either a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 can receive charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 can receive wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also provide power to the electronic device via the power management module 141.
[0076] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and provides power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage, impedance). In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0077] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0078] Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antennas can be used in conjunction with a tuning switch.
[0079] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0080] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (WiFi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0081] Electronic device 100 implements display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0082] Display screen 194 is used to display images, videos, and the like. Display screen 194 includes a display panel. In some embodiments of the present application, when the display panel utilizes materials such as OLED, AMOLED, or FLED, display screen 194 in FIG. 1 can be bent. Here, "display screen 194 can be bent" means that the display screen can be bent to any angle at any location and maintained at that angle. For example, display screen 194 can be folded in half from the center, either left or right. Alternatively, it can be folded in half from the center, either top or bottom.
[0083] The electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.
[0084] The ISP processes data fed back by camera 193. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and transformed into a visible image. The ISP can also perform algorithmic optimization on image noise, brightness, and skin tone. It can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within camera 193.
[0085] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include one or more cameras 193.
[0086] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0087] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. This allows electronic device 100 to play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.
[0088] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU can enable intelligent cognitive applications in electronic device 100, such as image recognition, face recognition, speech recognition, and text comprehension.
[0089] The external memory interface 120 can be used to connect to an external memory device, such as a Micro SD card or a hard drive, to expand the storage capacity of the electronic device 100. The external memory device communicates with the processor 110 via the external memory interface 120 to implement data storage. For example, files such as music and videos can be stored on an external memory card. In the embodiments of the present application, the external memory device connected to the external memory interface 120 can be referred to as external memory.
[0090] The internal memory 121 can be used to store one or more computer programs, which include instructions. The processor 110 can execute the above instructions stored in the internal memory 121, so that the electronic device 100 performs the methods provided in some embodiments of the present application, as well as various applications and data processing. The internal memory 121 may include a program storage area and a data storage area. The program storage area may store an operating system; the program storage area may also store one or more applications (such as a gallery, contacts, etc.). The data storage area may store data created during the use of the electronic device 100 (such as photos, contacts, etc.). In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage components, a flash memory component, a universal flash storage (UFS), etc. In some embodiments, the processor 110 can execute the instructions stored in the internal memory 121, and / or the instructions stored in the memory provided in the processor 110, so that the electronic device 100 performs the methods provided in the embodiments of the present application, as well as other applications and data processing. The electronic device 100 can implement audio functions such as music playback, weather, etc. through the audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor, etc. In the embodiment of the present application, the internal memory 121 can be referred to as a memory.
[0091] The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.
[0092] The pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In some embodiments, the pressure sensor 180A can be located on the display screen 194. There are many types of pressure sensors 180A, such as resistive, inductive, and capacitive. A capacitive pressure sensor can include at least two parallel plates made of conductive material. When force is applied to the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on this change in capacitance. When a touch operation is applied to the display screen 194, the electronic device 100 detects the touch intensity based on the pressure sensor 180A. The electronic device 100 can also calculate the touch location based on the detection signal from the pressure sensor 180A. In some embodiments, touch operations applied to the same touch location but with different touch intensities can correspond to different operation instructions. For example, when a touch operation with an intensity less than a first pressure threshold is applied to a short message application icon, a command to view short messages is executed. When a touch operation with an intensity greater than or equal to the first pressure threshold is applied to the short message application icon, a command to create a new short message is executed.
[0093] The gyroscope sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., X, Y, and Z axes) can be determined by the gyroscope sensor 180B. The gyroscope sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyroscope sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyroscope sensor 180B can also be used for navigation and somatosensory game scenes.
[0094] Accelerometer 180E can detect the magnitude of acceleration of electronic device 100 in all directions (generally three axes). It can also detect the magnitude and direction of gravity when electronic device 100 is stationary. It can also be used to identify the electronic device's posture, enabling applications such as switching between landscape and portrait modes and pedometers.
[0095] Ambient light sensor 180L is used to sense ambient light brightness. Electronic device 100 can adaptively adjust the brightness of display screen 194 based on the perceived ambient light. Ambient light sensor 180L can also be used to automatically adjust white balance when taking photos. Ambient light sensor 180L can also work with proximity light sensor 180G to detect whether electronic device 100 is in a pocket to prevent accidental touches.
[0096] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0097] The temperature sensor 180J is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the electronic device 100 reduces the performance of the processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to prevent the electronic device 100 from shutting down abnormally due to low temperature. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 boosts the output voltage of the battery 142 to prevent abnormal shutdown due to low temperature.
[0098] The touch sensor 180K is also called a "touch panel." The touch sensor 180K can be disposed on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen." The touch sensor 180K is used to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operations can be provided via the display screen 194. In other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100, in a location different from that of the display screen 194.
[0099] Figure 2 is a software structure diagram of the electronic device 100 according to an embodiment of the present application. The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer, from top to bottom. The application layer can include a series of application packages.
[0100] As shown in FIG2 , the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and short message.
[0101] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0102] As shown in FIG2 , the application framework layer may include a window manager, a content provider, a view system, a telephony manager, a resource manager, a notification manager, and the like.
[0103] The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, take screenshots, etc.
[0104] Content providers are used to store and retrieve data and make it accessible to applications. This data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0105] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0106] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including answering, hanging up, etc.).
[0107] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0108] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically without user interaction. For example, the Notification Manager is used to notify users of completed downloads, message reminders, and so on. The Notification Manager can also display notifications in the form of icons or scrolling text in the top status bar of the system, such as notifications from applications running in the background, or in the form of dialog windows on the display. Examples include displaying text messages in the status bar, sounding notifications, vibrating electronic devices, and flashing indicator lights.
[0109] The system library may include multiple functional modules, such as a surface manager, media libraries, a 3D graphics processing library (e.g., OpenGL ES), and a 2D graphics engine (e.g., SGL).
[0110] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0111] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.
[0112] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis and layer processing.
[0113] A 2D graphics engine is a drawing engine for 2D drawings.
[0114] The kernel layer is the layer between hardware and software. The kernel layer includes at least display driver, camera driver, audio driver, and sensor driver.
[0115] Before introducing the embodiments of the present application, concepts related to the embodiments of the present application are first introduced.
[0116] Process: A computer program's activity on a set of data. It is the fundamental unit of resource allocation and scheduling, and the foundation of operating system architecture. In early process-oriented computer architectures, processes were the primary execution entity for programs; in modern thread-oriented computer architectures, processes are containers for threads. A program is a description of instructions, data, and their organization, while a process is the entity that runs the program.
[0117] Threads, sometimes called lightweight processes (LWPs), are the smallest unit of program execution flow. A standard thread consists of a thread ID, the current instruction pointer, a set of registers, and a stack. Furthermore, a thread is an entity within a process, the basic unit independently scheduled and dispatched by the system. A thread does not possess any system resources, only those essential for execution. However, it can share all resources owned by the process with other threads belonging to the same process. A thread can create and revoke another thread, and multiple threads in the same process can execute concurrently.
[0118] Library file: A type of file on a computer that provides users with ready-to-use variables, functions, or classes. Library files are categorized as static and dynamic libraries, or simply static and dynamic libraries. The difference between static and dynamic libraries is reflected in the program's linking phase. Static libraries are copied into the program during the linking phase; dynamic libraries are not copied into the program during the linking phase. Instead, they are dynamically loaded into memory by the system at runtime for use by the program.
[0119] Executable file: A binary file containing program code that can be executed directly. When the executable file is run, the system creates a process and loads the executable file into the process's address space to execute, thereby realizing the program's functionality.
[0120] Symbol: The symbols of a library file usually refer to the function and variable names in the library file.
[0121] Symbol table: Usually a data structure used to store symbols (such as functions, variables, etc.) defined and referenced in a dynamic library and their related information, such as name, type, size, etc.
[0122] Relocation table: used to store symbols that need to be relocated in dynamic libraries. Usually, if a symbol is defined in other dynamic libraries, the symbol needs to be relocated.
[0123] Handle: A way to reference or identify an object, which can be used to access or manipulate underlying system resources.
[0124] When a program is launched, the system creates a process for it. A process is a fundamental concept in the system, representing a running instance of a program. When a process is created, the system allocates memory space (i.e., the process address space) to store information such as program code, data, and a stack. The system then loads the program's executable file into the process address space and begins executing the executable file.
[0125] Dynamic loading technology refers to dynamically loading one or more dynamic libraries into memory when the program is running, and mapping the functions and variables in them to the process address space of the program for the program to call. Dynamic loading technology allows the program to load the required library files as needed during runtime without having to link all library files to the program during compilation, thereby saving memory space and improving program flexibility. The component that completes the above dynamic loading process is the dynamic loader.
[0126] The dynamic loading process of the program at startup mainly includes the following steps:
[0127] (1) The kernel initializes the process address space and maps the code segment, data segment and other contents that need to be loaded into the process address space.
[0128] (2) Perform dependency analysis on the executable file of the program, that is, obtain the dynamic libraries that the executable file depends on. For example, the dynamic libraries that the executable file depends on can be viewed based on the content of type DT_DEEDED in the .dynamic segment of the executable file. If this dynamic library also depends on other dynamic libraries, then the names of the dynamic libraries that the dynamic library depends on are also added to the load set, and this cycle is repeated until all dynamic libraries are loaded. If the dependency relationship between executable files and dynamic libraries is regarded as a tree diagram, then the process of parsing the dynamic libraries that the executable file depends on is a process of traversing the tree diagram. For example, the depth-first method, breadth-first method, or other order can be used to traverse the entire tree diagram.
[0129] (3) Search for the dynamic libraries that the executable file depends on. For example, you can search for dynamic libraries in multiple paths such as LD_LIBRARY_PATH, / lib, / usr / lib, and system directories.
[0130] (4) Open the dynamic library found, read the elf_header information of the dynamic library, and obtain the file range that needs to be mapped into the memory, that is, the mapping interval.
[0131] (5) Map the content that needs to be loaded into the dynamic library to the process address space and add it to the dynamic library list. The dynamic library list is maintained by the dynamic loader and contains all the library files that need to be dynamically loaded when the application is running. Each node in the dynamic library list represents a dynamic library and contains some metadata about the dynamic library, such as the dynamic library name, a list of other dynamic libraries that the current dynamic library depends on, the address of the dynamic library's data and code, the address of the symbol table, etc.
[0132] (6) Traverse the dynamic library linked list to find the address of the symbol to be relocated. Before the dynamic library is loaded into the process address space, the address of the dynamic library in the process address space cannot be confirmed, nor can the address of the symbol defined in the dynamic library in the process address space be confirmed. If other dynamic libraries depend on this dynamic library and reference the symbol defined by this dynamic library, the program will not be able to determine the address of the symbol and will not be able to complete the symbol reference. Therefore, after all dynamic libraries are loaded, it is necessary to obtain the virtual address of the symbol definition in the process address space and update it to the location where the symbol is referenced, i.e., relocation.
[0133] Each dynamic library can contain a relocation table, where each entry represents a symbol to be relocated. The dynamic loader can traverse the relocation table to find the symbol to be relocated and, based on the address of the dynamic library mapped in the process address space, determine the virtual address of the symbol to be relocated in the process address space, thus completing the relocation.
[0134] (7) Complete relocation based on the virtual address of the symbol to be relocated.
[0135] (8) Execute the main function of the process to complete the startup of the process.
[0136] The advantages of dynamic library loading technology include:
[0137] (1) Save memory space: Dynamic libraries can be loaded only when needed, and there is no need to link all library files to the program at once, which can save memory space.
[0138] (2) Flexibility: Dynamic libraries can be loaded dynamically at runtime, and the required library files can be loaded as needed, making the program more flexible.
[0139] (3) Maintainability: Dynamic libraries can be updated and maintained independently without recompiling the entire program.
[0140] (4) Reusability: Multiple programs can share the same dynamic library, improving code reusability.
[0141] In short, dynamic library loading technology is a very important technology that can make the program more flexible, save memory space, and improve the maintainability and reusability of the code.
[0142] However, in a multi-process scenario, a new process may need to be started with a separate, complete dynamic loading, which involves a lot of redundant computation and processing, greatly wasting computing resources.
[0143] An embodiment of the present application provides a dynamic loading method, based on which multiple processes can reuse the parsing results of a dynamic library, thereby saving computing resources, reducing the time required for dynamic loading, and improving the startup performance of the program.
[0144] The following describes the dynamic loading method provided by the embodiment of the present application in conjunction with Figures 3 and 4.
[0145] Figure 3 is a schematic diagram of a system architecture for dynamic loading provided by an embodiment of the present application. Figure 4 is a schematic diagram of a method for dynamic loading provided by an embodiment of the present application. The dynamic loading method shown in Figure 4 can be applied to the system architecture shown in Figure 3.
[0146] Referring to Figure 3, the dynamic loading tool provided by the embodiment of the present application can include two parts: one is the preloading process, and the other is the dynamic loader. The preloading process mainly provides a list of files to be parsed for the user to configure which files need to be preloaded; it is started before all user processes are started, and the parsing results of the files in the list of files to be parsed are stored in shared data; when the user process is started, the shared data is shared with the user process. It mainly includes the following modules:
[0147] Parsing module: reads and parses the file to be parsed and the dynamic library that the file to be parsed depends on, and passes the parsing results to the data management module for storage.
[0148] Thread Management Module: Creates and maintains multiple threads, and parses the files in parallel based on the parsing module. Because shared data can only be added but not subtracted, and can only be read but not written, the thread management module can support the parallel parsing of executable files and dynamic library files.
[0149] Storage management module: responsible for the abstract management, maintenance and update of storage hardware resources.
[0150] Data management module: provides a unified interface for accessing executable files and dynamic libraries, uses a unified data structure to organize shared data, and provides shared data management capabilities based on the storage management module.
[0151] Communication module: realizes data communication and interaction with the dynamic loader.
[0152] The dynamic loader is mainly responsible for mapping dynamic libraries into the process address space and relocating dynamic library symbols. It mainly includes the following modules:
[0153] Communication module: realizes data communication and interaction with the preloaded process.
[0154] Multi-thread management module: provides the ability to load dynamic library files in parallel and perform parallel symbol resolution.
[0155] Data management module: provides data structure representation and access interface for shared data obtained from the preloading process.
[0156] File loading module: Based on shared data, obtain the dynamic library that the process depends on, eliminating dependency resolution; based on shared data, obtain the path of the dynamic library, eliminating multi-path search for the dynamic library; based on shared data, obtain the dynamic library file format information, including the mapping interval, eliminating file format resolution.
[0157] Symbol resolution module: implements symbol lookup and relocation based on shared data.
[0158] Referring to FIG4 , the steps performed on the preloading process side include:
[0159] S401: The kernel starts a preloading process.
[0160] Before all user processes are started, the system kernel starts the preloading process.
[0161] S402, open up a shared memory, and initialize a global dynamic library list and a global symbol table on the shared memory.
[0162] Shared memory is used to store shared data, namely the data obtained by the preload process from parsing the target file. Shared data can be stored in the form of a global target file list and a global symbol table. Each entry in the global target file list can store the parsing result of a target file (executable file, dynamic library file); each entry in the global symbol table can store a symbol and its related information.
[0163] S403: Parse the files to be parsed on the list of files to be parsed.
[0164] Specifically, the preload process reads the list of files to be parsed, creates a parsing task for each file on the list, and adds the task to the thread task queue. The idle thread retrieves the parsing task from the thread task queue, retrieves the file to be parsed through the parsing module interface, and parses it. If the file to be parsed depends on other dynamic library files, parsing tasks are also created for these dynamic library files and added to the thread task queue.
[0165] In some embodiments, multiple threads can parse these dynamic library files in parallel. For example, a first thread parses dynamic library 1, and a second thread parses dynamic library 2. The first thread and the second thread are two different threads within the process.
[0166] The list of files to be parsed can be configured by the user, allowing the user to select which files to preload, or the list of files to be parsed can be configured with a default set of files to be parsed. Each element in the list of files to be parsed can represent the name and / or path of a file to be parsed. The preloading process can then locate the file on disk based on the name and / or path of the file to be parsed.
[0167] The files to be parsed may include executable files and dynamic library files. This is explained by taking the case where the files to be parsed are executable files. The preloading process requires the executable files to be parsed. Specifically, the following steps may be included:
[0168] (1) Obtain the dynamic libraries that the executable file depends on. The dynamic libraries that the executable file depends on here should include the dynamic libraries that the executable file directly depends on and the dynamic libraries that the executable file indirectly depends on, that is, all the dynamic libraries that the executable file depends on when running.
[0169] (2) According to the name of the dynamic library, the dynamic library that the executable file depends on is searched in some specified paths or default paths on the disk, for example, the dynamic library is found in multiple paths such as LD_LIBRARY_PATH, / lib, / usr / lib, and system directories.
[0170] (3) Parse the found dynamic library to obtain the path, mapping interval, dependency information, symbol information and other information of the dynamic library. Among them, the path of the dynamic library can indicate the location of the dynamic library file on the disk, so that the dynamic loader can find the dynamic library. The mapping interval indicates the content that the dynamic library needs to be loaded into the memory, so that the dynamic loader can load the dynamic library into the memory. The dependency information indicates which dynamic libraries the dynamic library depends on (including directly dependent dynamic libraries and indirectly dependent dynamic libraries). The symbol information can, for example, include basic information such as the name, type, size, etc. of the symbols (such as functions, variables, etc.) defined in the dynamic library, as well as the name of the dynamic library where the symbol is located and the index of the symbol table where the symbol is located.
[0171] It should be noted that the dynamic library where the symbol is located refers to the dynamic library where the symbol is located and defined. The symbol table where the symbol is located refers to the symbol table of the dynamic library where the symbol is located. The index of the symbol table where the symbol is located can indicate the position of the symbol in the symbol table or the position of the symbol in the dynamic library where the symbol is located.
[0172] For the sake of convenience, the embodiment of the present application may refer to the parsing of the path, mapping interval, and dependency information of a dynamic library (or executable file) as format parsing, and the parsing of the symbolic information of a dynamic library (or executable file) as symbol parsing.
[0173] It should be understood that format parsing and symbol parsing can be performed simultaneously or separately, and the embodiments of the present application are not limited to this. The path, mapping interval, dependency information, etc. of the dynamic library (or executable file) can be referred to as the format parsing result, and the symbol information of the dynamic library can be referred to as the symbol parsing result.
[0174] In some embodiments, all the dynamic libraries that the executable file depends on may be obtained first, and then these dynamic libraries may be parsed uniformly. Alternatively, the dynamic libraries that a portion of the executable file depends on may be obtained first, and after the parsing of the dynamic libraries that the portion of the executable file depends on is completed, the dynamic libraries that another portion of the executable file depends on may be obtained and parsed, until all the dynamic libraries that the executable file depends on are parsed.
[0175] If the file to be parsed is a dynamic library file, the preloading process also needs to parse the dynamic library file to obtain the path, mapping interval, dependency information, symbol information, etc. For other dynamic libraries that the dynamic library depends on, you can refer to the steps described above to parse these dynamic libraries, which will not be repeated here.
[0176] It should be noted that an executable file can also be understood as a dynamic library file. When parsing an executable file, information such as the name, path, dependency information, and symbol information of the executable file can also be obtained.
[0177] It should be understood that parsing the file to be parsed includes parsing the file to be parsed and parsing the dynamic library that the file to be parsed depends on.
[0178] In an embodiment of the present application, the parsing results can be divided into two parts for storage. One part of the parsing results is stored in the form of a global target file list, that is, the format parsing results are stored in the form of a global target file list; the other part of the parsing results is stored in the form of a global symbol table, that is, the symbol information (symbol parsing results) is stored in the form of a global symbol table.
[0179] Exemplarily, each item in the global target file list may represent a format parsing result for a target file, such as the target file's path, mapping interval, dependency information, and other information. For example, the global target file list may include the names of one or more target files and one or more format parsing results, with the one or more target file names and the one or more format parsing results corresponding one to one. In other words, in the global target file list, the format parsing result for a target file can be found based on its name.
[0180] For example, the global target file list may be structured as shown in Table 1. It should be understood that Table 1 does not contain values corresponding to executable file 1, dynamic library 2, dynamic library 3, dynamic library 4, and dynamic library 5. In the actual parsing process, Table 1 may be filled with values corresponding to executable file 1, dynamic library 2, dynamic library 3, dynamic library 4, and dynamic library 5, respectively.
[0181] Table 1 Structure of a global target file list
[0182] It should be understood that the global target file list may also be other types of data structures, which is not limited in the embodiments of the present application. The above examples of the global target file list should not constitute any limitation on the embodiments of the present application.
[0183] In some embodiments, when a request message for obtaining a format parsing result is received, the corresponding format parsing result can be found according to the file name (or file path) carried by the request message. Then, according to the dependency information of the file, the format parsing results of all dynamic libraries that the file depends on are obtained. For example, when a request message containing executable file 1 is received, the dependency information of executable file 1 is found in the global target file list. If executable file 1 depends on dynamic library 2 and dynamic library 3, dynamic library 2 and dynamic library 3 are found in the global target file list; if dynamic library 2 also depends on dynamic library 4, dynamic library 4 also needs to be found in the global target file list; finally, the format parsing results of dynamic library 2, dynamic library 3 and dynamic library 4 are packaged and sent to the requester.
[0184] It should be understood that in the above example, the dependency information of executable file 1 can record information such as the name or path of dynamic library 2, dynamic library 3, and dynamic library 4, or it can also record the index of dynamic library 2, dynamic library 3, and dynamic library 4 in the global target file list, so that the format parsing results of the dynamic library that executable file 1 depends on can be quickly found.
[0185] The global symbol table stores symbol information for all resolved dynamic libraries. Each entry in the global symbol table represents a symbol and related information about the symbol, such as the symbol's name, the name of the dynamic library to which it belongs, and the index of the symbol table where the symbol resides. In other words, in the global symbol table, you can find the name of the dynamic library where the symbol resides and the index of the symbol table where the symbol resides, based on the symbol's name.
[0186] It should be understood that the symbols in the global symbol table are information about symbols defined in the resolved dynamic library.
[0187] For example, the global symbol table may have a structure as shown in Table 2. It should be understood that Table 2 does not contain the numerical values corresponding to Symbol 1, Symbol 2, and Symbol 2. In the actual parsing process, Table 2 may be filled with the numerical values corresponding to Symbol 1, Symbol 2, and Symbol 2, respectively.
[0188] Table 1 Structure of a global symbol table
[0189] In some embodiments, the index of the symbol table where the symbol is located may also be the position information of the symbol in the target file to which it belongs, or may also be the offset of the symbol in the target file to which it belongs.
[0190] It should be understood that the global symbol table may also be other types of data structures. For example, the global symbol table may also be a hash table or a linked list. The embodiments of the present application are not limited to this. The above examples of global symbol tables should not constitute any limitation to the embodiments of the present application.
[0191] It should be noted that the name of the target file, the name of the executable file, the name of the dynamic library file, the name of the symbol, etc. in the embodiments of the present application can be an identifier or ID, which is used to uniquely identify the file or the symbol. The identifier or ID can, for example, be composed of a series of numbers or letters.
[0192] S404: Create a communication server for monitoring connections and requests from communication clients.
[0193] For each request message received, a request task is created and placed in the thread task queue. The idle thread can obtain the request task from the thread task queue and process the request task.
[0194] S405: Receive the request message sent by the dynamic loader and determine the type of the request message.
[0195] In an embodiment of the present application, the request message may be of two types: a target file list request and a global symbol table request. The target file list request or the global symbol table request may carry the name or path of the executable file loaded by the user process. The target file list request is used to request the format parsing result of the executable file, and the global symbol table request is used to request the acquisition of the global symbol table.
[0196] For the convenience of explanation, the target file list request is referred to as the first request message, and the global symbol table request is referred to as the second request message.
[0197] S406: If the first request message is received, return a first target file list.
[0198] If the first request message is received, the format parsing result of the dynamic library that the executable file depends on is searched in the global target file list according to the name (or path) of the executable file loaded in the user process.
[0199] If the corresponding format parsing results are found, a first target file list is generated based on these format parsing results and returned to the dynamic loader. The first target file list is a target file list exclusive to the executable file. The structure of the first target file list is similar to that of the global target file list. Each item in the first target file list represents the format parsing result of a dynamic library that the executable file depends on. The first target file list does not include the format parsing results of dynamic libraries that the executable file does not depend on.
[0200] For example, when a first request message containing executable file 1 is received, the dependency information of executable file 1 is found in the global target file list. If executable file 1 depends on dynamic library 2 and dynamic library 3, dynamic library 2 and dynamic library 3 are found in the global target file list. If dynamic library 2 also depends on dynamic library 4, dynamic library 4 also needs to be found in the global target file list. Finally, the format parsing results of dynamic library 2, dynamic library 3 and dynamic library 4 are packaged in the first target file list and sent to the dynamic loader or user process.
[0201] It should be understood that in the above example, the dependency information of executable file 1 can record information such as the name or path of dynamic library 2, dynamic library 3, and dynamic library 4, or it can also record the index of dynamic library 2, dynamic library 3, and dynamic library 4 in the global target file list, so that the format parsing results of the dynamic library that executable file 1 depends on can be quickly found.
[0202] It should be noted that different executable files have different target file lists. For example, the preloading process may receive multiple first request messages, for example, one first request message carrying the path of executable file 1 and another first request message carrying the path of executable file 2. The target file list specific to executable file 1 includes the format parsing results of the dynamic libraries that executable file 1 depends on, while the target file list specific to executable file 2 includes the format parsing results of the dynamic libraries that executable file 2 depends on.
[0203] If the format parsing results for the dynamic libraries that the executable file depends on do not exist, a format parsing task is created for the executable file and added to the thread task queue. The idle thread acquires the format parsing task and performs format parsing on the executable file, obtaining the format parsing results for the executable file and the dynamic libraries that the executable file depends on, and returns these format parsing results to the dynamic loader.
[0204] In some embodiments, after the executable file format is parsed, the format parsing results of the executable file and the format parsing results of the dynamic library that the executable file depends on are saved, and these format parsing results are saved in the global target file list.
[0205] In some embodiments, format parsing tasks are created for the executable file and the dynamic library files that the executable file depends on, and added to the thread task queue. Multiple idle threads can respectively obtain format parsing tasks and perform format parsing on the executable file and the dynamic library files that the executable file depends on in parallel.
[0206] It should be understood that the multiple idle threads are multiple different threads in the process address space.
[0207] S407: If the second request message is received, the global symbol table is returned.
[0208] If the second request message is received, the executable file loaded in the user process is judged to determine whether the executable file has been subjected to symbol resolution according to its name (or path). If the executable file has been subjected to symbol resolution, the global symbol table is returned to the dynamic loader.
[0209] Optionally, if the second request message is received, the handle, address or pointer of the global symbol table is returned. The dynamic loader can access or read the global symbol table based on the handle, address or pointer of the global symbol table.
[0210] If the executable file has not been symbolically resolved, a symbol resolution task is created for the executable file and added to the thread task queue. The idle thread obtains the symbol resolution task, performs symbol resolution on the executable file, obtains symbol information for the executable file and the dynamic libraries it depends on, saves this symbol information to the global symbol table, and then returns the global symbol table to the dynamic loader.
[0211] In some embodiments, symbol resolution tasks are created for the executable file and the dynamic library files that the executable file depends on, and added to the thread task queue. Multiple idle threads can respectively obtain symbol resolution tasks and perform symbol resolution on the executable file and the dynamic library files that the executable file depends on in parallel.
[0212] In some embodiments, the preloading process may maintain a parsed file list for storing the names or paths of parsed executable files (or dynamic library files). Thus, upon receiving a request message, the preloading process may determine whether the executable file (or dynamic library file) has been parsed based on the parsed file list and the name or path of the executable file (or dynamic library file).
[0213] In some embodiments, since the global target file list records information of all resolved files, the global target file list can be used as the resolved file list.
[0214] 3 and 4 , the steps performed on the dynamic loader side may include:
[0215] S408, the kernel starts the user process.
[0216] Specifically, the process address space and stack are initialized, and the code of the executable file and other information are loaded, and the dynamic loader completes the dynamic loading.
[0217] S409: Create a communication client and establish a connection with the communication server.
[0218] It should be understood that the communication server and the communication client are a means of inter-process communication. In addition, other methods can also be used to achieve inter-process communication, which is not limited in the embodiments of the present application.
[0219] S410: Send a first request message and / or a second request message, and correspondingly receive a first target file list and / or a global symbol table.
[0220] The first request message or the second request message may include the name or path of the executable file loaded by the user process. The first request message is used to request the format parsing result of the executable file, and the first request message is used to request the global symbol table.
[0221] It should be noted that the first target file list is a target file list specific to the executable file. The structure of the first target file list is similar to that of the global target file list. Each item in the first target file list represents the format parsing result of a dynamic library that the executable file depends on. The first target file list does not include the format parsing results of dynamic libraries that the executable file does not depend on.
[0222] It should be noted that, usually, the dynamic loader may first send a first request message, and then send a second request message after all dynamic libraries that the executable file depends on are mapped into the process address space.
[0223] S411, traverse the first target file list, and map the dynamic library that the executable file depends on to the process address space.
[0224] Specifically, a load task is created for each dynamic library in the first target file list and added to the thread task queue. The idle thread executes the load task and maps the dynamic library to the process address space based on the format parsing result corresponding to the dynamic library. For example, the dynamic library file is first searched based on the dynamic library path, and then the content to be loaded is mapped to the process address space based on the dynamic library's mapping range.
[0225] In some embodiments, multiple idle processes can respectively perform loading tasks and simultaneously map multiple dynamic libraries to the process address space, thereby reducing the loading time of the dynamic libraries.
[0226] S412: After mapping the dynamic library that the executable file depends on to the process address space, relocation is performed.
[0227] Specifically, a relocation task is created for each dynamic library in the first target file list and the relocation task is added to the thread task queue. The idle thread executes the relocation task, obtains the relocation table of the dynamic library, traverses the relocation table, and obtains the symbol to be relocated. The name of the dynamic library where the symbol to be relocated is located and the index of the symbol table where the symbol to be relocated is located are then searched in the global symbol table. Based on the index of the symbol table where the symbol to be relocated is located, the symbol to be relocated is found in the symbol table where the symbol to be relocated is located, thereby obtaining the address of the symbol to be relocated in the process address space to complete the relocation.
[0228] In some embodiments, multiple idle processes can respectively execute relocation tasks and simultaneously relocate symbols to be relocated of multiple dynamic libraries.
[0229] It should be noted that, during the relocation process, the address of the symbol to be relocated in the process address space can usually be updated to the location that references the relocation symbol.
[0230] It should be noted that the relocation table of a dynamic library records all the symbols of the dynamic library that need to be relocated; the symbol table of a dynamic library records information such as the symbols defined in the dynamic library, the name of the symbol, the type of the symbol, the location of the symbol in the dynamic library, etc.
[0231] In some embodiments, the symbol to be relocated is found in the symbol table where the symbol to be relocated is located, and the relative position of the symbol to be relocated in the dynamic library to which it belongs can be obtained. Combined with the address of the dynamic library to which the symbol belongs in the process address space, the address of the symbol in the process address space can be determined.
[0232] Optionally, if multiple duplicate dynamic libraries are found in the global symbol table according to the name of the symbol to be relocated, the process returns to the traditional flow to search for the symbol to be relocated to complete the relocation.
[0233] S413, execute the main function of the user process to complete the startup of the user process.
[0234] FIG5 is a schematic flow chart of a dynamic loading method provided in an embodiment of the present application. As shown in FIG5 , the method includes:
[0235] S510: The user process requests to load a specified dynamic library.
[0236] During the startup of a user process, the user process may request to load a specified dynamic library. For example, the user process may use the dlopen function to load a dynamic library with a specified file name or a specified file path.
[0237] S520: The dynamic loader sends a third request message to the preloading process.
[0238] The third request message may carry the name or path of a specified dynamic library, and is used to request to obtain the format parsing result or global symbol table of the specified dynamic library.
[0239] S530: The preloading process searches for a corresponding format parsing result according to the name of the specified dynamic library.
[0240] Based on the name or path of the specified dynamic library, search the global target file list for the format parsing results of the specified dynamic library and the dynamic libraries on which the specified dynamic library depends.
[0241] Optionally, if the corresponding format parsing result is not found, a loading task and a symbol parsing task for the specified dynamic library are created to obtain the format parsing results and symbol information of the specified dynamic library and the dynamic libraries on which the specified dynamic library depends, and the format parsing results of the specified dynamic library are stored in the global target file list, and the symbol information of the specified dynamic library is stored in the global symbol table.
[0242] In some embodiments, the third request message may be included in the first request message, that is, the first request message may carry the name (or path) of the executable file loaded by the user process and the name (or path) of the specified dynamic library. The preloading process finds all format parsing results related to the executable file and the specified dynamic library in the global target file list based on the name (or path) of the executable file and the name (or path) of the specified dynamic library, and packages them and sends them to the dynamic loader.
[0243] In some embodiments, after performing symbol resolution on the designated dynamic library and the dynamic libraries on which the designated dynamic library depends, the updated global symbol table is returned to the dynamic loader.
[0244] Optionally, the dynamic loader sends a second request message to the preloading process to request the global symbol table.
[0245] S540 , the dynamic loader maps the specified dynamic library and the dynamic libraries that the specified dynamic library depends on to the process address space according to the format parsing results of the specified dynamic library and the dynamic libraries that the specified dynamic library depends on.
[0246] Optionally, based on the global symbol table and the relocation table of the specified dynamic library, the relocation of the to-be-relocated symbol of the specified dynamic library is completed.
[0247] FIG6 is a schematic flow chart of a dynamic loading method provided in an embodiment of the present application. As shown in FIG6 , the method includes:
[0248] S610: parse one or more target files and save one or more first parsing results.
[0249] It should be understood that the one or more target files may include a first target file, and the first target file may be an executable file or a dynamic library file.
[0250] It should be understood that there may or may not be a dependency relationship between one or more target files, and the embodiments of the present application are not limited to this.
[0251] In an embodiment of the present application, one or more first parsing results correspond to one or more target files. The first parsing result of the first target file (for example, the first dynamic library file) may include the name, path, mapping interval and dependency information of the first target file. Among them, the path of the first target file may indicate the location where the first target file is stored on the disk; the dependency information of the first target file may indicate the dynamic library files that the first target file depends on, including the dynamic library files that the first target file directly depends on and the dynamic library files that it indirectly depends on; the mapping interval of the first target file may indicate the file range that the first target file needs to be mapped to the process address space, that is, the content that the first target file needs to load.
[0252] Optionally, the first target file is a file in a list of files to be parsed, where the files in the list are files that need to be parsed before the first executable file is loaded into the address space of the process where the first executable file is located. In other words, the files in the list are files that need to be pre-parsed.
[0253] It should be noted that the first executable file may be, for example, an executable file of a program loaded in a user process, and the process address space is a memory space allocated by the system to the user process.
[0254] It should be noted that the files in the list of files to be parsed may be files configured by the user or may be default files that need to be pre-parsed.
[0255] It should be noted that one or more target files may be files in the list of files to be parsed or may not be files in the list of files to be parsed. For example, when the second executable file is started, the dynamic loader may need to parse the second executable file and the dynamic library files that the second executable file depends on. In this case, the first parsing result of the second executable file and the first parsing result of the dynamic library files that the second executable file depends on can be saved so that other executable files can find the first parsing result of the dynamic library files they need when loading.
[0256] It should be noted that the first parsing result may be, for example, the format parsing result in the embodiment shown in FIG. 4 , and one or more first parsing results may be saved in the form of a global target file list in the embodiment shown in FIG. 4 .
[0257] Optionally, the one or more target files are parsed in parallel using multiple threads, and one or more first parsing results are saved.
[0258] S620: Search the one or more first parsing results for a first parsing result of a dynamic library file that the first executable file depends on.
[0259] Optionally, in one or more first parsing results, the parsing results of the second dynamic library file and the dynamic library file on which the second dynamic library file depends are searched, where the second dynamic library file is the designated dynamic library file requested to be loaded by the process where the first executable file is located; based on the parsing results of the second dynamic library file and the dynamic library file on which the second dynamic library file depends, the second dynamic library file and the dynamic library file on which the second dynamic library file depends are mapped to the process address space.
[0260] Optionally, if the first parsing result of the dynamic library file that the first executable file depends on does not exist, the first executable file is parsed, and the first parsing result of the first executable file and the first parsing result of the dynamic library file that the first executable file depends on are saved; and / or, if the parsing result of the second dynamic library file does not exist, the second dynamic library file is parsed, and the first parsing result of the second dynamic library file and the first parsing result of the dynamic library file that the second dynamic library file depends on are saved.
[0261] S630: Map the dynamic library file that the first executable file depends on to the process address space where the first executable file is located according to the first parsing result of the dynamic library file that the first executable file depends on.
[0262] Optionally, the one or more target files may include a first dynamic library file, and the first executable file depends on the first dynamic library file. The first dynamic library file is obtained according to a path of the first dynamic library file; and the first dynamic library file is mapped to the process address space according to a mapping interval of the first dynamic library file.
[0263] Optionally, the dynamic library files that the first executable file depends on include a third dynamic library file and a fourth dynamic library file, wherein the first thread maps the third dynamic library file to the process address space where the first executable file is located based on the first parsing result of the third dynamic library file; the second thread maps the fourth dynamic library file to the process address space based on the first parsing result of the fourth dynamic library file, and the first thread and the second thread are different.
[0264] Optionally, one or more target files are parsed and information of one or more symbols is saved, where the one or more symbols are symbols defined in the one or more target files, and the one or more symbols include a first symbol, and the information of the first symbol includes the name of the target file to which the first symbol belongs and the location information of the first symbol in the target file to which the first symbol belongs.
[0265] Optionally, after mapping the dynamic library file that the first executable file depends on to the process address space where the first executable file is located, information of the second symbol is searched in information of one or more symbols, and the information of the second symbol is used to relocate the second symbol.
[0266] Optionally, according to the information of the second symbol, the address of the second symbol in the process address space is obtained; and according to the address of the second symbol in the process address space, the second symbol is relocated.
[0267] Optionally, when the first executable file and the dynamic library file on which the first executable file depends are not in the parsed file list, the first executable file and the dynamic library file on which the first executable file depends are parsed, and information about symbols defined in the first executable file and the dynamic library file on which the first executable file depends is saved. The parsed file list is used to store the names of the parsed executable files or dynamic library files.
[0268] Optionally, use multiple threads to parse one or more object files in parallel and save information about one or more symbols.
[0269] In an embodiment of the present application, when parsing a target file, the first parsing result of the target file can be saved. These first parsing results will be used in the dynamic library loading process, thereby decoupling the target file parsing process and the loading process, which is beneficial to optimizing the application startup speed and improving the user experience. On the other hand, the first parsing result of a target file can be used in the loading process of multiple different executable files, thereby realizing the sharing of one or more first parsing results, which is beneficial to saving computing resources and memory space.
[0270] FIG7 is a schematic flow chart of a dynamic loading method provided by an embodiment of the present application. As shown in FIG7 , the method includes:
[0271] S710: Parse one or more target files and save information of one or more symbols.
[0272] It should be understood that the one or more target files may include a first target file, and the first target file may be an executable file or a dynamic library file.
[0273] It should be understood that there may or may not be a dependency relationship between one or more target files, and the embodiments of the present application are not limited to this.
[0274] In an embodiment of the present application, one or more symbols are symbols defined in one or more target files, including all symbols defined in each target file.
[0275] It should be noted that the first executable file may be, for example, an executable file of a program loaded in a user process, and the process address space is a memory space allocated by the system to the user process.
[0276] It should be noted that the information of each symbol may be, for example, the symbol parsing result in the embodiment shown in FIG. 4 , and the information of one or more symbols may be stored in the form of a global symbol table in the embodiment shown in FIG. 4 .
[0277] Optionally, the first target file is a file in a list of files to be parsed, where the files in the list are files that need to be parsed before the first executable file is loaded into the address space of the process where the first executable file is located. In other words, the files in the list are files that need to be pre-parsed.
[0278] It should be noted that the files in the list of files to be parsed may be files configured by the user or may be default files that need to be pre-parsed.
[0279] It should be noted that the one or more target files may be files in the list of files to be parsed, or may not be files in the list of files to be parsed.
[0280] Optionally, use multiple threads to parse one or more object files in parallel and save information about one or more symbols.
[0281] S720: Search for information of a second symbol in the information of the one or more symbols, where the information of the second symbol is used to relocate the second symbol.
[0282] It should be noted that the second symbol is a symbol in the relocation table of the dynamic library file that the first executable file depends on. The relocation table records the symbols that need to be relocated in the dynamic library file that the first executable file depends on.
[0283] Optionally, based on the information of the second symbol, an address of the second symbol in the process address space where the first executable file is located is obtained; and based on the address of the second symbol in the process address space, the second symbol is relocated.
[0284] Optionally, when the first executable file or the dynamic library file that the first executable file depends on is not in the resolved file list, the first executable file and the dynamic library file that the first executable file depends on are parsed, and information about symbols defined in the first executable file and the dynamic library file that the first executable file depends on is saved. The resolved file list is used to store the name of the resolved executable file or dynamic library file.
[0285] In some embodiments, since the global target file list records information of all resolved files, the global target file list can be used as the resolved file list.
[0286] In an embodiment of the present application, when file target is parsed, the information of the symbol defined in the file target can be preserved. In an embodiment of the present application, when file target is parsed, the information of the symbol defined in the file target can be preserved. When symbol to be relocated is relocated, the position of symbol to be relocated in the process address space can be found quickly, thereby accelerating the relocation process, helping to optimize the application startup speed, helping to promote the user's experience. On the other hand, the information of one or more symbols can be used in the relocation process of a plurality of different executable files, thereby realizing the sharing of the information of these one or more symbols, helping to save computing resources, helping to save memory space.
[0287] Figure 8 is a schematic diagram of the hardware structure of an apparatus 800 provided in an embodiment of the present application. The apparatus 800 shown in Figure 8 (which may be an electronic device) includes a memory 810, a processor 820, a communication interface 830, and a bus 840. The memory 810, the processor 820, and the communication interface 830 are connected to each other via the bus 840.
[0288] The memory 810 may be a ROM, a static storage device, a dynamic storage device or a RAM. The memory 810 may store programs. When the program stored in the memory 810 is executed by the processor 820, the processor 820 is used to perform each step of the dynamic loading method of the embodiment of the present application.
[0289] The processor 820 can adopt a general-purpose CPU, microprocessor, ASIC, GPU or one or more integrated circuits to execute relevant programs to implement the functions required to be performed by the units in the device 800 of the embodiment of the present application, or to execute the dynamic loading method of the method embodiment of the present application.
[0290] The processor 820 may also be an integrated circuit chip with signal processing capabilities. During implementation, the various steps of the dynamic loading method of the present application may be performed by hardware integrated logic circuits or software instructions within the processor 820. The processor 820 may also be a general-purpose processor, a DSP, an ASIC, an FPGA, or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application may be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules within the decoding processor. The software modules may be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. The storage medium is located in the memory 810. The processor 820 reads the information within the memory 810 and, in conjunction with its hardware, performs the functions required to be performed by the units included in the apparatus 800 of the embodiments of the present application, or performs the dynamic loading method of the method embodiments of the present application.
[0291] The communication interface 830 uses a transceiver device such as, but not limited to, a transceiver to implement communication between the apparatus 800 and other devices or a communication network.
[0292] The bus 840 may include a path for transmitting information between the various components of the device 800 (eg, the memory 810 , the processor 820 , and the communication interface 830 ).
[0293] It should be noted that although the device 800 shown in FIG8 only shows a memory, a processor, and a communication interface, during the specific implementation process, those skilled in the art will understand that the device 800 also includes other components necessary for normal operation. At the same time, according to specific needs, those skilled in the art will understand that the device 800 may also include hardware components that implement other additional functions. In addition, those skilled in the art will understand that the device 800 may also include only the components necessary to implement the embodiments of the present application, and does not necessarily include all the components shown in FIG8.
[0294] An embodiment of the present application also provides a chip, which includes a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the dynamic loading method described in any possible implementation method described above is executed.
[0295] This embodiment further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are run on a computer, the dynamic loading method in the above embodiment is executed.
[0296] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps, so that the dynamic loading method in the above-mentioned embodiment is executed.
[0297] The above embodiments can be used alone or in combination with each other to achieve different technical effects.
[0298] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel 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.
[0299] In this embodiment, the electronic device can be divided into functional modules according to the above-mentioned method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into a single processing module. The above-mentioned integrated modules can be implemented in the form of hardware. It should be noted that the module division in this embodiment is illustrative and is only a logical functional division. In actual implementation, other division methods may be used.
[0300] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0301] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0302] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0303] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0304] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0305] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A method for dynamic loading, characterized in that: include: Parsing one or more target files and saving one or more first parsing results, wherein the one or more first parsing results correspond to the one or more target files one by one, the one or more target files include a first target file, and the first target file is an executable file or a dynamic library file; Searching the one or more first parsing results for a first parsing result of a dynamic library file that the first executable file depends on; According to a first parsing result of the dynamic library file that the first executable file depends on, the dynamic library file that the first executable file depends on is mapped to a process address space where the first executable file is located.
2. The method according to claim 1, characterized in that The one or more target files include a first dynamic library file, and the first parsing result includes a path, a mapping interval, and dependency information of the first dynamic library file.
3. The method according to claim 2, characterized in that The dynamic library file that the first executable file depends on includes the first dynamic library file, The mapping of the dynamic library file that the first executable file depends on to the process address space where the first executable file is located according to the first parsing result of the dynamic library file that the first executable file depends on includes: According to the path of the first dynamic library file, obtaining the first dynamic library file; Map the first dynamic library file to the process address space according to the mapping interval of the first dynamic library file.
4. The method according to any one of claims 1 to 3, characterized in that The first target file is a file in a list of files to be parsed, and the files in the list of files to be parsed are files that need to be parsed before the first executable file is loaded into the process address space.
5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: Searching for a first parsing result of a second dynamic library file and a dynamic library file on which the second dynamic library file depends from among the one or more first parsing results, wherein the second dynamic library file is a designated dynamic library file requested to be loaded by the process where the first executable file is located; According to the first parsing result of the second dynamic library file and the dynamic library file on which the second dynamic library file depends, the second dynamic library file and the dynamic library file on which the second dynamic library file depends are mapped to the process address space.
6. The method according to claim 5, characterized in that The method further comprises: If the first parsing result of the dynamic library file that the first executable file depends on is not found, the first executable file is parsed, and the first parsing result of the first executable file and the first parsing result of the dynamic library file that the first executable file depends on are saved; and / or, If the first parsing result of the second dynamic library file is not found, the second dynamic library file is parsed, and the first parsing result of the second dynamic library file and the first parsing result of the dynamic library file on which the second dynamic library file depends are saved.
7. The method according to any one of claims 1 to 6, characterized in that The step of parsing one or more target files and saving one or more first parsing results includes: The one or more target files are parsed in parallel using multiple threads, and the one or more first parsing results are saved.
8. The method according to claim 1, characterized in that The dynamic library files that the first executable file depends on include a third dynamic library file and a fourth dynamic library file, The mapping of the dynamic library file that the first executable file depends on to the process address space where the first executable file is located according to the first parsing result of the dynamic library file that the first executable file depends on includes: The first thread maps the third dynamic library file to the process address space where the first executable file is located according to the first parsing result of the third dynamic library file; The second thread maps the fourth dynamic library file to the process address space according to the first parsing result of the fourth dynamic library file, and the first thread and the second thread are different.
9. The method according to any one of claims 1 to 8, characterized in that The method further comprises: The one or more target files are parsed and information of one or more symbols is saved, wherein the one or more symbols are symbols defined in the one or more target files, and the one or more symbols include a first symbol, and the information of the first symbol includes the name of the target file to which the first symbol belongs and the position information of the first symbol in the target file to which the first symbol belongs.
10. The method according to claim 9, characterized in that The dynamic library file that the first executable file depends on includes a fifth dynamic library file, and the relocation table of the fifth dynamic library file includes a second symbol. The method further includes: After mapping the dynamic library file that the first executable file depends on to the process address space where the first executable file is located, searching for information of the second symbol in the information of the one or more symbols, the information of the second symbol is used to relocate the second symbol.
11. The method according to claim 10, characterized in that The method further comprises: According to the information of the second symbol, acquiring the address of the second symbol in the process address space; Relocate the second symbol according to the address of the second symbol in the process address space.
12. The method according to any one of claims 9 to 11, characterized in that: The method further comprises: When the first executable file and the dynamic library file on which the first executable file depends are not in the resolved file list, the first executable file and the dynamic library file on which the first executable file depends are resolved, and information about symbols defined in the first executable file and the dynamic library file on which the first executable file depends is saved. The resolved file list is used to store the names of the resolved executable files or dynamic library files.
13. The method according to any one of claims 9 to 12, characterized in that: The parsing of the one or more target files and saving information of one or more symbols includes: The one or more object files are parsed in parallel using multiple threads, and information of the one or more symbols is saved.
14. A method for dynamic loading, characterized in that: include: Parsing one or more target files and saving information of one or more symbols, wherein the one or more symbols are symbols defined in the one or more target files, the one or more symbols include a first symbol, the information of the first symbol includes a name of the target file to which the first symbol belongs and position information of the first symbol in the target file to which the first symbol belongs, the one or more target files include the first target file, and the first target file is an executable file or a dynamic library file; The information of the second symbol is searched in the information of the one or more symbols, where the second symbol is a symbol in a relocation table of a dynamic library file that the first executable file depends on, and the information of the second symbol is used to relocate the second symbol.
15. The method according to claim 14, characterized in that The method further comprises: According to the information of the second symbol, acquiring the address of the second symbol in the process address space where the first executable file is located; Relocate the second symbol according to the address of the second symbol in the process address space.
16. The method according to claim 14 or 15, characterized in that The first target file is a file in a list of files to be parsed, and the files in the list of files to be parsed are files that need to be parsed before the first executable file is loaded into the process address space.
17. The method according to any one of claims 14 to 16, characterized in that: The method further comprises: When the first executable file or the dynamic library file on which the first executable file depends is not in the resolved file list, the first executable file and the dynamic library file on which the first executable file depends are parsed, and information about symbols defined in the first executable file and the dynamic library file on which the first executable file depends is saved. The resolved file list is used to store the names of the resolved executable files or dynamic library files.
18. The method according to any one of claims 14 to 17, characterized in that: The parsing of the one or more target files and saving information of one or more symbols includes: The one or more object files are parsed in parallel using multiple threads, and information of the one or more symbols is saved.
19. An electronic device, characterized in that: The method comprises one or more processors; one or more memories; the one or more memories store one or more computer programs, the one or more computer programs include instructions, and when the instructions are executed by the one or more processors, the method as claimed in any one of claims 1 to 13 is executed, or the method as claimed in any one of claims 14 to 18 is executed.
20. A chip, characterized in that: The chip includes a processor and a communication interface, wherein the communication interface is used to receive a signal and transmit the signal to the processor, and the processor processes the signal so that the method as described in any one of claims 1 to 13 is executed, or the method as described in any one of claims 14 to 18 is executed.
21. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a computer, the method according to any one of claims 1 to 13 is executed, or the method according to any one of claims 14 to 18 is executed.
22. A computer program product comprising instructions, characterized in that When the computer program product is executed on a computer, the computer is enabled to execute the method according to any one of claims 1 to 13, or execute the method according to any one of claims 14 to 18.
Citation Information
Patent Citations
Dynamic loading method and electronic equipment
CN119225840A
Embedded real-time operating system dynamic loading method
CN107122216A
Dynamic loading method and device and target file manufacturing method and device
CN109814939A
Automatic servitization packaging method and system for a dynamic library, and application
CN111459489A
Code loading method, code loading device, storage medium and electronic equipment
CN114443174A
Cited By
Distributed industrial personal computer based on OpenHarmony system and data collaboration method thereof
CN121092340A