spyre-project / spyre

simple YARA-based IOC scanner
GNU Lesser General Public License v3.0
164 stars 27 forks source link

How to build for 32-bit program of linux on 64-bit linux using musl-gcc #76

Closed N0body007 closed 2 years ago

N0body007 commented 2 years ago

Hi, I don't know how to build for 32-bit program of linux on 64-bit linux using musl-gcc, just like the spyre of i386-linux-musl, which I don't know how to generate on 64-bit linux. I have searched a lot,but don't find the solution.Could you help me out? Thanks in advance.

hillu commented 2 years ago

If you just type make and have all the build-dependencies listed in the README present, you will get four binaries:

The last one is your 32bit (i386) musl-libc-based statically linked binarry.

Or am I misunderstanding your question?

hillu commented 2 years ago

@N0body007 Does my answer help?

N0body007 commented 2 years ago

I’am sorry for taking so long to reply to you. I've been busy with other things recently and didn't pay attention to GitHub messages. I'am sorry again. I have read the makefile you wrote.But I want to build 32-bit program of linux on 64-bit linux using Linux terminal command. I have build 64-bit program of linux successfully using musl-gcc. But when I used the following command to build 32-bit program of linux on 64-bit linux, "GOOS=linux GOARCH=386 CGO_ENABLED=1 \ CC=musl-gcc \ PKG_CONFIG_PATH=${PREFIX_LINUX_MUSL}/lib/pkgconfig \ go build -ldflags '-extldflags "-static"' -tags yara_static -o simple-yara-musl ./_examples/simple-yara" I got the one of errors like this "/usr/bin/ld: i386 architecture of input file `/tmp/go-build2117339483/b062/_x008.o' is incompatible with i386:x86-64 output". I don't know how to specify the lib of 32-bit musl gcc.Could you help me out?Thanks again.

hillu commented 2 years ago

Try setting CGO_CFLAGS=-m32 for building i386 objects. This only works with the patch applied by _3rdparty)/patch-musl-spec.sh, though.

N0body007 commented 2 years ago

Thank you very much for your answer. Through your answer, I know how to solve this problem.

hillu commented 2 years ago

Glad I could help. Closing the issue now.