Method and apparatus for processing shared objects in an operating system

By generating and managing dependency files and dynamically installing and uninstalling shared objects, the problem of memory consumption and cumbersome version upgrades caused by static linking in the NuttX embedded operating system is solved, enabling flexible management and memory saving of shared objects.

CN115994003BActive Publication Date: 2026-02-03BEIJING ESWIN COMPUTING TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310126585.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-16
Publication Date
2026-02-03
Estimated Expiration
2043-02-16

AI Technical Summary

Technical Problem

The NuttX embedded operating system only supports statically linked REL files, which increases disk and memory consumption, makes application version upgrades cumbersome, and cannot achieve dynamic linking shared object management.

Method used

It generates shared objects and the current application image, records the shared objects that the application image depends on through a dependency file, generates a file system and mounts it when the operating system starts, parses the dependency file and installs the shared objects into memory, and unloads unused shared objects after running, thus achieving dynamic management.

Benefits of technology

It simplifies the use of shared objects, reduces operating system memory consumption, and improves the flexibility and simplicity of operating system firmware expansion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115994003B_ABST
    Figure CN115994003B_ABST
Patent Text Reader

Abstract

The present disclosure provides a processing method and processing device for shared objects in an operating system, electronic equipment and computer readable medium, the method comprising: generating shared objects and a current application image; obtaining shared objects relied on by the current application image from the generated shared objects to generate a dependency file corresponding to the current application image; generating a file system according to the shared objects, the current application image and the dependency file, and mounting the file system on an operating system node when the operating system starts; parsing the dependency file before running the current application image, and sequentially installing the shared objects recorded in the dependency file to the memory where the current application image is located; and uninstalling the shared objects recorded in the dependency file from the memory after the current application image ends running.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of embedded operating system technology, and in particular to a method and apparatus for processing shared objects in an operating system, an electronic device, and a computer-readable medium. Background Technology

[0002] In an operating system, an application can be represented as a relocatable (REL) file. A REL file typically contains code, data, and relocation information with undetermined addresses. Based on the relocation information in the REL file, it can be dynamically loaded and executed at any address. After the REL file is loaded into memory and its code and data are relocated, the code and data in the REL file will have defined addresses. REL files can be used to easily extend the released operating system firmware.

[0003] In operating systems, REL files are primarily linked statically and dynamically. When a REL file is statically linked from intermediate object files and static libraries, multiple REL files will contain duplicate code, which undoubtedly increases disk and memory consumption. Furthermore, static linking hinders the updating of modules or libraries that applications depend on (such as memory-related or network-related modules or libraries). If a module or library that an application depends on needs updating (e.g., a function in a network library needs to be changed), then all applications need to be compiled and linked again with the latest module or library to generate the final application. Therefore, when some code is modified, the entire REL file needs to be relinked, making application version upgrades cumbersome. Dynamic linking separates the REL file from shared objects (shared libraries). Shared objects are loaded when the REL file is run, so only one copy of the shared object code resides on disk and in memory, and shared objects can be upgraded without modifying the REL file.

[0004] In related technologies, NuttX is a real-time embedded operating system (RTOS) and one of the mainstream embedded operating systems on the market. However, its support for firmware extensions is limited to statically linked REL files and does not support dynamic linking. Therefore, when you want to extend the operating system firmware, you can only use statically linked REL files, which undoubtedly increases the consumption of disk and memory space. Summary of the Invention

[0005] This disclosure provides a method and apparatus for processing shared objects in an operating system, an electronic device, and a computer-readable medium.

[0006] In a first aspect, embodiments of this disclosure provide a method for processing shared objects in an operating system, including:

[0007] Generate a shared object and the current application image;

[0008] Obtain the shared objects that the current application image depends on from the generated multiple shared objects, and generate the dependency files corresponding to the current application image;

[0009] A file system is generated based on the multiple shared objects, the current application image, and the dependent files, and the file system is mounted to the operating system node when the operating system starts.

[0010] Before running the current application image, the dependency files are parsed, and the shared objects recorded in the dependency files are installed into the memory where the current application image is located in turn.

[0011] After the current application image finishes running, the shared objects recorded in the dependency files are unloaded from memory.

[0012] In some embodiments, the shared object is in an executable and linkable format, the shared object is of a relocatable type, and the current application image is in a relocatable format.

[0013] In some embodiments, the shared object includes a symbol array and an initialization function, the symbol array containing at least one symbol; the step of generating the shared object includes:

[0014] The multiple source code files in the source code to be processed are compiled into the first target file respectively, and the first target files corresponding to the multiple source code files are linked to obtain the initial shared object;

[0015] Symbols are extracted from the initial shared object, and the symbols in the initial shared object are written into a symbol array in a preset symbol file, wherein the symbol array is used to record the symbols in the initial shared object;

[0016] Generate an initialization function corresponding to the initial shared object based on the symbol array and the number of symbols in the symbol array;

[0017] The symbol array and the initialization function are compiled into their respective second object files;

[0018] The second target file corresponding to the symbol array and the second target file corresponding to the initialization function are linked with the initial shared object to generate the shared object.

[0019] In some embodiments, the step of obtaining the shared objects that the current application image depends on from a plurality of generated shared objects to generate the dependency files corresponding to the current application image includes:

[0020] Extract undefined symbols from the current application image;

[0021] Compare the undefined symbol with the symbol in each shared object;

[0022] Record the names of the shared objects that match the comparison results in the dependency file corresponding to the current application image.

[0023] In some embodiments, prior to the step of parsing the dependency files, the processing method further includes: loading the current application image into the memory;

[0024] After the step of sequentially installing the shared objects recorded in the dependency files into the memory where the current application image resides, the processing method further includes:

[0025] Relocate the current application image in the memory;

[0026] After the relocation is complete, a task is created to create the current application image and then run the current application image.

[0027] In some embodiments, after the current application image finishes running and before unloading the shared objects recorded in the dependency file from the memory, the processing method further includes:

[0028] Determine whether the shared object recorded in the dependency file is currently being used by other application images;

[0029] If the shared object recorded in the dependency file is not currently used by other application images, then the step of unloading the shared object recorded in the dependency file from memory is executed.

[0030] Secondly, embodiments of this disclosure provide a processing apparatus for shared objects in an operating system, comprising:

[0031] The generation unit is configured to generate shared objects and the current application image;

[0032] The recording unit is configured to obtain the shared objects that the current application image depends on from a plurality of generated shared objects, so as to generate the dependency files corresponding to the current application image;

[0033] The mounting unit is configured to generate a file system based on the multiple shared objects, the current application image, and the dependent files, and mount the file system to the operating system node when the operating system starts.

[0034] The installation unit is configured to parse the dependency files before running the current application image, and sequentially install the shared objects recorded in the dependency files into the memory where the current application image is located.

[0035] The unloading unit is configured to unload the shared objects recorded in the dependency files from memory after the current application image finishes running.

[0036] In some embodiments, the recording unit is configured to:

[0037] Extract undefined symbols from the current application image;

[0038] Compare the undefined symbol with the symbol in each shared object;

[0039] Record the names of the shared objects that match the comparison results in the dependency file corresponding to the current application image.

[0040] In some embodiments, the processing apparatus further includes a determination unit, which is configured to determine, after the current application image finishes running, whether the shared object recorded in the dependency file is currently being used by other application images;

[0041] The unloading unit is configured to unload the shared object recorded in the dependency file from memory if the shared object recorded in the dependency file is not currently used by other application images.

[0042] Thirdly, embodiments of this disclosure provide an electronic device, including:

[0043] At least one processor; and

[0044] A memory communicatively connected to the at least one processor; wherein,

[0045] The memory stores one or more computer programs that can be executed by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the processing method as described in the first aspect.

[0046] Fourthly, embodiments of this disclosure provide a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the processing method as described in the first aspect.

[0047] In this embodiment of the disclosure, the method for handling shared objects in the operating system is used to manage shared objects in the operating system. When compiling the application, the shared objects that the application image depends on are recorded through a dependency file. This allows the shared objects to be automatically installed and uninstalled according to the usage of the shared objects by the application image, without requiring the coders to install them manually. This makes the use of shared objects simpler and more flexible, facilitating the expansion of the operating system firmware. It also makes expanding the operating system firmware simpler and more flexible, and can effectively reduce the consumption of operating system memory and save operating system memory space. Attached Figure Description

[0048] Figure 1 A flowchart illustrating a method for handling shared objects in an operating system, provided for at least one embodiment of this disclosure;

[0049] Figure 2 This is a flowchart illustrating one method of generating a shared object according to an embodiment of the present disclosure;

[0050] Figure 3 This is a flowchart illustrating one method of generating dependency files according to an embodiment of the present disclosure;

[0051] Figure 4 This is a block diagram of a processing apparatus for shared objects in an operating system, provided for at least one embodiment of the present disclosure. Detailed Implementation

[0052] The following describes in detail, with reference to the accompanying drawings, the method and apparatus for processing shared objects in the operating system provided in this disclosure, electronic equipment, and computer-readable medium.

[0053] The present disclosure will be described more fully below with reference to the accompanying drawings; however, the embodiments shown may be embodied in different forms and should not be construed as being limited to the embodiments set forth in this disclosure. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will enable those skilled in the art to fully understand the scope of this disclosure.

[0054] This disclosure may be described with reference to plan and / or cross-sectional views using the ideal schematic diagrams of this disclosure. Therefore, the example illustrations may be modified according to manufacturing techniques and / or tolerances.

[0055] Where there is no conflict, the various embodiments of this disclosure and the features thereof in the embodiments may be combined with each other.

[0056] The terminology used in this disclosure is for describing particular embodiments only and is not intended to limit the disclosure. The term "and / or" as used in this disclosure includes any and all combinations of one or more of the associated enumerated entries. The singular forms "a" and "the" as used in this disclosure are also intended to include the plural forms, unless the context clearly indicates otherwise. The term "comprising" as used in this disclosure specifies the presence of the stated feature, integral, step, operation, element, and / or component, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof.

[0057] Unless otherwise specified, all terms used in this disclosure (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this disclosure, and will not be interpreted as having an idealized or overly formal meaning, unless expressly so defined in this disclosure.

[0058] In related technologies, although NuttX supports shared objects, there are certain limitations to the use of shared objects. Coders need to know in advance which shared objects the application uses and code the use of shared objects in the source code. The use of shared objects is not convenient or flexible.

[0059] This disclosure provides a method and apparatus for processing shared objects in an operating system, which aims to effectively solve the technical problems existing in related technologies.

[0060] In a first aspect, embodiments of this disclosure provide a method for processing shared objects in an operating system.

[0061] Figure 1 This illustration shows an optional implementation of the method for handling shared objects in an operating system provided in an embodiment of this disclosure. For example... Figure 1 As shown, the method for handling shared objects in the operating system of this disclosure includes:

[0062] Step S11: Generate shared objects and the current application image.

[0063] In this embodiment of the disclosure, the operating system may be an embedded operating system, such as the Nuttx embedded operating system, the shared object refers to the shared library in the operating system, that is, the library or module ending with ".so" in the operating system, and the application image refers to the application program (APP).

[0064] In this embodiment of the disclosure, shared objects can be obtained and generated based on the source code of the operating system, and the current application image can be generated based on the source code of the application (APP) to be loaded.

[0065] Step S12: Obtain the shared objects that the current application image depends on from the multiple generated shared objects, so as to generate the dependency files corresponding to the current application image.

[0066] The shared objects that the current application image depends on are the shared objects required for the normal loading of the current application image. The dependency file contains information about the shared objects that the current application image depends on, such as the name of the shared object. The dependency file can be in ROMFS format, where the file content records the name of the shared objects that the current application image depends on. ROMFS is a relatively simple read-only file system that occupies less space.

[0067] Step S13: Generate a file system based on multiple shared objects, the current application image, and dependent files, and mount the file system to the operating system node when the operating system starts.

[0068] The generated shared objects, the current application image, and dependent files are integrated into the file system, which is the method and data structure used by the operating system to define files on storage devices (commonly disks, but also solid-state drives based on NAND Flash) or partitions.

[0069] Mounting is a process by which the operating system makes computer files and directories on a storage device (such as a hard drive, CD-ROM, or shared resource) accessible to users through the computer's file system.

[0070] An operating system node is a device node in the operating system. For the operating system, all I / O resources are files, including files, directories, hard drives, devices, etc. In the operating system, all devices are usually stored as files in the " / dev" directory and are usually accessed through files. The " / dev" directory records the location and information of hardware devices. A device node is an abstraction of a device by the operating system kernel. That is, the operating system abstracts a device as a file. A device node is a file. Applications usually access devices through a set of standardized calls. The device node is the bridge between the application and the device driver.

[0071] When the operating system starts, a file system containing shared objects, the current application image, and dependent files is mounted onto the operating system node so that the current application image can be run when the operating system runs.

[0072] Step S14: Before running the current application image, parse the dependency files and install the shared objects recorded in the dependency files into the memory where the current application image is located.

[0073] The `open` function can be used to open the dependency file and obtain the names of the shared objects that the current application image depends on. This allows you to determine the shared objects that the current application image depends on and install their program code sequentially into the memory where the current application image resides. The memory where the current application image resides is the operating system's memory.

[0074] Before running the current application image, the shared objects that the current application image depends on are installed into the memory where the current application image is located, so that the current application image can be relocated and run normally in the future.

[0075] Step S15: After the current application image finishes running, unload the shared objects recorded in the dependency files from memory.

[0076] After the current application image finishes running, the shared objects recorded in the dependency files are unloaded from memory, thereby reducing the consumption of operating system memory and saving operating system memory space.

[0077] In this embodiment of the disclosure, the method for handling shared objects in the operating system is used to manage shared objects in the operating system. When compiling the application, the shared objects that the application image depends on are recorded through a dependency file. This allows the shared objects to be automatically installed and uninstalled according to the usage of the shared objects by the application image, without requiring the coders to install them manually. This makes the use of shared objects simpler and more flexible, which facilitates the expansion of the operating system firmware, makes the expansion of the operating system firmware simpler and more flexible, and can effectively reduce the consumption of operating system memory and save operating system memory space.

[0078] In this embodiment of the disclosure, the shared object is in Executable and Linkable Format (ELF) format, the shared object type is Relocatable (REL) type, and the current application image is in Relocatable (REL) format. ELF is a file format with two types: one is REL type, which requires a relocation step to run an REL type ELF file; the other is a directly executable type, which does not require a relocation step to run an ELF file.

[0079] In some embodiments, the shared object includes a symbol array and an initialization function. The symbol array contains at least one symbol, which represents a function or variable in the shared object, such as the summation function add(a, b) and the difference function sub(a, b), where a and b represent variables in the function. Figure 2 This is a flowchart illustrating one method of generating shared objects according to an embodiment of the present disclosure. In some embodiments, such as... Figure 2 As shown, in step S11, the step of generating the shared object may further include:

[0080] Step S21: Compile multiple source code files in the source code to be processed into first target files respectively, and link the first target files corresponding to the multiple source code files to obtain the initial shared object.

[0081] The source code to be processed is divided into multiple independent modules according to their functions. Each module is a source code file. For example, the part related to the network is a module, and the graphics display is a module. The functions of different modules are different. One is related to the network, and the other is the graphics display of the screen.

[0082] In step S21, a compiler can be used to compile multiple source code files in the source code to be processed into first object files, with each source code file corresponding to one first object file. Then, a linker is used to link the first object files corresponding to the multiple source code files to generate an initial shared object. The source code files are C files with the ".c" extension. The compiler compiles the ".c" source code files into object files with the ".o" extension, and the linker links the multiple object files with the ".o" extension to generate an initial shared object in ELF format. The ".o" file is an object file, i.e., an executable file, a type of retargetable file, and is usually saved in ELF format.

[0083] Specifically, the linker can combine multiple first object files according to the linker script to generate an initial shared object in ELF format, where the first object files contain link addresses indicating the storage location of sections in the first object files.

[0084] Step S22: Extract symbols from the initial shared object and write the symbols in the initial shared object into a symbol array in a preset symbol file. The symbol array is used to record the symbols in the initial shared object.

[0085] The GCC (GNU Compiler Collection) tool riscv-unknown-elf-nm can be used to extract a symbol table from the initial shared object. The symbol table records the symbols in the initial shared object and writes the symbols in the initial shared object to a preset symbol file. The symbol file is a C file that stores the symbol names of the initial shared object and records the symbols in the initial shared object through a symbol array.

[0086] Step S23: Generate the initialization function corresponding to the initial shared object based on the symbol array and the number of symbols in the symbol array.

[0087] A shell script can be used to assign the pointer to the symbol array of the generated initial shared object to the pointer to the symbol structure in the initialization function, and assign the number of symbols of the initial shared object to the symbol data variable in the initialization function, thereby generating an initialization file. The initialization file is a C file and contains the initialization function.

[0088] Step S24: Compile the symbol array and initialization function into their respective second object files.

[0089] The compiler is used to compile the symbol array and the initialization function separately, generating a second object file with the ".o" suffix.

[0090] Step S25: Link the second target file corresponding to the symbol array and the second target file corresponding to the initialization function with the initial shared object to generate a shared object.

[0091] The linker is used to link the second object file corresponding to the symbol array and the second object file corresponding to the initialization function with the initial shared object, thereby generating the shared object.

[0092] In step S11, the step of generating the current application image may further include: compiling the application's source code using a compiler to generate a third object file with the .o suffix, and linking the third object file using a linker to generate the current application image in REL format.

[0093] Figure 3 This is a flowchart illustrating one method of generating dependency files according to an embodiment of the present disclosure, such as... Figure 3 As shown, in some embodiments, step S12, the step of obtaining the shared objects that the current application image depends on from the generated multiple shared objects to generate the dependency files corresponding to the current application image, may further include:

[0094] Step S31: Extract undefined symbols from the current application image.

[0095] Retrieves undefined (UND) symbols from the current application image. Undefined symbols refer to symbols (i.e., functions or variables) whose addresses are not defined (e.g., address 0) in the current application image, meaning the symbol in which the call is located is not specified.

[0096] Step S32: Compare the undefined symbols with the symbols in each shared object, and record the names of the shared objects that match the comparison results in the dependency file corresponding to the current application image.

[0097] Undefined symbols are compared with symbols in each shared object to determine if they match. This matching process determines whether the undefined symbol exists in a shared object within the current application image, and consequently, identifies the shared objects that the current application image depends on. The names of these shared objects are then recorded in the dependency file corresponding to the current application image. For example, if the current application image contains an undefined symbol A, and symbol A exists in shared object B, then the current application image depends on shared object B.

[0098] In some embodiments, before the step of parsing the dependency files, i.e. before step S14, the processing method may further include: loading the current application image into memory. Then, the dependency files are parsed, and the shared objects recorded in the dependency files are sequentially installed into the memory where the current application image resides.

[0099] In some embodiments, after sequentially installing the shared objects recorded in the dependency files into the memory where the current application image resides, the processing method may further include: relocating the current application image in memory; creating a task for the current application image after the relocation is complete, and running the current application image. In the operating system, running the current application image requires creating a task to manage the current application image.

[0100] Then, after the current application image finishes running, the shared objects recorded in the dependency files are unloaded from memory. In some embodiments, after the current application image finishes running, before unloading the shared objects recorded in the dependency files from memory, the processing method may further include: determining whether the shared objects recorded in the dependency files are currently used by other application images; if the shared objects recorded in the dependency files are not currently used by other application images, then performing the step of unloading the shared objects recorded in the dependency files from memory; if the shared objects recorded in the dependency files are currently used by other application images, then not unloading the shared objects.

[0101] In this embodiment of the disclosure, the shared object has a global variable in the operating system, which can record whether it is used by other modules or other applications (APP). Therefore, it can be determined whether the shared object recorded in the dependency file is currently being used by other application images through this global variable of the shared object.

[0102] Secondly, embodiments of this disclosure provide a processing apparatus for shared objects in an operating system.

[0103] Figure 4 This illustration shows an optional implementation of a processing apparatus for shared objects in an operating system provided in an embodiment of this disclosure. For example... Figure 4 As shown, the processing device 400 for shared objects in the operating system of this embodiment includes: a generation unit 401, a recording unit 402, a mounting unit 403, an installation unit 404, and an unloading unit 405.

[0104] The generation unit 401 is configured to generate shared objects and the current application image; the recording unit 402 is configured to obtain the shared objects that the current application image depends on from the generated shared objects to generate the dependency files corresponding to the current application image; the mounting unit 403 is configured to generate a file system based on the multiple shared objects, the current application image, and the dependency files, and mount the file system to the operating system node when the operating system starts; the installation unit 404 is configured to parse the dependency files before running the current application image and install the shared objects recorded in the dependency files into the memory where the current application image is located in turn; and the unloading unit 405 is configured to unload the shared objects recorded in the dependency files from memory after the current application image finishes running.

[0105] In some embodiments, the shared object includes a symbol array and an initialization function, wherein the symbol array contains at least one symbol; the generation unit 401 is configured to: compile multiple source code files in the source code to be processed into first object files respectively, and link the first object files corresponding to the multiple source code files respectively to obtain an initial shared object; extract symbols from the initial shared object, and write the symbols in the initial shared object into a symbol array in a preset symbol file, wherein the symbol array is used to record the symbols in the initial shared object; generate an initialization function corresponding to the initial shared object according to the symbol array and the number of symbols in the symbol array; compile the symbol array and the initialization function into their respective second object files; link the second object file corresponding to the symbol array and the second object file corresponding to the initialization function with the initial shared object to generate a shared object.

[0106] In some embodiments, the recording unit 402 includes: an extraction subunit configured to extract undefined symbols from the current application image; a comparison subunit configured to compare the undefined symbols with the symbols in each shared object; and a recording subunit configured to record the names of the shared objects that match the comparison results in the dependency file corresponding to the current application image.

[0107] In some embodiments, the processing apparatus 400 further includes a loading unit and a relocation and execution unit, wherein the loading unit is configured to load the current application image into memory before the installation unit 404 parses the dependency files.

[0108] The relocation and execution unit is configured to: after the installation unit 404 installs the shared objects recorded in the dependency files into the memory where the current application image is located, relocate the current application image in memory; after the relocation is completed, create a task for the current application image and run the current application image.

[0109] In some embodiments, the processing device 400 further includes a determination unit, which is configured to determine whether the shared object recorded in the dependency file is currently used by other application images after the current application image finishes running; the unloading unit 405 is configured to perform the step of unloading the shared object recorded in the dependency file from memory if the shared object recorded in the dependency file is not currently used by other application images.

[0110] The processing apparatus provided in this embodiment is used to implement the above processing method. For specific related descriptions, please refer to the relevant descriptions in the above processing method, which will not be repeated here.

[0111] Thirdly, embodiments of this disclosure also provide an electronic device, the electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the above-described processing method.

[0112] Fourthly, embodiments of this disclosure also provide a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the above-described processing method.

[0113] Those skilled in the art will understand that all or some of the steps, systems, and devices disclosed above, as functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0114] In hardware implementations, the division between functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be executed by several physical components working together.

[0115] Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit (CPU), digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software may be distributed on a computer-readable medium, which may include both computer-readable media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer-readable media includes volatile and non-volatile, removable and non-removable media implemented in any method or technique for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer-readable media include, but are not limited to, random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory (FLASH) or other disk storage; read-only optical disc (CD-ROM), digital versatile disc (DVD) or other optical disc storage; magnetic cartridges, magnetic tapes, disk storage or other magnetic storage; and any other media that can be used to store desired information and can be accessed by a computer. Furthermore, as is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0116] This disclosure has disclosed exemplary embodiments, and although specific terminology has been used, it is for general illustrative purposes only and should not be construed as limiting. In some instances, it will be apparent to those skilled in the art that features, characteristics, and / or elements described in connection with particular embodiments may be used alone, or in combination with features, characteristics, and / or elements described in connection with other embodiments, unless otherwise expressly indicated. Therefore, those skilled in the art will understand that various changes in form and detail may be made without departing from the scope of this disclosure as set forth by the appended claims.

Claims

1. A method for handling shared objects in an operating system, characterized in that, include: Generate a shared object and the current application image; Obtain the shared objects that the current application image depends on from the generated multiple shared objects, and generate the dependency files corresponding to the current application image; A file system is generated based on the multiple shared objects, the current application image, and the dependent files, and the file system is mounted to the operating system node when the operating system starts. Before running the current application image, the dependency files are parsed, and the shared objects recorded in the dependency files are installed into the memory where the current application image is located in turn. After the current application image finishes running, the shared objects recorded in the dependency files are unloaded from the memory; The step of obtaining the shared objects that the current application image depends on from the generated multiple shared objects to generate the dependency files corresponding to the current application image includes: Extract undefined symbols from the current application image; Compare the undefined symbol with the symbol in each shared object; Record the names of the shared objects that match the comparison results in the dependency file corresponding to the current application image.

2. The processing method according to claim 1, characterized in that, The shared object is in an executable and linkable format, the shared object is of a relocatable type, and the current application image is in a relocatable format.

3. The processing method according to claim 1, characterized in that, The shared object includes a symbol array and an initialization function, wherein the symbol array contains at least one symbol; the steps for generating the shared object include: The multiple source code files in the source code to be processed are compiled into the first target file respectively, and the first target files corresponding to the multiple source code files are linked to obtain the initial shared object; Symbols are extracted from the initial shared object, and the symbols in the initial shared object are written into a symbol array in a preset symbol file, wherein the symbol array is used to record the symbols in the initial shared object; Generate an initialization function corresponding to the initial shared object based on the symbol array and the number of symbols in the symbol array; The symbol array and the initialization function are compiled into their respective second object files; The second target file corresponding to the symbol array and the second target file corresponding to the initialization function are linked with the initial shared object to generate the shared object.

4. The processing method according to claim 1, characterized in that, Before the step of parsing the dependency files, the processing method further includes: loading the current application image into the memory; After the step of sequentially installing the shared objects recorded in the dependency files into the memory where the current application image resides, the processing method further includes: Relocate the current application image in the memory; After the relocation is complete, a task is created to create the current application image and then run the current application image.

5. The processing method according to claim 1, characterized in that, After the current application image finishes running, and before unloading the shared objects recorded in the dependency files from memory, the processing method further includes: Determine whether the shared object recorded in the dependency file is currently being used by other application images; If the shared object recorded in the dependency file is not currently used by other application images, then the step of unloading the shared object recorded in the dependency file from memory is executed.

6. A processing apparatus for shared objects in an operating system, characterized in that, include: The generation unit is configured to generate shared objects and the current application image; The recording unit is configured to obtain the shared objects that the current application image depends on from a plurality of generated shared objects, so as to generate the dependency files corresponding to the current application image; The mounting unit is configured to generate a file system based on the multiple shared objects, the current application image, and the dependent files, and mount the file system to the operating system node when the operating system starts. The installation unit is configured to parse the dependency files before running the current application image, and sequentially install the shared objects recorded in the dependency files into the memory where the current application image is located. The unloading unit is configured to unload the shared objects recorded in the dependency file from the memory after the current application image finishes running; The recording unit is configured as follows: Extract undefined symbols from the current application image; Compare the undefined symbol with the symbol in each shared object; Record the names of the shared objects that match the comparison results in the dependency file corresponding to the current application image.

7. The processing apparatus according to claim 6, characterized in that, The processing device further includes a judgment unit, which is configured to determine whether the shared object recorded in the dependency file is currently being used by other application images after the current application image finishes running; The unloading unit is configured to unload the shared object recorded in the dependency file from memory if the shared object recorded in the dependency file is not currently used by other application images.

8. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs that can be executed by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the processing method as described in any one of claims 1-5.

9. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the processing method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Dynamic addition of code in shared libraries

    CN108780419A

  • System service dynamic construction method in microkernel operating system

    CN115495158A