编译 aarch64 二进制 bash 脚本
Compile aarch64 binary bash script
我在 x86-64 机器上使用 shc 将 bash 脚本转换为可执行二进制文件。这 运行 在我的机器上没问题,但我这样做是为了将它推送到 aarch64 机器上。将二进制文件复制到 aarch64 机器后,出现此错误:
无法执行二进制文件:执行格式错误
这似乎是由于此 OS 上的二进制文件未格式化为 运行 造成的。有谁知道一个工具可以给我一个可以在 aarch64 上执行的二进制文件(似乎 shc 不能这样做)。
编辑:文件命令打印出来(在 aarch 机器上):
ELF 64 位 LSB 可执行文件,x86-64,版本 1 (SYSV),动态链接,解释器 /lib64/ld-linux-x86-64.so.2,用于 GNU/Linux 2.6.32,BuildID[sha1] =f6f72e60c9ae8c2fd3abe5aa47f9ba6be7000be6,剥离
只是确认该文件适用于 x86-46
谢谢 masseyb。当我看到你的评论时,我正在尝试这样做。已经在arm机上使用了编译器,现在可以用了
简短的回答是在目标操作系统上编译二进制文件。来自 man
页面:
shc itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script.
编译生成包含机器代码的目标文件。机器代码 "may be regarded as the lowest-level representation of a compiled or assembled computer program or as a primitive and hardware-dependent programming language"(参考 https://en.wikipedia.org/wiki/Machine_code)。在 SunOS 11.3 SPARCv4 上编译源代码生成的机器代码将不包含与在 AIX PowerPC8 上编译相同源代码生成的机器代码相同的指令。
我在 x86-64 机器上使用 shc 将 bash 脚本转换为可执行二进制文件。这 运行 在我的机器上没问题,但我这样做是为了将它推送到 aarch64 机器上。将二进制文件复制到 aarch64 机器后,出现此错误:
无法执行二进制文件:执行格式错误
这似乎是由于此 OS 上的二进制文件未格式化为 运行 造成的。有谁知道一个工具可以给我一个可以在 aarch64 上执行的二进制文件(似乎 shc 不能这样做)。
编辑:文件命令打印出来(在 aarch 机器上):
ELF 64 位 LSB 可执行文件,x86-64,版本 1 (SYSV),动态链接,解释器 /lib64/ld-linux-x86-64.so.2,用于 GNU/Linux 2.6.32,BuildID[sha1] =f6f72e60c9ae8c2fd3abe5aa47f9ba6be7000be6,剥离
只是确认该文件适用于 x86-46
谢谢 masseyb。当我看到你的评论时,我正在尝试这样做。已经在arm机上使用了编译器,现在可以用了
简短的回答是在目标操作系统上编译二进制文件。来自 man
页面:
shc itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script.
编译生成包含机器代码的目标文件。机器代码 "may be regarded as the lowest-level representation of a compiled or assembled computer program or as a primitive and hardware-dependent programming language"(参考 https://en.wikipedia.org/wiki/Machine_code)。在 SunOS 11.3 SPARCv4 上编译源代码生成的机器代码将不包含与在 AIX PowerPC8 上编译相同源代码生成的机器代码相同的指令。