In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Development environment
Host: Windows 7
Integrated development environment: Real-Evo IDE 3.2.5
Virtual machine: Ubuntu 14.04
This article only introduces the porting process of libffi library, including the acquisition of resources, the modification of engineering files and the handling of compilation errors. The migrated libffi supports ARM, MIPS, PowerPC and x86 platforms. This document takes the x86 platform as an example. After completing the operation steps of this document, you only need to modify the base project that the libffi project depends on, and then recompile and upload it to use the libffi library on the supported platform.
2. Introduction to libffi
The full name of "FFI" is Foreign Function Interface, which usually refers to code that allows code written in one language to call another. The "libffi" library provides only the lowest-level, architecture-related, complete "FFI", so there must be a layer on top of it to manage the format conversion of parameters between the two languages.
High-level language compilers generate code according to a series of rules that are necessary, especially for stand-alone compilation. One of these is the calling Convention (Calling Convention), which contains a series of compiler assumptions about function parameters and function return values at the entry of a function. It is sometimes called "ABI" (Application Binary Interface). The calling convention (Calling Conventions) defines how the function is called in the program, and it determines how the data (such as parameters) are organized in the stack when the function is called.
Generally speaking, there are two basic instructions used in function calls: the "CALL" instruction and the "RET" instruction. " The CALL "instruction pushes the current instruction pointer (which points to the instruction immediately following the CALL instruction) onto the stack, and then executes an unconditional transfer instruction to the new code address." "RET" is an instruction used in conjunction with the "CALL" instruction, and it is the last instruction in most functions. " The "RET" instruction pops up the return address (that is, the address where the "CALL" instruction is pushed into the stack), loads it into the "EIP" register, and continues execution from that address.
3. Resource acquisition
3.1 libffi source code acquisition
In general, resources for third-party parts to be migrated can be obtained through the official website. The latest version of libffi can be downloaded from https://github.com/libffi/libffi.
The version of libffi used in this article is libffi-2.99.9. After download, the unzipped file is shown in figure 3-1.
Figure 3-1 partial files after libffi decompression
The src directory mainly contains the source files to be compiled and the supported platform files. Configure is a configuration file. Running this file under the Linux platform can generate a Makefile file, and execute the make command to generate the final library file.
The platforms supported by libffi can see the platform-related directories contained in the src directory, and the supported platforms are shown in figure 3-2.
Figure 3-2 platforms supported by libffi
Libffi migrated to SylixOS supports ARM, MIPS, POWERPC, and x86 platforms.
For the new version of libffi, the directory structure is different and the configuration method is also different, which needs to be configured in combination with the specific libffi version when porting.
4. Configuration under Linux platform
4.1 configuration
The Linux environment used in the compilation process is the Ubuntu distribution. Copy the downloaded package file to the Ubuntu environment and extract it. Since the downloaded library file already contains the configure configuration file, you need to execute this command to generate the makefile file, as shown in figure 4-1.
Figure 4-1 execution profile
Generate the makefile file as shown in figure 4-2.
Figure 4-2 generate makefile file
Since it is only for the purpose of configuring the libffi library, the configuration of libffi is completed after the configure script is executed, and then the libffi folder is saved for migration.
5. New libffi Library Project
5.1Import libffi source code
Create the libffi shared library project in Real-Evo IDE, delete the file libffi.c under the src directory in the libffi project, and import the libffi source file. The imported project file is shown in figure 5-1.
Figure 5-1 Import the libffi source file into the libffi library project
5.2 modify makefile
Change the libffi project properties to expert mode, as shown in figure 5-2.
Figure 5-2 change the project attribute to expert mode
Modify the libffi.mk file and add the compiled source file, as shown in figure 5-3.
Figure 5-3 modify libffi.mk add source file
Modify the libffi.mk file, add the header file path, and modify as shown in figure 5-4.
Figure 5-4 modify libffi.mk add header file path
Where PLATFORM is defined in the Makefile file, and the platforms supported by PLATFORM are shown in figure 5-5.
Figure 5-5 platforms supported by PLATFORM
Where TOOLCHAIN_PREFIX is related to the base project on which it depends. After specifying the dependent base project, the value of TOOLCHAIN_PREFIX has been determined.
5.3 compile the libffi project
Save the changes and compile, with the error shown in figure 5-6.
Figure 5-6 compilation error
After opening ffitarget.h, you can see that its content is garbled, so it leads to an error. Delete the header file and recompile it, which can be compiled and passed.
To support the PowerPC platform, you need to add content to the libffi/src/libffi/include/ffi.h file as shown in figure 5-7.
Figure 5-7 add the POWERPC macro
In order to support the MIPS platform, you need to replace the interface in the libffi/src/libffi/src/mips/ffi.c file. The original calling API is:
_ _ builtin__clear_cache (clear_location, clear_location + FFI_TRAMPOLINE_SIZE)
To be replaced by:
_ _ clear_cache (clear_location, clear_location + FFI_TRAMPOLINE_SIZE)
Compile again, and you can generate the libffi library file, which is located in the Debug directory. This is shown in figure 5-8.
Figure 5-8 compiles and generates libnopoll library files
Open the x86 virtual machine and configure the device IP of the libffi project to be the IP of the x86 virtual machine, and the generated library file can be imported into the x86 virtual machine. At this point, the compilation and upload of libffi are completed. The rest of the work is to test whether the transplanted libffi library can run properly through test cases.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.