简体   繁体   English

编译aarch64二进制bash脚本

[英]Compile aarch64 binary bash script

I have used shc on an x86-64 machine to convert a bash script to executable binary. 我在x86-64机器上使用shc将bash脚本转换为可执行二进制文件。 This runs fine on my machine, but I am making this with the intention of pushing it to a aarch64 machine. 这在我的机器上运行良好,但是我打算将其推送到aarch64机器上。 After copying the binary to the aarch64 machine I get this error: 将二进制文件复制到aarch64计算机后,出现以下错误:

cannot execute binary file: Exec format error 无法执行二进制文件:Exec格式错误

This appears to be caused by the binary file not being formatted to run on this OS. 这似乎是由于二进制文件未格式化为在此OS上运行而引起的。 Does anyone know of a tool that will give me a binary file that can be executed on aarch64 (it doesn't appear that shc can do this). 有谁知道一个工具,该工具会给我一个可以在aarch64上执行的二进制文件(似乎shc可以做到这一点)。

EDIT : the file command prints this out (on the aarch machine): 编辑 :file命令将其打印出来(在aarch机器上):

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f6f72e60c9ae8c2fd3abe5aa47f9ba6be7000be6, stripped 用于GNU / Linux 2.6.32的ELF 64位LSB可执行文件,x86-64版本1(SYSV),动态链接,解释器/lib64/ld-linux-x86-64.so.2、BuildID[sha1]=f6f72e60c9ae8c2fd3abe5aa47f9ba6be7000be6 ,剥离

Just confirming that the file is for x86-46 只需确认该文件适用于x86-46

The short answer is to compile the binary on the target operating system. 简短的答案是在目标操作系统上编译二进制文件。 From the man page: 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. shc本身不是cc之类的编译器,而是对shell脚本进行编码和加密,并生成具有附加到期功能的C源代码。 It then uses the system compiler to compile a stripped binary which behaves exactly like the original script. 然后,它使用系统编译器来编译行为与原始脚本完全相同的剥离二进制文件。

Compilation produces an object file containing the machine code. 编译产生一个包含机器代码的目标文件。 Machine code "may be regarded as the lowest-level representation of a compiled or assembled computer program or as a primitive and hardware-dependent programming language" (ref. https://en.wikipedia.org/wiki/Machine_code ). 机器代码“可以被视为编译或组装的计算机程序的最低层表示,或被视为原始的和硬件相关的编程语言”(请参阅https://en.wikipedia.org/wiki/Machine_code )。 Machine code resulting from compiling the source code on SunOS 11.3 SPARCv4 will not contain the same instructions as machine code resulting from compiling the same source code on AIX PowerPC8. 在SunOS 11.3 SPARCv4上编译源代码所产生的机器代码将不包含与在AIX PowerPC8上编译相同源代码所产生的机器代码相同的指令。

Thanks masseyb. 谢谢masseyb。 I was just trying that when I saw your comment. 看到您的评论时,我只是在尝试。 It works now that I have used the compiler on the arm machine. 现在,我已经在arm机器上使用了编译器,因此可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM