Author Topic: Cannot execute binary file  (Read 19064 times)

nobody

  • Guest
Cannot execute binary file
« on: October 18, 2008, 01:08:59 PM »
I have problem with execution of assembler program on linux. The error is "Cannot execute binary file". I set chmod to execute, but it doesn't work. Where is problem?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Cannot execute binary file
« Reply #1 on: October 18, 2008, 05:06:24 PM »
Sounds like a problem with the header. If the problem were lack of executable permission, the error message would have been "permission denied".

The "normal" way to create an executable would be "nasm -f elf myfile.asm" (possibly "-g", "-F dwarf", "-Ox" added), followed by "ld -o myfile myfile.o".

Alternatively, we can stuff the ELF header into the source (starting with 7F 'E' 'L' 'F'), and assemble with "-f bin" (Nasm's default). This will require "chmod +x", since Nasm doesn't know about file permissions.

Exactly what *did* you do to get this result?

Best,
Frank

nobody

  • Guest
Re: Cannot execute binary file
« Reply #2 on: October 27, 2008, 03:24:20 PM »
Thanks for ld -o myfile myfile.o and it works (I don't use this before), but in some case after use nasm and ld, the compiled program don't work properly and the message is "Segmentation fault", and I don't know where is a problem. I tested this same program on Windows with Tasm and it works, but on Linux with nasm it doesn't.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Cannot execute binary file
« Reply #3 on: October 27, 2008, 10:23:29 PM »
It is possible to write source code that will run on Windows or Linux, by extensive use of conditional assembly (gets real ugly real quick!), or by using portable libraries for *all* interaction with the OS. Besides the obvious C library, vid's FasmLib or the HLA standard library exist in Windows and Linux forms... maybe others. Besides the "underscores or not" issue, other trickery may be required.

As a general rule, programs written for Windows won't run on Linux, and visa versa (different OS, doncha know...). Furthermore, there are differences between Tasm and Nasm syntax - even if it assembles without complaint, it may not be right. Nasm is supposed to assemble some subset of Tasm code with the "-t" switch and some include files - I've never gotten it to work without some "hand editing" of the source.

I don't think we can help you find the problem without seeing the code. Post it here, if it's not too long, or put it up somewhere we can find it... mail it to me - fbkotler verizon net - if all else fails, and we'll see if we can help you get it going...

Best,
Frank