no matter what I do to nasm I can't get it to make an assembled program, it keeps making this file, and when I check it's file type, all it says is "data", when I try to run it, it says "cannot execute binary files", I want it to just assemble something, and I want to do it with out making object files or linking at all, can someone please help me?, I am using Ubuntu linux version 10.04:irritated:
14 replies to this topic
#1
Posted 02 August 2010 - 04:33 PM
|
|
|
#2
Posted 02 August 2010 - 07:44 PM
It can be done in three simple steps, Run the following to compile it:
nasm -f elf foo.asmto link linux provides ld with GNU binutils (which Ubuntu should have):
ld -s -o foo foo.oFinally just ./foo to run it.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 03 August 2010 - 09:52 AM
Nullw0rm said:
It can be done in three simple steps, Run the following to compile it:
nasm -f elf foo.asmto link linux provides ld with GNU binutils (which Ubuntu should have):
ld -s -o foo foo.oFinally just ./foo to run it.
well actually I don't really think I need to link it, so I was wondering if someone could tell me if nasm can assemble it without linking, but thanks anyway, I will be sure to try that:)
I mean it is just a hello world
Edited by Basix, 03 August 2010 - 09:53 AM.
clarification
#4
Posted 03 August 2010 - 10:42 AM
Basix said:
I mean it is just a hello world
Doesn't matter. If you want a "normal" application, you have to link it.
Greets,
artificial
Sometimes words ain't enough to express something. That's why computer scientists use double words.
#5
Posted 03 August 2010 - 12:41 PM
artificial said:
Doesn't matter. If you want a "normal" application, you have to link it.
Greets,
artificial
Greets,
artificial
can linux run programs that aren't linked?, and do compilers/assembler give you the option of not linking?
#6
Posted 03 August 2010 - 05:10 PM
I don't believe you understand how computers work. The compiler will assemble machine code out of the source, the assembler assembles machine code. All it is, is different sections of data, you cannot run it. Linking the sections (thus using a linker) puts the machine code in an executable format, providing entry points to the machine language etc, you can't skip it. Of course you can tell it to keep not linked, but you're not going to get anywhere with that.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#7
Posted 07 August 2010 - 06:17 PM
Not linking code is only good for creating libraries. The only way you can get out of linking (kinda) is to use the -f option on nasm and set the output format to "bin." You can only use this if you're writing your own code that'll be executed by the processor directly, i.e. without an operating system present. Not too useful except for low-level development. Is that what you're looking for?
By the way, how are you doing this Hello World app without using system functions? If you're trying to use interrupts it'll explode on a modern operating system. (Windows allows raw binaries to execute like this, but the programs are sandboxed and can't do a whole ton. Plus code, data, and stack is limited to 64K combined.)
By the way, how are you doing this Hello World app without using system functions? If you're trying to use interrupts it'll explode on a modern operating system. (Windows allows raw binaries to execute like this, but the programs are sandboxed and can't do a whole ton. Plus code, data, and stack is limited to 64K combined.)
sudo rm -rf /
#8
Posted 09 August 2010 - 08:41 AM
Nullw0rm said:
I don't believe you understand how computers work. The compiler will assemble machine code out of the source, the assembler assembles machine code. All it is, is different sections of data, you cannot run it. Linking the sections (thus using a linker) puts the machine code in an executable format, providing entry points to the machine language etc, you can't skip it. Of course you can tell it to keep not linked, but you're not going to get anywhere with that.
I thought I understood how computers work, so you are saying that when the assembler is done assembling, it still can't be run by the cpu?, I am pretty sure that a program doesn't need to be linked just to be runnable, I am pretty sure that operating systems aren't linked to anything
#9
Posted 09 August 2010 - 06:09 PM
Basix said:
when the assembler is done assembling, it still can't be run by the cpu?
Quote
I am pretty sure that a program doesn't need to be linked just to be runnable, I am pretty sure that operating systems aren't linked to anything
1) Have one gigantic source code file with all your code
2) Don't rely on anything you didn't write yourself.
3) Can't have an operating system run your code. Your code essentially is the operating system.
Even then, the compiler just spits out an object file. You need to tell the linker that you want a flat binary with no extra OS-dependent information. There's no escaping the linker.
sudo rm -rf /
#10
Posted 10 August 2010 - 12:19 PM
dargueta said:
The answer is almost always no. Compilers--NASM included--typically output object files that contain the code necessary to run, but not all of it. The operating system needs to add some runtime libraries so it can load it properly, get any extra functions from outside libraries, pass it arguments, perform any cleanup operations, and so on.
That's because operating systems aren't executable formats. They're just raw binary code. The operating system defines its own executable formats which all programs that run on it need to adhere to. This way the operating system knows exactly what to expect and can handle the program appropriately. When you compile a C/C++ program, the compiler does the linking behind your back and spits out an executable. You need the C runtime libraries to use printf() and all that. The only way you can not need linking to system libraries--system libraries, mind you--is if you:
1) Have one gigantic source code file with all your code
2) Don't rely on anything you didn't write yourself.
3) Can't have an operating system run your code. Your code essentially is the operating system.
Even then, the compiler just spits out an object file. You need to tell the linker that you want a flat binary with no extra OS-dependent information. There's no escaping the linker.
That's because operating systems aren't executable formats. They're just raw binary code. The operating system defines its own executable formats which all programs that run on it need to adhere to. This way the operating system knows exactly what to expect and can handle the program appropriately. When you compile a C/C++ program, the compiler does the linking behind your back and spits out an executable. You need the C runtime libraries to use printf() and all that. The only way you can not need linking to system libraries--system libraries, mind you--is if you:
1) Have one gigantic source code file with all your code
2) Don't rely on anything you didn't write yourself.
3) Can't have an operating system run your code. Your code essentially is the operating system.
Even then, the compiler just spits out an object file. You need to tell the linker that you want a flat binary with no extra OS-dependent information. There's no escaping the linker.
so then how do I tell it not to link the programs?, and can modern operating systems run anything that isn't linked?
#11
Posted 10 August 2010 - 11:45 PM
You don't want it to not link, otherwise most modern operating systems won't let you run it. Windows does allow you to run small raw binaries, but with some restrictions. Why is beyond me, as it's a huge potential security hole.
You can't run object files.
You can't run object files.
sudo rm -rf /
#12
Posted 11 August 2010 - 08:33 AM
dargueta said:
You don't want it to not link, otherwise most modern operating systems won't let you run it. Windows does allow you to run small raw binaries, but with some restrictions. Why is beyond me, as it's a huge potential security hole.
You can't run object files.
You can't run object files.
why would it be a security hole?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









