Compiling the AArch64 ExaGear Strace Patch
Question
How do I build the AArch64
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:
- Prepare the compilation environment.
- 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.
- 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
- Configure environment variables.
- Add the path of the cross compilation toolchain to PATH and add the directory of the isl library to LD_LIBRARY_PATH.
1export 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
1export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
- 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
- Add the path of the cross compilation toolchain to PATH and add the directory of the isl library to LD_LIBRARY_PATH.
- Download strace source code strace-4.25.tar.xz.
- Create a strace.patch file in the root directory.
cd /root vim strace.patch
- 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]) { - 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:
1tar 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
- Configure the strace source code tree.
1./configure --enable-mpers=no --host=aarch64-none-linux-gnu LDFLAGS="-static -pthread"
- 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