Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

assembly - Use ld on 64-bit platform to generate 32-bit executable

I wrote an assembly that is assemble with:

$as --32 -o hello.o hello.s

Then I tried to generate an executable with:

$ld -o hello hello.o

It gives me an error:

ld: i386 architecture of input file `ConditionalBranching.o' is incompatible with i386:x86-64 output

I tried using flag -m32 or --32, but ld dont take them. I cannot find a solution by reading the man page of ld. How can I generate a 32-bit binary from my 32-bit shared object?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your linker is attempting to create a 64-bit binary, but your assembly code was assembled for a 32-bit architecture. This creates a mismatch.

Fix this by passing the -m elf_i386 flag to your linker, explicitly instructing it to create a 32-bit binary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...