Method and device for detecting bit shift of key function code segment of relay protection device
By distinguishing and processing different types of functions during the code compilation stage of relay protection devices, and generating and executing specific linker scripts, it is possible to detect bit shifts in critical function code segments without increasing hardware costs. This solves the problems of increased cost and complexity in existing technologies and improves the reliability and fault recovery capability of relay protection devices.
Patent Information
- Application Number
- CN202411984604.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-12-31
AI Technical Summary
In the prior art, using a duplicated or redundant storage system to improve the reliability and fault tolerance of a relay protection device usually increases cost and complexity, and is unable to effectively detect continuous multiple address abnormal changes.
During the code compilation stage of the relay protection device, a compilation directory is created, and the first type of functions that do not require cyclic redundancy check verification and the second type of functions that require cyclic redundancy check verification are distinguished and processed. Initial executable and linkable format files are generated, and a secondary linking script is generated by compiling code scripts. The target executable and linkable format files are executed to perform code segment bit shift detection and obtain the detection results of key functions.
Without increasing additional hardware costs, it effectively detects bit shifts in critical code segments, improving the reliability and fault recovery capabilities of relay protection devices, simplifying the operation process, and reducing system costs.
Smart Images

Figure CN119988179B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of relay protection, and in particular to a method and device for detecting bit shift of a key function code segment of a relay protection device. BACKGROUND
[0002] A relay protection device is an important component for protecting reliable operation of a power system. Due to the importance and complexity of the relay protection device, the reliability and security of the storage system of the relay protection device are very critical.
[0003] Currently, some technical solutions have been proposed for detecting abnormality or failure of the storage system of the relay protection device in the prior art. For example, the use of error correcting code (ECC) technology can effectively solve the problem of soft error caused by bit flip of memory and Nand Flash devices. Another technical solution is to use a dual or redundant storage system to improve the reliability and fault tolerance of the relay protection device. However, the above technical solutions also have some deficiencies. The use of ECC technology cannot achieve detection and recovery of continuous multiple address (multiple unit) abnormal bit shift. The use of a dual or redundant storage system to improve the reliability and fault tolerance of the relay protection device usually increases the cost and complexity. SUMMARY
[0004] The present application provides a method and device for detecting bit shift of a key function code segment of a relay protection device, which solves the defect that the use of a dual or redundant storage system to improve the reliability and fault tolerance of the relay protection device usually increases the cost and complexity in the prior art, and effectively detects the bit shift of the key code segment without increasing the cost of additional hardware, thereby obtaining the detection result of the bit shift of the key function code segment of the relay protection device.
[0005] The present application provides a method for detecting bit shift of a key function code segment of a relay protection device, which includes the following steps.
[0006] In the code compilation phase of the relay protection device, a compilation directory is created.
[0007] In the compilation directory, a first type of source file in which a first type of function is located and a second type of source file in which a second type of function is located are processed to generate an initial executable and linkable format file. The first type of function is a key function that does not require cyclic redundancy check verification, and the second type of function is a key function that requires cyclic redundancy check verification. The second type of function includes at least one key function.
[0008] The initial executable and linkable format file is parsed to obtain a function information file; wherein the function information file includes a structure body variable corresponding to each function in the initial executable and linkable format file, and the structure body variable includes a cyclic redundancy check value and a function length corresponding to the second type of function which needs to be checked by the cyclic redundancy check.
[0009] The code script is called to generate a secondary link script; wherein the code script is a pre-prepared link script file.
[0010] According to the function information file, the first type of target file and the second type of target file, a target executable and linkable format file is generated.
[0011] The target executable and linkable format file is executed to detect the code segment bit transposition of the second type of function of the relay protection device, and a key function code segment bit transposition detection result of the relay protection device is obtained.
[0012] According to the method for detecting the key function code segment bit transposition of the relay protection device, the first type of source file in which the first type of function in the key function is located and the second type of source file in which the second type of function is located are processed in the compilation directory to generate an initial executable and linkable format file, including: the first type of source file in which the first type of function in the key function is located is compiled in the compilation directory to obtain a first type of target file corresponding to the first type of source file after the compilation, and the second type of source file in which the second type of function in the key function is located is compiled to obtain a second type of target file corresponding to the second type of source file after the compilation; the first type of target file and the second type of target file are linked to generate the initial executable and linkable format file.
[0013] According to the method for detecting the key function code segment bit transposition of the relay protection device, according to the function information file, the first type of target file, the second type of target file and the secondary link script, a target executable and linkable format file is generated, including: the function information file is compiled to generate a function target file; the first type of target file, the second type of target file and the function target file are linked according to the secondary link script to generate the target executable and linkable format file.
[0014] The application provides a detection method for bit displacement of a key function code segment of a relay protection device, which comprises the following steps of: executing a target executable and linkable format file, and detecting bit displacement of a second type function of the relay protection device to obtain a bit displacement detection result of the key function code segment of the relay protection device.
[0015] The application provides a detection method for bit displacement of a key function code segment of a relay protection device, which comprises the following steps of: executing a target executable and linkable format file, and detecting bit displacement of a second type function of the relay protection device to obtain a bit displacement detection result of the key function code segment of the relay protection device.
[0016] The application provides a detection method for bit displacement of a key function code segment of a relay protection device, which comprises the following steps of: executing a target executable and linkable format file, and detecting bit displacement of a second type function of the relay protection device to obtain a bit displacement detection result of the key function code segment of the relay protection device.
[0017] The application further provides a detection device for bit displacement of a key function code segment of a relay protection device.
[0018] The application further provides a detection device for bit displacement of a key function code segment of a relay protection device.
[0019] The file processing module is configured to process first type source files and second type source files in the compiling directory, to generate an initial executable and linkable format file, wherein the first type source files are located at first type functions, and the second type source files are located at second type functions; the first type functions are key functions without cyclic redundancy check, and the second type functions are key functions with cyclic redundancy check; and the second type functions include at least one key function.
[0020] The file parsing module is configured to parse the initial executable and linkable format file to obtain a function information file, wherein the function information file includes a structure variable corresponding to each function in the initial executable and linkable format file, and the structure variable includes a cyclic redundancy check value and a function length corresponding to the second type function.
[0021] The script generating module is configured to call a code script to generate a secondary link script, wherein the code script is a pre-prepared link script file.
[0022] The file generating module is configured to generate a target executable and linkable format file according to the function information file, the first type target file, the second type target file and the secondary link script.
[0023] The bit shift detection module is configured to execute the target executable and linkable format file, to detect code segment bit shifts of the second type functions of the relay protection device, and to obtain a key function code segment bit shift detection result of the relay protection device.
[0024] The application further provides an electronic device, including a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the detection method of the key function code segment bit shift of the relay protection device when executing the computer program.
[0025] The application further provides a non-transitory computer readable storage medium, which stores a computer program, and the computer program implements the detection method of the key function code segment bit shift of the relay protection device when executed by a processor.
[0026] The application further provides a computer program product, which includes a computer program, and the computer program implements the detection method of the key function code segment bit shift of the relay protection device when executed by a processor.
[0027] The application provides a detection method and device for bit transposition of a key function code segment of a relay protection device. The application discloses a detection method and device for bit transposition of a key function code segment of a relay protection device. BRIEF DESCRIPTION OF DRAWINGS
[0028] In order to more clearly illustrate the technical solutions of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without any creative effort on the basis of these drawings.
[0029] Figure 1 FIG. 1 is one of the flow diagrams of the detection method for bit transposition of the key function code segment of the relay protection device provided by the application.
[0030] Figure 2 FIG. 2 is a schematic diagram of the initial linking script provided by the application.
[0031] Figure 3 FIG. 3 is a schematic diagram of the secondary linking script provided by the application.
[0032] Figure 4Figure 2 is a flowchart of the method for detecting the bit shift of the key function code segment of the relay protection device according to the present application.
[0033] Figure 5 Figure 3 is a structural diagram of the device for detecting the bit shift of the key function code segment of the relay protection device according to the present application.
[0034] Figure 6 Figure 4 is a structural diagram of the electronic device according to the present application. DETAILED DESCRIPTION
[0035] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be described clearly and completely below with reference to the drawings of the present application. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments of the present application, all the other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0036] The method for detecting the bit shift of the key function code segment of the relay protection device according to the present application will be described below. Figures 1-4 The method for detecting the bit shift of the key function code segment of the relay protection device according to the present application can be applied to the detection of the bit shift of the key function code segment of the relay protection device. The execution subject of the method can be an electronic device or a device for detecting the bit shift of the key function code segment of the relay protection device arranged in the electronic device. The device for detecting the bit shift of the key function code segment of the relay protection device can be realized by software, hardware or a combination of both. Figure 1 Figure 1 is a flowchart of the method for detecting the bit shift of the key function code segment of the relay protection device according to the present application. Figure 1 As shown in Figure 1, the method comprises the following steps 101, 102, 103, 104, 105 and 106.
[0037] Step 101, creating a compilation directory in the code compilation stage of the relay protection device.
[0038] In this step, the relay protection device is an important component for protecting the reliable operation of the power system. It can detect the faults or abnormal states in the power system and cut off the faulty elements from the power system through the tripping of the circuit breaker or the sending of signals to ensure the rapid recovery of the normal operation of the other non-faulty parts. Due to the importance and complexity of the relay protection device, the reliability and security of the storage system are very critical.
[0039] In a specific embodiment, before creating the compilation directory, further comprising: obtaining a directory detection command; determining whether the compilation directory exists based on the directory detection command; and continuing to perform the step of creating the compilation directory if the compilation directory does not exist.
[0040] In this step, the directory detection command refers to a command for determining whether a compilation directory exists in the code compilation stage of the relay protection device, for example, it can be@test -d $(BUILD_DIR) || mkdir -p $(BUILD_DIR), @test -d $(BUILD_DIR) || mkdir -p $(BUILD_DIR) is a conditional statement, which is usually used to ensure that a directory exists, and if it does not exist, it is created, BUILD_DIR is a variable that should contain the path of the directory you want to check or create, the @ symbol is used in some contexts to suppress the output of the execution result of the command. test -d $(BUILD_DIR) is a test condition that checks whether the directory specified by $(BUILD_DIR) exists. The -d option is used to test whether a file exists and is a directory. BUILD_DIR refers to the build directory, mkdir is a command for creating a directory, and the -p parameter tells mkdir to create the directory if necessary, and if the directory already exists, no error will be reported. This is a very useful option because it allows the script to run safely without knowing whether the directory already exists. $(BUILD_DIR) is a reference to the variable BUILD_DIR, which is not limited in this embodiment.
[0041] Specifically, in the code compilation stage of the relay protection device, the directory detection command is used to determine whether the protection program of the relay protection device exists in the compilation directory. If it is determined that the protection program of the relay protection device does not exist in the compilation directory, a compilation directory is created for the protection program of the relay protection device.
[0042] Step 102, processing the first type of source file in which the first type of function in the key function is located and the second type of source file in which the second type of function is located in the compilation directory to generate an initial executable and linkable format file.
[0043] In this step, the key functions in the protection program of the relay protection device are divided into functions that need to be checked by Cyclic Redundancy Check (CRC) and functions that do not need to be checked by CRC. The functions that need to be checked by CRC and the functions that do not need to be checked by CRC need to be placed in different C source files. The source files of the functions that need to be checked by CRC and the source files of the functions that do not need to be checked by CRC only need to be distinguished in the MAKEFILE file (a file describing the compilation rules), and do not need to be marked in the source code.
[0044] In this step, the initial executable and linkable format file is an Executable and Linkable Format (ELF) file.
[0045] Among them, the first type of function is a key function that does not need to check the cyclic redundancy check, and the second type of function is a key function that needs to check the cyclic redundancy check; the second type of function contains at least one key function.
[0046] Specifically, the first-category source files where the first-category functions in the key functions are located and the second-category source files where the second-category functions are located are compiled in the compilation directory, and the compiled first-category source files and the compiled second-category source files are connected through the linker according to the initial link script to finally generate the initial executable and linkable format files.
[0047] In a specific embodiment, the first-category source files where the first-category functions in the key functions are located and the second-category source files where the second-category functions are located are processed in the compilation directory to generate initial executable and linkable format files, including: compiling the first-category source files where the first-category functions in the key functions are located in the compilation directory to obtain first-category target files corresponding to the compiled first-category source files, compiling the second-category source files where the second-category functions in the key functions are located to obtain second-category target files corresponding to the compiled second-category source files; linking the first-category target files and the second-category target files to generate initial executable and linkable format files.
[0048] In this step, the first type of function is a key function that does not need to check the cyclic redundancy check, and the second type of function is a key function that needs to check the cyclic redundancy check; the first type of function and the second type of function contain at least one key function.
[0049] Specifically, after creating the compilation directory, compile the first type of source files where the first type of functions in the key functions are located in the compilation directory to obtain the first type of target files corresponding to the compiled first type of source files, and compile the second type of source files where the second type of functions in the key functions are located to obtain the second type of target files corresponding to the compiled second type of source files, and then use the linker to connect the first type of target files and the second type of target files according to the initial link script to generate the initial executable and linkable format files.
[0050] The advantage of this setting is that it allows flexible compilation. By classifying and compiling functions that need to be checked for CRC and functions that do not need to be checked during the compilation phase, it is beneficial to automatically manage structure variables and link scripts in the subsequently generated function information files, greatly simplifying the operation process and improving development efficiency.
[0051] In this step, the linker, for example, can be an ld linker, is mainly used to link multiple compiled object files together to generate an executable file or a shared library. It is an important tool in the programming and software development process, which completes the last step of the compilation process.
[0052] Further, the compilation needs to check the CRC function in the second type of source file, and this compilation process uses the gcc compilation option '-finstrument-functions'. Using this compilation option, the gcc compiler will automatically instrument each function compiled, and when entering the function execution, the first step will call the stub function first, and after executing the stub function, the remaining code of the original function will be executed. This embodiment is not limited.
[0053] The advantage of such a setting is that additional hardware does not need to be added, and by combining compiler instrumentation technology and CRC checking, the detection of storage exceptions is achieved, saving hardware resources and reducing system costs.
[0054] Exemplarily, Figure 2 is the initial linking script provided by the present application, as shown in Figure 2 is the initial linking script, Figure 2 0x6E400000, 0x6DA00000, 0x68600000 and 0x68000000 are storage addresses, and the embodiment is not limited. By using the linker to connect the first type of object file and the second type of object file according to the initial linking script in Figure 2 .bss section* (.bss) represents the storage of uninitialized global variables of the first type of object file and the second type of object file,.data section* (.data) represents the storage of global variables of the first type of object file and the second type of object file,.text section* (.text) represents the storage of code segments and compiled code of the first type of object file and the second type of object file, and then the initial executable and linkable format file after linking is generated based on.bss section* (.bss),.data section* (.data) and.text section* (.text).
[0055] Step 103, parsing the initial executable and linkable format file to obtain a function information file.
[0056] In this step, the function information file includes a structure variable corresponding to each function in the initial executable and linkable format file, and the structure variable includes a cyclic redundancy check value and a function length of the second type of function that needs to be checked cyclic redundancy check.
[0057] Specifically, after obtaining the initial executable and linkable format file, a command line tool and a prepared secondary linking script are used to export all function start addresses, lengths and function names from the symbol table of the initial executable and linkable format file to obtain a function information file.
[0058] In a specific embodiment, after obtaining the initial executable and linkable format file, the hexadecimal content of the test section is exported to obtain a function code section binary file.
[0059] For example, the command line tool can be the readelf tool with the "-s –wide" parameter to export the symbol table in the initial executable and linkable format file, the grep tool is used to filter the "FUNC" field in the symbol table, the awk '{print $$2 " " $$3 " " $$8}' tool is used to output the corresponding columns of the filtered content to the dump.data file, and the function information file is generated by the secondary linking script (python script) using the dump.data file. The readelf tool with the "-s.text" parameter is used to export the test section (text section) in the initial executable and linkable format file, and the awk '{print $$2 $$3 $$4 $$5}' tool is used to output the filtered content to the dump.hex file. The python script uses the dump.data file and the dump.hex file to calculate the CRC value of each function code section by calling the CRC calculation tool through the secondary linking script (python script), and finally fills the CRC value into the initial value position of the corresponding structure variable in the function information file. Further, the secondary linking script (python script) is used to generate a new function code section binary file, i.e., the function code section binary file, which specifies the linking position of each function in the text section, and specifies the linking position of the structure variable corresponding to the function information file generated in the fifth step before each function position, which is used to obtain the CRC value and length of its own code section when the function is executed.
[0060] For example, Figure 3 is a secondary linking script provided by the present application, as shown in Figure 3 , which represents the secondary linking script, Figure 3The addresses 0x6E400000, 0x6DA00000, 0x68600000 and 0x68000000 are storage addresses, and the embodiment is not limited thereto. The.bss segment is used to store global variables that are not initialized in a defined process, the.data segment is used to store global variables that are initialized in a defined process, and the.text segment is used to store binary codes of functions that do not need to be CRC checked. The segment next to the.text segment is a code segment of each function that needs to be CRC checked and a data structure used for the CRC checking, such as.text.fuc1 storing the code segment of the CRC checking function and.header.fuc1 storing the data structure (the data structure includes crc and the code segment length len) used for the CRC checking function. The embodiment is not limited thereto. The numbers on the left are storage spaces of the segments designated in the secondary linking script, such as the.data segment being stored in the address space of 0x68600000-0x6DA00000. The linker will place the code segment, the uninitialized global variables and the initialized global variables in the object file compiled in the linking stage into the segments designated in the linking script, and then perform repositioning and other operations on the global variables and function calls used in the text segment, to finally link the object executable and linkable format file that can run on the processor.
[0061] Step 104, calling the code generation script to generate the secondary linking script.
[0062] In this step, the code generation script is a pre-called linking script file; the code generation script may be, for example, a python (a widely used high-level programming language) script, and the embodiment is not limited thereto.
[0063] Specifically, after obtaining the initial linking script of step 102, the pre-called code generation script is called to generate the secondary linking script.
[0064] Step 105, generating the object executable and linkable format file according to the function information file, the first type of object file, the second type of object file and the secondary linking script.
[0065] Specifically, after obtaining the function information file, the object executable and linkable format file is generated according to the function information file, the first type of object file, the second type of object file and the secondary linking script.
[0066] In a specific embodiment, the target executable and linkable format file is generated according to the function information file, the first type target file, the second type target file and the secondary linking script, including: compiling the function information file to generate a function target file; and linking the first type target file, the second type target file and the function target file according to the secondary linking script to generate the target executable and linkable format file.
[0067] In this step, the target executable and linkable format file is also an ELF file.
[0068] Specifically, after obtaining the function information file and the secondary linking script, the function information file is compiled to generate a function target file, and then the function target file, the first type target file and the second type target file are linked again through the secondary linking script to finally obtain the target executable and linkable format file.
[0069] Step 106, executing the target executable and linkable format file to detect the code segment bit shift of the second type function of the relay protection device to obtain the key function code segment bit shift detection result of the relay protection device.
[0070] Specifically, after obtaining the target executable and linkable format file, the target executable and linkable format file is executed, and the code segment bit shift of the second type function of the relay protection device is detected based on the function code segment binary file and the target executable and linkable format file to obtain the key function code segment bit shift detection result of the relay protection device.
[0071] In a specific embodiment, the target executable and linkable format file is generated according to the function information file, the first type target file, the second type target file and the secondary linking script, including: compiling the function information file to generate a function target file; and linking the first type target file, the second type target file and the function target file according to the secondary linking script to generate the target executable and linkable format file.
[0072] In this step, realize the function self code segment CRC checksum function in the pile function.This pile function at first reads and is stored in the code segment CRC and the code segment length that form in the compiling stage with the next-door neighbour of the verified function position.Then calculate the CRC of this function again and compare with the CRC value that reads.If more inconsistent, then illustrate that single bit or multi-bit displacement has taken place in the code segment of this function, behind the pile function record error log, jump to abnormal interrupt handling function.If the pile function verification CRC is identical, then continue normal execution and be the code of verified function.
[0073] Specifically, the stub function in the target executable and linkable format file is executed, and the function length of the function formed in the compilation stage is found from 8 bytes above the starting address of the second-class function according to the function code segment binary file, and the target cyclic redundancy check value corresponding to the second-class function is recalculated according to the starting address and the function length; the code segment bit shift of the second-class function of the relay protection device is detected according to the cyclic redundancy check value and the target cyclic redundancy check value, and the key function code segment bit shift detection result of the relay protection device is obtained.
[0074] The advantage of this setting is that the real-time performance of the relay protection device will not be affected by the verification of the key function by the stub function, and it is suitable for relay protection devices with high real-time requirements.
[0075] In a specific embodiment, a code segment bit shift detection is performed on the second type of function of the relay protection device according to a cyclic redundancy check value and a target cyclic redundancy check value to obtain a key function code segment bit shift detection result of the relay protection device, including: performing a code segment bit shift detection on the second type of function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value to determine whether the cyclic redundancy check value and the target cyclic redundancy check value are the same; when the cyclic redundancy check value and the target cyclic redundancy check value are the same, determining that the key function code segment bit shift detection result is normal, and continuing to execute the remaining code of the second type of function of the relay protection device; when the cyclic redundancy check value and the target cyclic redundancy check value are different, determining that the key function code segment bit shift detection result is abnormal, and obtaining an error log; wherein the error log is used to indicate that the cyclic redundancy check value and the target cyclic redundancy check value are different.
[0076] In this step, the error log is used to indicate that the cyclic redundancy check value is different from the target cyclic redundancy check value.
[0077] Specifically, the second type of function of the relay protection device is detected for code segment bit transposition according to the cyclic redundancy check value and the target cyclic redundancy check value, and it is determined whether the cyclic redundancy check value and the target cyclic redundancy check value are the same; in the case that the cyclic redundancy check value and the target cyclic redundancy check value are the same, it is determined that the key function code segment bit transposition detection result is normal, and the remaining code of the second type of function of the relay protection device is continued to be executed; in the case that the cyclic redundancy check value and the target cyclic redundancy check value are different, it is determined that the key function code segment bit transposition detection result is abnormal, and an error log is obtained, and it is indicated by the error log that the cyclic redundancy check value and the target cyclic redundancy check value are different. After the error log is recorded, the relay protection device restart state is set, and then the code processing entrance of the abnormality is jumped to, so that the relay protection device is restarted.
[0078] The advantage of such setting is that the specific function where the abnormality occurs can be accurately located, the fault analysis and positioning are facilitated, and the fault recovery capability of the relay protection device is improved.
[0079] In a specific embodiment, Figure 4 is a flowchart of the detection method of the key function code segment bit transposition of the relay protection device provided by the application, as shown in Figure 4 The target executable and linkable format file is generated by specifically comprising the following steps.
[0080] Step 401, in the code compilation stage of the relay protection device, a compilation directory is created.
[0081] Step 402, the first type of source file is compiled to obtain the first type of target file, and the second type of source file is compiled to obtain the second type of target file.
[0082] Specifically, the first type of source file where the first type of function in the key function is located is compiled in the compilation directory to obtain the first type of target file corresponding to the first type of source file after compilation, and the second type of source file where the second type of function in the key function is located is compiled to obtain the second type of target file corresponding to the second type of source file after compilation.
[0083] Step 403, the first type of target file and the second type of target file are linked according to the initial linking script to generate an initial executable and linkable format file.
[0084] Step 404, the initial executable and linkable format file is parsed to obtain a function information file.
[0085] Step 405, a secondary linking script is generated by calling a code compiling script.
[0086] Specifically, after the initial linking script is obtained, the secondary linking script is generated by calling the pre-called code compiling script.
[0087] Step 406, compiling the function information file to generate a function object file.
[0088] Step 407, linking the first type object file, the second type object file and the function object file according to the secondary linking script to generate an object executable and linkable format file.
[0089] Specifically, the first type object file, the second type object file and the function object file are linked according to the secondary linking script to generate the object executable and linkable format file, and after the object executable and linkable format file is generated, the automatic compilation ends.
[0090] The application provides a kind of detection method of key function code segment bit displacement of relay protection device, by creating compilation directory in the code compilation stage of relay protection device;In the first type source file of first type function in key function and the second type source file of second type function are handled in compilation directory, and initial executable and linkable format file is generated;Wherein, the first type function is the key function that does not need to check cyclic redundancy check, and the second type function is the key function that needs to check cyclic redundancy check;Second type function includes at least one key function;Function information file is obtained by parsing initial executable and linkable format file;Wherein, function information file includes the structure body variable corresponding to each function in initial executable and linkable format file, and the cyclic redundancy check value corresponding to second type function of structure body variable and function length that need to check cyclic redundancy check;Secondary linking script is generated by calling code script;Wherein, code script is the linking script file that is called in advance;According to function information file, first type object file, second type object file and secondary linking script, object executable and linkable format file is generated;The key function of second type function of relay protection device is detected by executing object executable and linkable format file, and the detection result of key function code segment bit displacement of relay protection device is obtained.The technical scheme of the application is used to solve the defects that the use of double or redundant storage system in prior art usually increases cost and complexity to improve the reliability and fault tolerance of relay protection device, effectively detects the key code segment bit displacement condition without increasing additional hardware cost, and obtains the detection result of key function code segment bit displacement of relay protection device.
[0091] The detection device of key function code segment bit displacement of relay protection device provided by the application is described below, and the detection device of key function code segment bit displacement of relay protection device described below can be correspondingly referred to the detection method of key function code segment bit displacement of relay protection device described above.
[0092] Figure 5 is a structural schematic diagram of a bit shift detection device for a key function code segment of a relay protection device provided by the present application, referring to Figure 5 , the bit shift detection device for a key function code segment of a relay protection device 500 comprises a directory creation module 501, a file processing module 502, a file parsing module 503, a script generation module 504, a file generation module 505 and a shift detection module 506.
[0093] The directory creation module 501 is configured to create a compilation directory in a code compilation stage of the relay protection device.
[0094] The file processing module 502 is configured to process a first type of source file in which a first type of function in the key function is located and a second type of source file in which a second type of function is located in the compilation directory, and generate an initial executable and linkable format file; wherein the first type of function is a key function which does not need to check a cyclic redundancy check, and the second type of function is a key function which needs to check a cyclic redundancy check; the second type of function comprises at least one key function.
[0095] The file parsing module 503 is configured to parse the initial executable and linkable format file to obtain a function information file; wherein the function information file comprises a structure variable corresponding to each function in the initial executable and linkable format file, and the structure variable comprises a cyclic redundancy check value and a function length corresponding to the second type of function which needs to check a cyclic redundancy check.
[0096] The script generation module 504 is configured to call a code script to generate a secondary link script; wherein the code script is a link script file which is prepared in advance.
[0097] The file generation module 505 is configured to generate a target executable and linkable format file according to the function information file, the first type of target file, the second type of target file and the secondary link script.
[0098] The shift detection module 506 is configured to execute the target executable and linkable format file, detect the key function code segment bit shift of the second type of function of the relay protection device, and obtain a key function code segment bit shift detection result of the key function of the relay protection device.
[0099] In an example embodiment, the file processing module 502 is specifically configured to compile the first type of source file in which the first type of function in the key function is located in the compilation directory to obtain a first type of target file corresponding to the first type of source file after compilation, compile the second type of source file in which the second type of function in the key function is located to obtain a second type of target file corresponding to the second type of source file after compilation, and link the first type of target file and the second type of target file to generate the initial executable and linkable format file.
[0100] In an example embodiment, the file generation module 505 is specifically configured to compile the function information file to generate a function object file; and link the first type of object file, the second type of object file and the function object file according to a secondary linking script to generate an object executable and linkable format file.
[0101] In an example embodiment, the bit shift detection module 506 is specifically configured to execute the stub function in the object executable and linkable format file, recompute the target cyclic redundancy check value corresponding to the second type of function according to the start address and the function length corresponding to the second type of function, and detect the code segment bit shift of the second type of function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value to obtain the key function code segment bit shift detection result of the relay protection device.
[0102] In an example embodiment, the bit shift detection module 505 detects the code segment bit shift of the second type of function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value to obtain the key function code segment bit shift detection result of the relay protection device, and is specifically configured to detect the code segment bit shift of the second type of function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value, determine whether the cyclic redundancy check value and the target cyclic redundancy check value are the same, determine that the key function code segment bit shift detection result is normal and continue to execute the remaining code of the second type of function of the relay protection device in the case where the cyclic redundancy check value and the target cyclic redundancy check value are the same, and determine that the key function code segment bit shift detection result is abnormal and obtain an error log in the case where the cyclic redundancy check value and the target cyclic redundancy check value are not the same; wherein the error log is used to indicate that the cyclic redundancy check value and the target cyclic redundancy check value are not the same.
[0103] In an example embodiment, the device further comprises a directory determination module. The directory determination module is configured to obtain a directory detection command before the step of creating a compilation directory, determine whether the compilation directory exists based on the directory detection command, and continue to execute the step of creating the compilation directory in the case where the compilation directory does not exist.
[0104] The device of the present embodiment can be used to execute the method of any one of the method-side embodiments of the relay protection device key function code segment bit shift detection method, and the specific implementation process and technical effects are similar to those of the method-side embodiments of the relay protection device key function code segment bit shift detection method. For details, refer to the detailed description in the method-side embodiments of the relay protection device key function code segment bit shift detection method, which will not be described here.
[0105] Figure 6 is a structural schematic diagram of an electronic device provided by the present application, asFigure 6 As shown, the electronic device can include a processor 610, a communications interface 620, a memory 630, and a communications bus 640, wherein the processor 610, the communications interface 620, and the memory 630 complete mutual communication through the communications bus 640. The processor 610 can invoke a logic instruction in the memory 630 to execute a detection method of a bit shift of a key function code segment of a relay protection device, the method including: creating a compilation directory in a code compilation phase of the relay protection device; processing a first type of source file in which a first type of function is located and a second type of source file in which a second type of function is located in the compilation directory, to generate an initial executable and linkable format file; wherein the first type of function is a key function that does not need to check a cyclic redundancy check, and the second type of function is a key function that needs to check the cyclic redundancy check; the second type of function includes at least one key function; parsing the initial executable and linkable format file to obtain a function information file; wherein the function information file includes a structure variable corresponding to each function in the initial executable and linkable format file, and the structure variable includes a cyclic redundancy check value corresponding to the second type of function that needs to check the cyclic redundancy check and a function length; invoking a code script to generate a secondary linking script; generating a target executable and linkable format file according to the function information file, a first type of object file, a second type of object file, and the secondary linking script; and executing the target executable and linkable format file to detect the bit shift of the key function code segment of the relay protection device for the second type of function of the relay protection device, to obtain a bit shift detection result of the key function code segment of the relay protection device.
[0106] In addition, the logic instruction in the memory 630 described above can be implemented in the form of a software function unit and sold or used as an independent product, and can be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing 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 embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.
[0107] In another aspect, the present application also provides a computer program product, which comprises a computer program, the computer program being stored in a non-transitory computer readable storage medium, and the computer program being capable of executing the method for detecting bit shift of a key function code segment of a relay protection device provided by each of the above methods when executed by a processor, the method comprising: creating a compilation directory in a code compilation stage of the relay protection device; processing a first type of source file in which a first type of function in the key function and a second type of source file in which a second type of function are located in the compilation directory to generate an initial executable and linkable format file; wherein the first type of function is a key function which does not need to be checked for cyclic redundancy check, and the second type of function is a key function which needs to be checked for cyclic redundancy check; the second type of function comprises at least one key function; parsing the initial executable and linkable format file to obtain a function information file; wherein the function information file comprises a structure variable corresponding to each function in the initial executable and linkable format file, and the structure variable comprises a cyclic redundancy check value and a function length of the second type of function which needs to be checked for cyclic redundancy check; calling a code script to generate a secondary link script; generating a target executable and linkable format file according to the function information file, a first type of object file, a second type of object file and the secondary link script; and executing the target executable and linkable format file to detect bit shift of the key function code segment of the relay protection device for the second type of function of the relay protection device, and obtain a bit shift detection result of the key function code segment of the relay protection device.
[0108] In yet another aspect, the present application also provides a non-transitory computer readable storage medium having stored thereon a computer program, which, when executed by a processor, implements the method for detecting bit shift of a key function code segment of a relay protection device provided by each of the above methods, and the method comprises: creating a compilation directory at a code compilation stage of the relay protection device; processing a first type of source file in which a first type of function in the key functions is located and a second type of source file in which a second type of function is located in the compilation directory, to generate an initial executable and linkable format file; wherein the first type of function is a key function that does not need to check a cyclic redundancy check, and the second type of function is a key function that needs to check the cyclic redundancy check; the second type of function includes at least one key function; parsing the initial executable and linkable format file to obtain a function information file; wherein the function information file includes a structure variable corresponding to each function in the initial executable and linkable format file, and the structure variable includes a cyclic redundancy check value corresponding to the second type of function that needs to check the cyclic redundancy check and a function length; calling a code script to generate a secondary linking script; generating a target executable and linkable format file according to the function information file, the first type of object file, the second type of object file and the secondary linking script; and executing the target executable and linkable format file to detect bit shift of the key function code segment of the relay protection device for the second type of function of the relay protection device, to obtain a bit shift detection result of the key function code segment of the relay protection device.
[0109] The device embodiments described above are merely illustrative, wherein the units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment according to actual needs. Those skilled in the art can understand and implement without creative labor.
[0110] From the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be realized by means of software and necessary general hardware platform, and of course can also be realized by hardware. Based on such understanding, the above technical solutions can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in each embodiment or some parts of the embodiments.
[0111] It should be pointed out finally that the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit the same; and although the present application has been described in detail with reference to the foregoing embodiments, it should be appreciated by those skilled in the art that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features thereof can be replaced equivalently; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for detecting bit shifts in a key function code segment of a relay protection device, characterized in that: include: During the code compilation phase of the relay protection device, a compilation directory is created; Compile the first-category source files containing the first-category functions in the compilation directory to obtain the first-category target files corresponding to the compiled first-category source files, and compile the second-category source files containing the second-category functions in the key functions to obtain the second-category target files corresponding to the compiled second-category source files; link the first-category target files and the second-category target files to generate initial executable and linkable format files; wherein the first-category functions are key functions that do not require cyclic redundancy check verification, and the second-category functions are key functions that require cyclic redundancy check verification; and the second-category functions contain at least one key function; Parsing the initial executable and linkable format file to obtain a function information file; wherein the function information file includes a structure variable corresponding to each function in the initial executable and linkable format file, the structure variable including a cyclic redundancy check value and a function length corresponding to the second type of function requiring cyclic redundancy check; Calling a compilation code script to generate a secondary link script; wherein the compilation code script is a pre-compiled link script file; Generate a target executable and linkable format file according to the function information file, the first type of target file, the second type of target file and the secondary link script; Executing the target executable and linkable format file, performing code segment bit shift detection on the second-category function of the relay protection device, and obtaining the code segment bit shift detection result of the key function of the relay protection device; executing the target executable and linkable format file, performing code segment bit shift detection on the second-category function of the relay protection device, and obtaining the code segment bit shift detection result of the key function of the relay protection device, includes: executing the stub function in the target executable and linkable format file, and recalculating the target cyclic redundancy check value corresponding to the second-category function according to the starting address and the function length corresponding to the second-category function; performing code segment bit shift detection on the second-category function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value, and obtaining the code segment bit shift detection result of the key function of the relay protection device.
2. The method for detecting bit shift of a key function code segment of a relay protection device according to claim 1, characterized in that: Generating a target executable and linkable format file according to the function information file, the first type of target file, the second type of target file, and the secondary link script includes: Compiling the function information file to generate a function target file; The first type of target file, the second type of target file, and the function target file are linked according to the secondary link script to generate the target executable and linkable format file.
3. The method for detecting bit shifts in code segments of key functions of a relay protection device according to claim 1, wherein the detecting of code segment bit shifts of the second type of function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value to obtain a detection result of the bit shifts in the code segments of the key functions of the relay protection device comprises: performing code segment bit shift detection on the second-type function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value, and determining whether the cyclic redundancy check value and the target cyclic redundancy check value are the same; When the cyclic redundancy check value is the same as the target cyclic redundancy check value, determining that the bit shift detection result of the key function code segment is normal, and continuing to execute the remaining code of the second type function of the relay protection device; When the cyclic redundancy check value and the target cyclic redundancy check value are different, it is determined that the bit shift detection result of the key function code segment is abnormal, and an error log is obtained; wherein, the error log is used to indicate that the cyclic redundancy check value and the target cyclic redundancy check value are different.
4. The method for detecting bit shift of a key function code segment of a relay protection device according to claim 1, characterized in that: Before creating the compilation directory, it also includes: Get directory detection command; Determining whether the compilation directory exists based on the directory detection command; If the compilation directory does not exist, continue to execute the step of creating the compilation directory.
5. A device for detecting bit shifts in a key function code segment of a relay protection device, characterized in that: include: The directory creation module is used to create a compilation directory during the code compilation phase of the relay protection device; A file processing module is configured to compile a first-category source file containing a first-category function in a key function in the compilation directory to obtain a first-category target file corresponding to the compiled first-category source file, and to compile a second-category source file containing a second-category function in the key function to obtain a second-category target file corresponding to the compiled second-category source file; link the first-category target file and the second-category target file to generate an initial executable and linkable format file; wherein the first-category function is a key function that does not require a cyclic redundancy check, and the second-category function is a key function that requires a cyclic redundancy check; and the second-category function includes at least one key function; A file parsing module, configured to parse the initial executable and linkable format file to obtain a function information file; wherein the function information file includes a structure variable corresponding to each function in the initial executable and linkable format file, the structure variable including a cyclic redundancy check value and a function length corresponding to the second type of function requiring cyclic redundancy check; A script generation module is used to call a compilation code script to generate a secondary link script; wherein the compilation code script is a pre-compiled link script file; A file generation module, configured to generate a target executable and linkable format file according to the function information file, the first type of target file, the second type of target file, and the secondary link script; A displacement detection module is used to execute the target executable and linkable format file, perform code segment bit displacement detection on the second-category function of the relay protection device, and obtain the code segment bit displacement detection result of the key function of the relay protection device; the execution of the target executable and linkable format file, perform code segment bit displacement detection on the second-category function of the relay protection device, and obtain the code segment bit displacement detection result of the key function of the relay protection device, including: executing the stub function in the target executable and linkable format file, and recalculating the target cyclic redundancy check value corresponding to the second-category function according to the starting address and the function length corresponding to the second-category function; performing code segment bit displacement detection on the second-category function of the relay protection device according to the cyclic redundancy check value and the target cyclic redundancy check value, and obtaining the code segment bit displacement detection result of the key function of the relay protection device.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the method for detecting bit shifts in a key function code segment of a relay protection device as described in any one of claims 1 to 4 is implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for detecting bit shifts in a key function code segment of a relay protection device as described in any one of claims 1 to 4 is implemented.
8. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method for detecting bit shifts in a key function code segment of a relay protection device as described in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Method and device for locating programming language errors and electronic equipment
CN118331878A
Source code instrumentation method and device and storage medium
CN118733426A