assembly error: i386 architecture incompatible with i386:x86-64 output
I was following a simple tutorial on how to program and compile a hello world program using assembly when I got this error;
Quote:
Quote:
Quote:
the tutorial then asked me to compile the file with the command; Quote:
Quote:
Thanx in advance! |
Quote:
The asm code you used is 32 bit i386 assembler. The nasm command you gave assembles that into 32 bit elf. The ld command you gave attempts to link that into the native architecture for your machine (x86_64). Quote:
Quote:
Code:
ld -m elf_i386 -s -o hello hello.o That command should link 32 bit (i386) code on any system whose binary tools support i386, even if i386 is not the system's native architecture. Most x86_64 Linux distributions include enough i386 support for you to link and run that 32 program. I assume Linux Mint does, but I don't know how to be sure short of trying the above. BTW, you didn't need the hello.s file. The hello.asm file is the complete program in nasm syntax. The hello.s file is the same complete program, but in gas syntax. If I'm looking at the correct tutorial http://www.tldp.org/HOWTO/html_single/Assembly-HOWTO/ It also tells you to assemble the gas version with Code:
as -o hello.o hello.S Code:
ld -s -o hello hello.o So if you use the above as and ld commands, you are taking 32 bit source code and assembling and linking it as 64 bit binary. For this particular trivial program, that actually works. The 64 bit program produced from 32 bit source code will do the right thing. But if you try that with more advanced examples, it generally won't work. 32 bit source code usually needs to be assembled and linked to 32 bit binary. |
John,
Could you expound a bit on how a 64-bit system handles 32-bit code? When the chip is in 64-bit mode, it can still run 32-bit code, right? ie. when there is a task switch to a 32-bit piece of code, the CPU will enter "64-bit 32-bit mode", which is different from *just* 32-bit mode as entered upon at bootup time by the chip? Which will make it interpret the actual numbers going to the chip as 32-bit opcodes, instead of 64-bit ones? I *think* I read about this a long time back on Ars Technica, but my memory has failed me since then.... :) Thanks for your input. |
Quote:
Quote:
Quote:
Quote:
Quote:
|
Hello!
I have similar problem. When i wanna link assembly file with cpp file. I using commands: nasm -f elf funsumuj.asm -o funsumuj.o ld -shared funsumuj.o -o libfunsumuj.so g++ -c sumuj.cpp g++ sumuj.o funsumuj.o -o sumuj ./sumuj But it also doesn't work. Error with i have looks that: /usr/bin/ld: i386 architecture of input file `funsumuj.o' is incompatible with i386:x86-64 output With commands should i use? |
Quote:
In a g++ command, you use -m32 that same way (in addition to all the other options used on an i386 system). But your list of commands is a bit strange: You assemble funsumuj.asm into an object file, then link that into a .so, but then you link the object file (not the .so) into your final executable. So your ld command seems to be wasted. If your original commands would have worked on a 32 bit system, the following ought to work on x86-64 nasm -f elf funsumuj.asm -o funsumuj.o g++ -m32 -c sumuj.cpp g++ -m32 sumuj.o funsumuj.o -o sumuj ./sumuj If funsumuj.asm is really supposed to be used as a shared library, you would use nasm -f elf funsumuj.asm -o funsumuj.o ld -m elf_i386 -shared funsumuj.o -o libfunsumuj.so g++ -m32 -c sumuj.cpp g++ -m32 sumuj.o libfunsumuj.so -o sumuj ./sumuj |
Thank you very much.
|
It's still dont work.
I have error: Code:
administrator@ubuntu:~/Dokumenty$ g++ -m32 -c 2.cpp |
I'm not using Ubuntu, nor gcc4.6 myself, so I can't easily check any of this. On the systems I have access to features.h does not try to include predefs.h
But I did a google search on your error, and the various discussions of that error that I found indicate a piece of 32-bit support is not installed on your 64-bit Ubuntu. That piece can be installed with the command sudo apt-get install libc6-dev-i386 Note, I can't confirm that is correct. I just copied from discussion of the error message you quoted. I especially can't confirm that is the only required piece of 32bit support that you are missing. If that fixes this error, it might only advance you to some error indicating the next missing -i386 package. |
Quote
Quote:
Another option you could go with is to use the 64 bit for the loader: nasm -f elf64 betweenA.asm -o betweenA.o gcc -o between.out between.c betweenA.o ./between.out This would also be acceptable if you are missing dependencies. This way you can do the conversion in NASM. I understand that you are using the g++ and i am using the gcc...so i apologize...please try it out and see if it helps (i rarely work on high level languages anymore.) Below is the code i tested it on: For C: #include <stdio.h> int main(){ printf("In C!\n"); //only use prinf this way as it is an example...using it this way is asking to be exploited extern test_(); test_(); return 0; } For NASM: section .data msg db "In NASM!",0xA msgL equ $-msg section .text global test_ test_: mov EAX,4 mov EBX,1 mov ECX,msg mov EDX,msgL int 0x80 ret I hope this helps... :) |
Whenever you post code into dead topics, please use [code] and [/code] tags.
|
Understood.
Regards, Nilo |
All times are GMT -5. The time now is 01:37 PM. |