Error:
Problem Solving Process:
1, first determine the CPU architecture
2, this is a 64-bit architecture of the CPU, if the use of ELF parameters, the default is in 32-bit mode to deal with, then need more precise to specify this mode, such as ELF32 (32-bit), ELF64 (64-bit), the specific reference: http://www.nasm.us/doc/ Nasmdoc7.html
Then rewrite the above can be as follows:
Nasm-f elf64-g-F stabs sandbox.asm-o sandbox. old-o sandbox. O
3, if you want to compile 32-bit and 64-bit combination, then you can start from the link, the wording can be changed to:
Nasm-f elf-g-F stabs sandbox.asm-o sandbox. old-m elf_i386-o sandbox. O
In fact, this should be wrong, can not be said to be a combination, but should be said to be a link to a compatible 32-bit mode application.
Because from above can read, elf default is 32 for, and Elf_i386 also is 32 bit, where elf_x86_64 is 64 bit. So, it should be compatible.
Perhaps the above is not professional, or said: Nasm compiled out is 32-bit, and the linker LD link 32-bit application to 64-bit as an executable file, it is wrong to do, you should link 32-bit application to 32-bit as an executable file.
Therefore, I think it should not be related to the CPU architecture, but should be related to the operating system, the operating system to distinguish between 32-bit and 64-bit, and many of the assembly examples are still stuck on the 32-bit x86, causing the above problems arise.
Another point, when using LD, some books will write "Ld-m Elf_i386-o sandbox.o Sandbox", now the new version is not supported.
Reference:
https://stackoverflow.com/questions/31369916/ Unable-to-compile-assembly-usr-bin-ld-i386-architecture-of-input-file-array1?rq=1
Https://stackoverflow.com/questions/19200333/architecture-of-i386-input-file-is-incompatible-with-i386x86-64
Https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
https://stackoverflow.com/questions/11748970/how-to-pass-m-elf-i386-to-gcc
Ubuntu 16.04 uses NASM when compiling with the LD linker: The i386 architecture is incompatible with the i386:x86-64 output of the input file SANDBOX.O (I386 architecture in the input files SANDBOX.O is Not compatible with i386:x86-64 output)