如何编译ARM 64版本ExaGear Strace补丁
问题
如何在部署了ExaGear的环境下,通过交叉编译的方式,从源码构建出ARM 64版本的
回答
用户可以使用工具链编译Strace V4.25源码及对应patch得到ARM 64 Strace可执行程序。编译步骤如下。
- 准备编译环境。
- 从下列任一渠道下载Linaro交叉编译工具链(文件名:gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz):
- 将下载的文件上传到“/root”目录中并解压。
cd /root tar xvf gcc-arm-10.2-2020.11-x86_64-aarch64-none-linux-gnu.tar.xz
- 设置环境变量。
- 将交叉编译工具链的路径添加到PATH,并将isl库所在的目录加到LD_LIBRARY_PATH。
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
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
- 设置GCC工具链的环境变量。
# 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
- 将交叉编译工具链的路径添加到PATH,并将isl库所在的目录加到LD_LIBRARY_PATH。
- 下载Strace源码。
下载地址:https://github.com/strace/strace/releases/download/v4.25/strace-4.25.tar.xz
- 在root目录下新建一个strace.patch。
# cd /root # vim strace.patch
- 将如下内容拷贝到strace.patch文件中并保存。
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]) {
- 将strace-4.25.tar.xz上传到“/root”目录下,解压源码包后合入patch文件。
# cd /root # tar xvf strace-4.25.tar.xz # cd strace-4.25/ # patch -p1 < ../strace.patch
解压过程中,若遇到如下问题:
# tar xvf strace-4.25.tar.xz 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)
可创建相关的符号链解决,如下:
# Fix above issue: # cd /usr/local/lib/ # ln -s -f /lib64/liblzma.so.5.2.2 liblzma.so.5
- 配置Strace源码树。
# ./configure --enable-mpers=no --host=aarch64-none-linux-gnu LDFLAGS="-static -pthread"
- 编译安装Strace补丁。
# cd strace-4.25/ # make # make install exec_prefix=/root/strace_installation
Strace生成路径如下:
/root/strace_installation/bin