CN110659085A - Method and device for overloading limited number of functions in Linux kernel module - Google Patents

Method and device for overloading limited number of functions in Linux kernel module Download PDF

Info

Publication number
CN110659085A
CN110659085A CN201910922723.XA CN201910922723A CN110659085A CN 110659085 A CN110659085 A CN 110659085A CN 201910922723 A CN201910922723 A CN 201910922723A CN 110659085 A CN110659085 A CN 110659085A
Authority
CN
China
Prior art keywords
func
module
functions
function
overloading
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910922723.XA
Other languages
Chinese (zh)
Inventor
连志军
王平江
张锴
张顺林
洪亮
张雪俊
焦明杰
陈曼林
徐慧
魏梦晴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Quanzhou China Robot Co Ltd
Quanzhou Huazhong University Of Science And Technology Institute Of Manufacturing
Original Assignee
Quanzhou China Robot Co Ltd
Quanzhou Huazhong University Of Science And Technology Institute Of Manufacturing
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Quanzhou China Robot Co Ltd, Quanzhou Huazhong University Of Science And Technology Institute Of Manufacturing filed Critical Quanzhou China Robot Co Ltd
Priority to CN201910922723.XA priority Critical patent/CN110659085A/en
Publication of CN110659085A publication Critical patent/CN110659085A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention belongs to the technical field of Linux operating systems, and particularly relates to a method and a device for overloading a limited number of functions in a Linux kernel module. By means of the function to be realized with ambiguity, a plurality of CASEs are distributed in the main control program, each CASE is defined in different expansion modules, a function symbol table is simultaneously exported outwards, and a specific expansion function module is loaded according to needs, so that function overloading is flexibly realized. According to the method, the virtual modules are loaded at the end of all modules, functions derived from all the expansion modules are defined in the virtual modules, but all the functions are realized to be null and directly return, and the virtual module loading is to avoid kernel loading failure caused by undefined external symbols existing due to the fact that some modules are not loaded.

Description

Method and device for overloading limited number of functions in Linux kernel module
Technical Field
The invention belongs to the technical field of Linux operating systems, and particularly relates to a method and a device for overloading a limited number of functions in a Linux kernel module.
Background
In the development of a Linux kernel module, the Linux kernel module is mainly based on a C language, but the Linux kernel module often relates to the ambiguity of functions, namely a function name has multiple specific implementations, and different expansion functions are realized. However, in kernel module development, the C language can support function reloading unlike C + +, and cannot be realized by different functions. It is very inconvenient to flexibly implement a specific function. When the program main module only calls the same function to realize different expansion functions, the different expansion functions can be written in a plurality of target files, but because the same function definition is contained in the plurality of target files, the redefinition error of the symbol table occurs when the target files are linked, and the reloading of the function cannot be realized.
For symbol conflicts between the dynamic library and the dynamic library, the principle of the loader is breadth-first (BFS), namely, a main program is loaded firstly, then all the main programs are loaded to explicitly depend on all the dynamic libraries, and then the dynamic libraries which the dynamic libraries depend on are loaded until all the dynamic libraries are loaded. When two dynamic libraries are loaded, if functions with the same name exist, only the first loaded function takes effect, namely all calls to the function point to the function in the first loaded dynamic library, and no method is available for deriving function reloading.
Disclosure of Invention
Aiming at the prior art, the invention provides a method and a device for realizing the overloading of a limited number of functions in a kernel module under a Linux operating system, which can realize the overloading of the functions and load different expansion modules according to the requirements, so that the functions of a program can be cut and combined flexibly.
The invention adopts the following technical scheme:
a method for reloading a limited number of functions in a Linux kernel module comprises the following steps,
s1, calling a func () function in the program main module, wherein the func () function has a plurality of different specific implementations, and after the program source code is compiled and linked once, the specific implementations are freely selected without compiling the source code. And calling func () functions in the program main module, wherein the func () functions are divided into a plurality of cases and respectively call func _0(), func _1(), … and func _ n ().
S2 and the expansion modules A, B, …, and Max respectively define specific implementations of func _0(), func _1(), …, and func _ n () functions, and EXPORT the functions func _0(), func _1(), …, and func _ n () through an exit _ SYMBOL.
And S3, loading the extended function module and linking the extended function module and the program main module together, wherein the program main module can find the corresponding realization of the function func () when linking, thereby realizing the overloading of a limited number of functions in the kernel module. And loading the corresponding expansion module as required during actual running, wherein when the program is loaded, the dynamic link device of the system loads the dynamic link library required by the program into the address space of the process, and binds all unresolved symbols into the corresponding dynamic link library for relocation.
The technical scheme further comprises a virtual module, wherein functions derived from all the expansion modules are defined in the virtual module, all the functions are realized to be null and directly return, and the virtual module is loaded at the last of all the modules, so that the phenomenon that kernel loading fails due to the existence of undefined external symbols because some modules are not loaded is avoided.
In the step S3, different numbers of expansion modules are loaded according to the actual function implementation requirement. According to the actual function implementation requirements, a specific expansion module is loaded, a limited number of expansion modules can be loaded simultaneously, and only some expansion modules can be loaded. The overloading and flexible combination of the specific function in the kernel module are realized.
An apparatus for overloading a limited number of functions in a Linux kernel module comprises,
a program main module, configured to call a func () function, where the func () function is divided into multiple cases, and call func _0(), func _1(), …, and func _ n ();
the expanding module is used for defining the specific implementation of func _0(), func _1(), … and func _ n () functions and exporting the functions func _0(), func _1(), … and func _ n () through EXPORT _ SYMBOL;
and the extension function module is loaded and linked with the program main module together, the program main module is operated to load the corresponding extension module, the corresponding realization of the function func () is found, and the function overloading with limited quantity in the kernel module is realized.
The further optimization of the technical scheme also comprises a virtual module, wherein functions derived from all the expansion modules are defined in the virtual module, but all the functions are realized to be null and directly return, and the virtual module is loaded at the end of all the modules.
According to the technical scheme, further optimization is achieved, when the program main module runs, different numbers of expansion modules are loaded according to actual function implementation requirements.
The invention divides various CASEs in the main control program through the function to realize the ambiguity, each CASE is defined in different expansion modules, a function symbol table is simultaneously exported outwards, and a specific expansion function module is loaded according to the requirement, thereby flexibly realizing function overloading.
Drawings
FIG. 1 is a flow chart of a method for overloading a limited number of functions in a Linux kernel module;
FIG. 2 is a flow chart of a method implemented by the single channel robot control system;
FIG. 3 is a flow chart of a multi-channel robot control system forward and inverse solution module intelligent configuration method;
FIG. 4 is a diagram of a device architecture for overloading a limited number of functions in a Linux kernel module.
Detailed Description
To further illustrate the various embodiments, the invention provides the accompanying drawings. The accompanying drawings, which are incorporated in and constitute a part of this disclosure, illustrate embodiments of the invention and, together with the description, serve to explain the principles of the embodiments. Those skilled in the art will appreciate still other possible embodiments and advantages of the present invention with reference to these figures. Elements in the figures are not drawn to scale and like reference numerals are generally used to indicate like elements.
The invention will now be further described with reference to the accompanying drawings and detailed description.
Referring to fig. 1, a flow chart of a method for reloading a limited number of functions in a Linux kernel module is shown, the method comprises the following steps,
s1, calling a func () function in the program main module, wherein the func () function has a plurality of different specific implementations, and after the program source code is compiled and linked once, the specific implementations are freely selected without compiling the source code. And calling func () functions in the program main module, wherein the func () functions are divided into a plurality of cases and respectively call func _0(), func _1(), … and func _ n ().
S2 and the expansion modules A, B, …, and Max respectively define specific implementations of func _0(), func _1(), …, and func _ n () functions, and EXPORT the functions func _0(), func _1(), …, and func _ n () through an exit _ SYMBOL.
And S3, loading corresponding expansion modules as required during actual running, wherein when the program is loaded, the dynamic link device of the system loads the dynamic link library required by the program into the address space of the process, and binds all unresolved symbols into the corresponding dynamic link library for relocation. The program main module can find the realization of the corresponding function func () when linking, and the function overloading in a limited number of kernel modules is realized.
When the function expanding module is loaded and linked with the program main module, the expanding function can be normally used, and if some function modules are removed, the program can be normally linked, and only specific functions are omitted, so that the functions of the program can be more easily cut and flexibly combined.
S4, writing a virtual module, wherein the virtual module comprises all functions derived by all the expansion modules, the functions are realized as null and are directly returned, and the virtual module is loaded at the end of all the modules, so that the loading failure of the main control module due to the existence of undefined external symbols caused by the fact that some modules are not loaded is avoided.
Examples
In recent years, China has become the country with the fastest growing demand of the robot cooperative control system. At present, the domestic numerical control system has many single channels and weak multi-channel control capability. With the increase of the number of channels, the development of a numerical control system is more complex, and mainly the configuration of the multiple channels, the multiple channel PLC, the communication among the multiple channels and the like. At present, in most multi-channel systems, the number of channels is determined, the function of each channel is also determined, and the free configuration of forward and reverse solution modules of various types of robots cannot be realized.
In the development of a multi-channel numerical control system, each channel can correspond to different robots and can also correspond to the same type of robot, but the structural parameters of the robots are not consistent. The corresponding forward and inverse solution functions of the robot are not the same in each case. The Linux module has a plurality of communication methods, and function symbol derivation is the most convenient method and can be directly called after derivation. Referring to fig. 2, a flow chart of a method for implementing the single-channel robot control system is shown. Currently, in single-channel modular development, a corresponding forward and inverse solution function is called in a main control module by deriving a symbol table. However, in the multi-channel development, no one has proposed a better solution for solving the problem of repeated conflict of function symbol tables derived when the same module is loaded for multiple times and the problem of symbol table loss when only individual channels are configured, so as to realize intelligent configuration of forward and reverse solution modules.
The invention provides a method for overloading a limited number of functions in a Linux kernel module, which can realize intelligent configuration of a forward and reverse solution module of a multi-channel robot control system. The present invention will be described in more detail with reference to the following examples and fig. 3, but the present invention is not limited thereto.
Referring to fig. 3, a flow chart of the intelligent configuration method of the forward and reverse solution modules of the multi-channel robot control system is shown. The invention provides a method for overloading a limited number of functions in a Linux kernel module, which realizes intelligent configuration of a forward and reverse solution module of a multi-channel robot control system and comprises the following steps:
1. the maximum number of channels is defined, the embodiment is set as 16, the forward and inverse solution modules of each type of robot are rewritten according to the total number of channels, the forward and inverse solution function in each module is added with the corresponding channel serial number information, and the modules corresponding to the channel serial numbers are compiled and generated. In the example, the makefile of the SCARA module is rewritten and compiled to generate 16 so modules from SCARA00 to SCARA15, and the problem of repeated conflict of function symbol tables derived when the same module is loaded for multiple times is solved. The positive solution functions in each corresponding SCARA module are Kinemathardware 00-Kinemathardware 15, and the function SYMBOL table is derived through EXPORT _ SYMBOL.
2. And simultaneously writing a virtual module DUMMY, wherein the DUMMY virtual module defines function symbol tables derived from all channels, but the contents of all functions are null and are directly returned. The kinematic forwarding 00 through kinematic forwarding 15 are defined in the DUMMY virtual module in this embodiment and derived by EXPORT _ SYMBOL, but each function is null direct repeat 0.
3. Modifying the main control module, calling the corresponding function derived from the corresponding module EXPORT _ SYMBOL according to the channel number CASE through the switch
SWITCH(channel_Index)
{ CASE 0: KinematicForward00; break;
CASE 1: KinematicForward01; break;
CASE 15: KinematicForward15; break;
}
4. And during configuration, the corresponding dynamic library can be selected to load according to the type of the robot needing to be configured in the channel, and the conflict of the function symbol table is solved. In the embodiment, the channel 0 selects to load the SCARA00 module, the channel 1 loads the DELTA01, the channel 2 selects the PUMA02, the channel 3 selects the PUMA03, and the corresponding module is loaded according to the requirement.
5. And finally, loading a virtual module DUMMY, solving the problem of function symbol table loss caused by only configuring individual channels, and freely selecting configuration. The embodiment finally loads the DUMMY virtual module, and solves the problem of function symbol table missing caused by calling the functions from the kinematic forwarding 00 to the kinematic forwarding 15 in the main module because the corresponding module is not loaded.
Referring to fig. 4, a block diagram of an apparatus for overloading a limited number of functions in a Linux kernel module, the apparatus comprising,
and the program main module is used for calling the func () function, wherein the func () function is divided into a plurality of cases and respectively calls the func _0(), func _1(), func _2(), and other functions.
The extension module, the extension module A, B, C, respectively defines the specific implementation of functions such as func _0(), func _1(), func _2(), and derives the functions func _0(), func _1(), func _2(), and the like through an extract _ SYMBOL.
And the extension function module is loaded and linked with the program main module together, the program main module is operated to load the corresponding extension module, the corresponding realization of the function func () is found, and the function overloading with limited quantity in the kernel module is realized. And loading the corresponding expansion module as required during actual running, wherein when the program is loaded, the dynamic link device of the system loads the dynamic link library required by the program into the address space of the process, and binds all unresolved symbols into the corresponding dynamic link library for relocation.
The virtual module defines functions derived from all the expansion modules, but all the functions are null and directly return, and the virtual module is loaded at the end of all the modules, so that the loading failure of the main control module due to undefined external symbols existing because some modules are not loaded is avoided.
While the invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.

Claims (6)

1. A method for overloading a limited number of functions in a Linux kernel module is characterized in that: comprises the following steps of (a) carrying out,
s1, calling func () functions in the program main module, wherein the func () functions are divided into a plurality of cases and respectively call func _0(), func _1(), … and func _ n ();
s2 and the expansion modules A, B, …, and Max respectively define specific implementations of func _0(), func _1(), …, and func _ n () functions, and EXPORT the functions func _0(), func _1(), …, and func _ n () through an exit _ SYMBOL;
and S3, loading the extended function module and linking the extended function module and the program main module together, wherein the program main module can find the corresponding realization of the function func () when linking, thereby realizing the overloading of a limited number of functions in the kernel module.
2. The method for overloading a limited number of functions in a Linux kernel module of claim 1, wherein: the system also comprises a virtual module, wherein functions derived from all the expansion modules are defined in the virtual module, but all the functions are realized to be null and directly return, and the virtual module is loaded at the end of all the modules.
3. The method for overloading a limited number of functions in a Linux kernel module of claim 1, wherein: in the step S3, different numbers of expansion modules are loaded according to the actual function implementation requirement.
4. The device for overloading the limited number of functions in the Linux kernel module is characterized in that: comprises the steps of (a) preparing a mixture of a plurality of raw materials,
a program main module, configured to call a func () function, where the func () function is divided into multiple cases, and call func _0(), func _1(), …, and func _ n ();
the expanding module is used for defining the specific implementation of func _0(), func _1(), … and func _ n () functions and exporting the functions func _0(), func _1(), … and func _ n () through EXPORT _ SYMBOL;
and the extension function module is loaded and linked with the program main module together, the program main module is operated to load the corresponding extension module, the corresponding realization of the function func () is found, and the function overloading with limited quantity in the kernel module is realized.
5. The apparatus for overloading a limited number of functions in a Linux kernel module of claim 4, wherein: the system also comprises a virtual module, wherein functions derived from all the expansion modules are defined in the virtual module, but all the functions are realized to be null and directly return, and the virtual module is loaded at the end of all the modules.
6. The apparatus for overloading a limited number of functions in a Linux kernel module of claim 4, wherein: and when the program main module is operated, loading different quantities of expansion modules according to the actual function realization requirement.
CN201910922723.XA 2019-09-27 2019-09-27 Method and device for overloading limited number of functions in Linux kernel module Pending CN110659085A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910922723.XA CN110659085A (en) 2019-09-27 2019-09-27 Method and device for overloading limited number of functions in Linux kernel module

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910922723.XA CN110659085A (en) 2019-09-27 2019-09-27 Method and device for overloading limited number of functions in Linux kernel module

Publications (1)

Publication Number Publication Date
CN110659085A true CN110659085A (en) 2020-01-07

Family

ID=69039425

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910922723.XA Pending CN110659085A (en) 2019-09-27 2019-09-27 Method and device for overloading limited number of functions in Linux kernel module

Country Status (1)

Country Link
CN (1) CN110659085A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112859753A (en) * 2021-01-19 2021-05-28 深圳市汇川技术股份有限公司 Secondary development method, device and equipment for numerical control system and readable storage medium
CN113157979A (en) * 2021-03-16 2021-07-23 中国人民解放军国防科技大学 Method, system and medium for constructing kernel module relational graph based on dummy module nodes

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060130021A1 (en) * 2003-09-15 2006-06-15 Plum Thomas S Automated safe secure techniques for eliminating undefined behavior in computer software
CN102123217A (en) * 2009-12-14 2011-07-13 株式会社理光 Image forming apparatus, function adding method, and computer-readable recording medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060130021A1 (en) * 2003-09-15 2006-06-15 Plum Thomas S Automated safe secure techniques for eliminating undefined behavior in computer software
CN102123217A (en) * 2009-12-14 2011-07-13 株式会社理光 Image forming apparatus, function adding method, and computer-readable recording medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
严悍: "《新标准C++程序设计》", 31 August 2018, 东南大学出版社 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112859753A (en) * 2021-01-19 2021-05-28 深圳市汇川技术股份有限公司 Secondary development method, device and equipment for numerical control system and readable storage medium
CN112859753B (en) * 2021-01-19 2022-03-25 深圳市汇川技术股份有限公司 Secondary development method, device and equipment for numerical control system and readable storage medium
CN113157979A (en) * 2021-03-16 2021-07-23 中国人民解放军国防科技大学 Method, system and medium for constructing kernel module relational graph based on dummy module nodes
CN113157979B (en) * 2021-03-16 2023-09-29 中国人民解放军国防科技大学 Method, system and medium for constructing kernel module relation graph based on dummy module node

Similar Documents

Publication Publication Date Title
KR100518584B1 (en) Shared library system and method for constructing the system
CN101957770B (en) The starting method of application program and device on a kind of mobile device
CN102118281B (en) Method, device and network equipment for automatic testing
US7739696B2 (en) Message translation systems and methods
US7735075B2 (en) System and method for a pseudo dynamic link library (DLL) linker for a monolithic image in a wireless device
CN102541521B (en) Automatic operating instruction generating device based on structured query language and method
CN110659085A (en) Method and device for overloading limited number of functions in Linux kernel module
JPH02272627A (en) Digital computer system and method of invocation of procedure of the same
CN110968509B (en) Method and system for batch customizing of variables
CN113284038B (en) Method, computing device, computing system, and storage medium for performing computations
CN112650539B (en) Heterogeneous many-core processor-oriented dynamic link operation support method
CN110659088B (en) Method and system for expanding program under embedded environment
CN112527393A (en) Instruction scheduling optimization device and method for master-slave fusion architecture processor
CN102929853A (en) DCS (Data Communication System) project data generating system and method based on Excel sheet association
CN105630898A (en) Method applicable to switch application database table data version
US5561801A (en) System and method for multilevel promotion
CN106484375B (en) Instruction block loading method, soft switch equipment and system
CN113791870B (en) WebAssemble virtual machine distributed system fine granularity migration method and system
CN102681970B (en) Signal processor and configuration method thereof
CN105279195A (en) Method and apparatus for webpage application to call browser function
CN112035439A (en) Data migration method and device, computer equipment and computer readable storage medium
CN101625643B (en) Address mapping method of 8051 single chip
CN112130858A (en) Code compiling method and compiling server
US9330152B2 (en) Grid loader process
CN117931317A (en) Virtual plug-in system and method based on computer simulation platform

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200107