Author Topic: how to reserve stack space in my progam?  (Read 25201 times)

Offline tenim

  • Jr. Member
  • *
  • Posts: 3
how to reserve stack space in my progam?
« on: May 09, 2010, 10:48:11 AM »
hello,

i write my nasm programs under linux, 64bit. my only other experience are with tasm under dos(realmode).
in old tasm-style i reserved stack space for  my program by typing:
    .STACK 100h

how can i do this with nasm 2.08 in 64bit mode? the nasm manual says:

segment stack stack
        resb 64
stacktop:

but, if i try to assembe this code, nasm says:
prog1.asm:5: warning: Unknown section attribute 'stack' ignored on declaration of section `stack'
prog1.asm:6: warning: uninitialized space declared in non-BSS section `stack': zeroing

after linking, i run inside(gdb gui) and load my new binary. if i klick in inside on the "stack"-button he says everytime "no stack".


a second question:
which way is generally better to link my .o file? with ld or over gcc?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: how to reserve stack space in my progam?
« Reply #1 on: May 09, 2010, 03:11:27 PM »
"segment stack stack" is known only in "-f obj" output - the old dos OMF format for making MZ executables. You didn't see that in a 64-bit section of the Manual (I hope!). We haven't told the OS where the stack is since... well, since dos. The OS tells us, these days. In a 32-bit program, you reserve stack space by subtracting something from esp. I ASSume it's the same for 64-bit - rsp, of course - but 64-bit code is apparently much fussier about alignment. 64-bit questions are "above my pay grade".

I can't imagine why gdb is claiming "no stack". No value at all in rsp? :)

My preference is, if I don't have anything to compile, I don't use gcc. You might think, if we're using libc, we need the C "startup code" to be linked in. My experience has been that this isn't true. This seems "risky" to me, so I keep trying it. So far, it always works. 32-bit ld has a "glitch" in it - by default it wants to use "/lib/ld-linux.so.1", which doesn't exist on modern systems. We need to specify "-I /lib/ld-linux.so.2", or you get "file not found" when you try to execute the program - very confusing, 'cause my file's right there! An advantage to using gcc is that it knows what to tell ld. No idea what the situation is in 64-bit...

If you want to make 32-bit programs with your 64-bit tools, you'll need to tell them so, or they'll complain. Just "-386" for gcc, I think, and "-melf-i386" for ld - check me on those, I'm not sure...

http://www.x86-64.org/documentation.html

Supposed to be a 64-bit tutorial here (but the link doesn't work! :(

http://www.vikaskumar.org/wiki/amd64/amd64/index.htm

http://milw0rm.org/papers/110

You're in "pioneer territory" here, Tenim. Good luck!

Best,
Frank


Offline tenim

  • Jr. Member
  • *
  • Posts: 3
Re: how to reserve stack space in my progam?
« Reply #2 on: May 10, 2010, 10:06:43 AM »
Quote
We haven't told the OS where the stack is since... well, since dos. The OS tells us, these days.

ok, this means i can use in my progam any amount of stack space(if i have enough ram installed) without declaring it before in the quellcode because
the os reserves this ram dynamically if my progam needs more stack space(i.e. if i use push)?

the message "no stack" was given by "inside", the gdb frontend and can eventually a wrong mesage. i use now "ddd" als frontend für gdb because it don´t crashes if my program
has a segfault in contrast to insight. the only thing with ddd is to tell him to use "intel" syntax for displaying code and not at&t.
this works sometimes and sometimes he forget it.