我要评分
获取效率
正确性
完整性
易理解

Compiling the AArch64 ExaGear Strace Patch

Question

How do I build the AArch64 strace from the source code in cross-compilation mode when ExaGear is deployed?

Answer

Use the toolchain to compile the strace V4.25 source code and the corresponding patch to obtain the executable AArch64 strace program. The compilation procedure is as follows:

  1. Prepare the compilation environment.

    Prepare the compilation environment according to the requirements listed in Table 1 and Table 2.

    Table 1 Hardware requirements

    Item

    Requirement

    Server architecture

    x86_64

    CPU

    Intel® Xeon® CPU E5-2690 v2@3.00 GHz or later

    Memory

    At least 1 GB

    Drive

    At least 4 GB

    Table 2 Software requirements

    Item

    Requirement

    OS

    CentOS 7.6, Ubuntu 18.0.4 or later

    OS user

    Common user

    GNU Make

    4.3 or later

    GCC

    7.5.0 or later

  2. Download the Linaro cross compilation toolchain (gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz) from the official website of Arm GNU Toolchain.
  3. Upload the downloaded file to /root and decompress it.
    1
    2
    cd /root
    tar xvf gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz
    
  4. Configure environment variables.
    1. Add the path of the cross compilation toolchain to PATH and add the directory of the isl library to LD_LIBRARY_PATH.
      1
      export PATH=/root/gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu/libexec/gcc/aarch64-none-linux-gnu/10.2.1:/root/gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu/bin:$PATH
      
      1
      export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
      

      If the local GCC toolchain is installed not using the system source (Yum or APT), go to 4.b. If it is installed using the system source, neglect 4.b. By default, the GCC toolchain is installed using the system source.

    2. Set the environment variables of the GCC toolchain.
      1
      2
      export PATH=/home/lei/mpi_x86/gcc-9.3.0/bin:/usr/libexec/gcc/x86_64-redhat-linux/9.3.0:$PATH
      export LD_LIBRARY_PATH=/home/lei/mpi_x86/gcc-9.3.0/lib64:/usr/libexec/gcc/x86_64-redhat-linux/9.3.0:$LD_LIBRARY_PATH
      
  5. Download strace source code strace-4.25.tar.xz.
  6. Create a strace.patch file in the root directory.
    cd /root
    vim strace.patch
  7. Copy the following content to the strace.patch file and save the file.
    diff --git a/linux/aarch64/get_scno.c b/linux/aarch64/get_scno.c
    index 350f32fb..0ed956dd 100644
    --- a/linux/aarch64/get_scno.c
    +++ b/linux/aarch64/get_scno.c
    @@ -1,3 +1,5 @@
    +static bool have_syscall_hack = false;
    +
     /* Return codes: 1 - ok, 0 - ignore, other - error. */
     static int
     arch_get_scno(struct tcb *tcp)
    @@ -8,11 +10,20 @@ arch_get_scno(struct tcb *tcp)
    		case sizeof(aarch64_regs):
    			/* We are in 64-bit mode */
    			scno = aarch64_regs.regs[8];
    +			if (scno & 0x80000000) {
    +				have_syscall_hack = true;
    +				update_personality(tcp, 1);
    +				scno = aarch64_regs.regs[7];
    +				scno = shuffle_scno(scno);
    +				break;
    +			}
    +			have_syscall_hack = false;
    			break;
    		case sizeof(arm_regs):
    			/* We are in 32-bit mode */
    			/* Note: we don't support OABI, unlike 32-bit ARM build */
    			scno = arm_regs.ARM_r7;
    +			have_syscall_hack = false;
    			break;
    	}
    
    diff --git a/linux/aarch64/get_syscall_args.c b/linux/aarch64/get_syscall_args.c
    index ea6e497d..96b2d404 100644
    --- a/linux/aarch64/get_syscall_args.c
    +++ b/linux/aarch64/get_syscall_args.c
    @@ -6,7 +6,7 @@
     static int
     get_syscall_args(struct tcb *tcp)
     {
    -	if (tcp->currpers == 1)
    +	if (tcp->currpers == 1 && !have_syscall_hack)
    		return arm_get_syscall_args(tcp);
    	tcp->u_arg[0] = aarch64_regs.regs[0];
    	tcp->u_arg[1] = aarch64_regs.regs[1];
    diff --git a/syscall.c b/syscall.c
    index fe85b8bf..9eac619a 100644
    --- a/syscall.c
    +++ b/syscall.c
    @@ -286,8 +286,8 @@ update_personality(struct tcb *tcp, unsigned int personality)
    	tcp->currpers = personality;
    
    	if (!qflag) {
    -		error_msg("[ Process PID=%d runs in %s mode. ]",
    -			  tcp->pid, personality_names[personality]);
    +//		error_msg("[ Process PID=%d runs in %s mode. ]",
    +//			  tcp->pid, personality_names[personality]);
    	}
    
    	if (need_mpers_warning[personality]) {
    
  8. Upload strace-4.25.tar.xz to /root, decompress the source package, and integrate it into the patch file.
    1
    2
    3
    4
    cd /root
    tar xvf strace-4.25.tar.xz
    cd strace-4.25/
    patch -p1 < ../strace.patch
    

    During the decompression, the following problem may occur:

    1
    tar xvf strace-4.25.tar.xz
    
    1
    2
    xz: /usr/local/lib/liblzma.so.5: version 'XZ_5.1.2alpha' not found (required by xz)
    xz: /usr/local/lib/liblzma.so.5: version 'XZ_5.2.2' not found (required by xz)
    

    Create a symbol link to solve the problem.

    1
    2
    3
    Fix above issue:
    cd /usr/local/lib/
    ln -s -f /lib64/liblzma.so.5.2.2 liblzma.so.5
    
  9. Configure the strace source code tree.
    1
    ./configure --enable-mpers=no --host=aarch64-none-linux-gnu LDFLAGS="-static -pthread"
    
  10. Compile and install the strace patch.
    1
    2
    3
    cd strace-4.25/
    make
    make install exec_prefix=/root/strace_installation
    

    Strace is generated in the following path:

    1
    /root/strace_installation/bin