How does such a minimal binary take up 300+ bytes?
Name:
Anonymous2014-04-26 23:56
Please help me learn assembly
I want to use as but I guess ill switch to nasm if it's better. Look I just need a tutorial that teaches me how to program assembly step by step on linux. Please?
Name:
Anonymous2014-04-26 23:59
How does such a minimal binary take up 300+ bytes?
probably the elf header and shit, try objdump -d to see maybe?
>>5 So according to this, my text and data segments only take up 26 bytes, and the other 314 bytes of my program are in the ELF header. What the fuck.
Also, confirmed that the data segment is writeable. Another what the fuck.
Name:
Anonymous2014-04-27 5:41
>>7 Of course data segment is writeable, as is bss segment. I think data is where your `int g_foo = 42; global variable goes, so you need that to be writeable so your variable is mutable.
Name:
Anonymous2014-04-27 5:46
>>7 A writeable .data segment is the norm. If you want fuck to be immutable, put it in .text or .rodata.
>>10 Actually 32 bit code is more efficient because all pointers are half as large; this has a significant effect on code density and instruction cache hit rate. In many cases this outweighs the benefits of the extra general purpose registers that are available in long mode.
Actually real mode is more efficient because all pointers are half as large; this has a significant effect on code density and int 21h cost. In many cases this outweighs the benefits of the extra register width and flat address space that are available in protected mode.
>>11 That's because the DOS COM ``format'' isn't an executable format in any modern sense. DOS just dumped the contents of a .COM file into memory at a fixed address and jumped into it. So you have no dynamic linking, no position independent code, no relocation, nothing. If you want any of that, you need that header ``boilerplate''.
Name:
Anonymous2014-04-27 7:28
>>14 nothing stops COM code from relocating itself.
Name:
Anonymous2014-04-27 7:37
>>13 The functional improvement going from real mode to protected mode is much larger than going from protected mode to long mode. Nearly all modern programs benefit (or even require) memory protection and a 4 GiB virtual address space. Conversely only certain workloads benefit from a 128 TiB virtual address space; for other applications the benefit of sticking with 32 bit pointers in long mode is so large that the Linux kernel supports a whole second 32-bit ABI specifically to allow for it.
Name:
Anonymous2014-04-27 7:40
>>15 It's a pointless exercise to write special purpose loader code for every program that needs to be relocated. The whole point of having a standard executable format is to make it possible for multiple programs to share the same loader.
It's a pointless exercise to write special purpose loader code for every program that needs to be relocated.
That is why we have compiler and static linker. OS kernel shouldn't do anything more than providing hardware abstraction layer. Everything else should be reconfigurable.
>>18 When did this become an operating systems discussion?
You are free to reinvent the wheel for every program you write. However I imagine after you've written the same dumb boilerplate loader code for three or four programs I imagine you will end up rearranging the combined result into something that looks a lot like loaders others have already written.
>>18 Also, as a side note - dynamic linkers need not be part of the kernel, and in practice they often are not. On Linux systems the dynamic linkers are just libraries can indeed be replaced.
Works just as okey. For example, Windows 3.1 provided it's own linker.
Name:
Anonymous2014-04-27 9:56
>>8,9 Ah, ok. I relocated fuck to .rodata and bork segfaulted as expected. I also objdump -x'd this program and confirmed that it sticks the string in .rodata:
>>33 You need to be careful that you only use each segment for its intended use. The text segment (.text) can contain both code and data (keeping in mind that any data you place in the text segment cannot be changed by your program during execution). The initialized part of the data segment (.data) should contain just data, not code. And the uninitialized part of the data segment (.bss) cannot have values placed in it as assembly time at all -- all you can do here is allocate memory (that is, add to the total amount of memory to be included as uninitialized data). In all three types of segment, you can define symbolic labels; such a label has as its value an address within that segment.
section .text global foo foo: push ebp ; save ebp onto the stack mov ebp,esp ; save the stack pointer in ebp push msg ; push argument onto the stack call puts add esp,4 ; skip past 'msg' on the stack mov esp,ebp ; reset the stack??? pop ebp ; restore ebp
mov eax,1 ; sys_exit mov ebx,0 ; 0 int 0x80
not totally sure its correct.. and I'd like to do it without a .c file
Name:
Anonymous2014-04-29 0:06
>>34 Fuck you, I make a new segment for every function I need and it's never bitten me in the ass.
Who cares about Windows asm any more anyway. Is it because AT&T syntax is such ugly garbage? Yeah, GCC made a blunder choosing that one.
Also, FASM is better than nasm.
Name:
Anonymous2014-04-29 0:15
>>36 FASM is the CL of assemblers, that is, for niggers
>>38 What assembler is better than FASM? And what the fuck do you mean by ``hipster''? You could say ``normalfag'' as fucking every ``normal'' person uses ruby or python.
Name:
Anonymous2014-04-29 10:49
>>38 i think you're stuck with at&t syntax for inline asm though