Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [12:27] • Vulpes raises hand:
- [12:27] Vulpes: if I empty off my floating register-stack, will it affect other variables that I have set outside my assembly code?
- [12:29] Vulpes: ie, if I: main(){ double a=1.0f; assembly_call_erases_fpstack(); printf("%f \n",a); etc...
- [12:29] Vulpes: in my code, a is now NAN. was the float value never saved to memory?
- [12:30] Jester01: maybe. check the assembly code. and the calling convention documentation :)
- [12:33] Jester01: generally you should only pop values you pushed
- [12:34] iiyo ([email protected]) joined the chat room.
- [12:36] Jester01: for the record, my gcc moves the variable initialization to after the assembly call
- [12:37] • Jester01 tries passing "a" as argument
- [12:37] Vulpes: I can link you my code, but I'm not sure you want to get your hands this dirty
- [12:38] Jester01: sure :)
- [12:39] arek_deepinit ([email protected]) joined the chat room.
- [12:39] • Vulpes looks at his .c
- [12:39] zach (817442c2@gateway/web/freenode/ip.129.116.66.194) joined the chat room.
- [12:39] Vulpes: wait ... hold up
- [12:39] AlbertoSilva ([email protected]) left the chat room. (Read error: Connection reset by peer)
- [12:39] Jester01: no matter what I did so far, gcc always called other functions with empty fpu stack
- [12:40] AlbertoSilva ([email protected]) joined the chat room.
- [12:42] monsterwizard ([email protected]) left the chat room. (Read error: Connection reset by peer)
- [12:42] FUZxxl ([email protected]) left the chat room. (Quit: euler=:[:+/i.*[:+./0=3 5|"0 1 i.)
- [12:42] zach: i have something strange going on when I assemble something with nasm. The line verbatim is "BootDrive equ bp-2" but it gives the error "invalid operand type." Help?
- [12:44] Jester01: that's invalid because EQU is trying to define a symbol with a known value. your value is dependent on value of the BP register at runtime. if you want simple text replacement, use a macro
- [12:44] Jester01: such as %define BootDrive bp-2
- [12:47] zach: ah, makes sense, thanks
- [12:47] Philopon ([email protected]) joined the chat room.
- [12:48] Vulpes: links:
- [12:48] Vulpes: http://pastebin.com/5q00PFs6 http://pastebin.com/BC8tmwx1
- [12:48] Vulpes: not necessary to view: http://pastebin.com/5NGJHAvJ http://pastebin.com/wc9JvVLr
- [12:49] Vulpes: so all I'm doing is loading all the floats up into the stack so I can print them out, which works
- [12:49] Vulpes: then I attempt to load them all back in
- [12:49] wobster ([email protected]) left the chat room. (Quit: wobster)
- [12:49] Vulpes: then I'm done ... or so I was to think so
- [12:51] Vulpes: on that 4th link, lines 144-151 print out the floats on the stack
- [12:51] Jester01: your asm code is wrong, but should not affect the C code
- [12:51] Vulpes: which were put in there on 2nd link lines 36-45
- [12:52] Vulpes: which places?
- [12:55] Vulpes: 37 & 39 are supposed to be dwords, right? not qwords? I'd assume so because they print out correctly
- [12:55] repozitor ([email protected]) left the chat room.
- [12:56] Jester01: you are popping 8 values from the stack, even if there were not that many present
- [12:56] Jester01: then you push them back
- [12:56] Jester01: so you will always return with a full stack
- [12:57] Vulpes: is there something wrong with that?
- [12:57] Jester01: furthermore, you are adjusting the stack pointer every time, so what is line 173 doing?
- [12:57] Jester01: YES
- [12:57] Jester01: as I said, you are not restoring the fpu stack
- [12:58] Jester01: you always pop off 8 values, even if there were not that many
- [12:58] Vulpes: oh sorry 173 sould be commented out
- [12:58] Jester01: and you always push 8 back
- [12:58] Jester01: suppose stack only had 1 value
- [12:58] Jester01: you pop 8 times
- [12:58] Jester01: then push back 8 items
- [12:58] Jester01: so now stack has 8 items instead of 1
- [12:59] Jester01: your test code does fill it with 8 values
- [12:59] Jester01: so it will work in that case
- [12:59] Vulpes: is there some sort of counter index that shows how many items are on the stack?
- [12:59] Burlingk ([email protected]) left the chat room. (Read error: Connection reset by peer)
- [12:59] Vulpes: I thought if you pushed too much it would fall off or popped too much, you would get garbage values, but nothing else
- [13:00] Vulpes: I figured if I popped everything off the float stack & then pushed it all back on, regardless if I took garbage numbers, all the data would be the same
- [13:00] Vulpes: am I not understanding instructions correctly?
- [13:02] Reversy ([email protected]) left the chat room.
- [13:03] plusk ([email protected]) joined the chat room.
- [13:05] nANdy (3ec730fd@gateway/web/freenode/ip.62.199.48.253) joined the chat room.
- [13:06] Jester01: hm you may be right about that (except for the stack overflow detection)
- [13:06] Jester01: stack top is stored in the fpu status register, btw.
- [13:07] • Vulpes learned something new
- [13:08] Jester01: HOWEVER .. FPU stack may be irrelevant to the current problem .. since you are not saving general purpose registers that you should definitely preserve
- [13:09] killown (~geek@unaffiliated/killown) joined the chat room.
- [13:09] Jester01: notably, ESI
- [13:10] Vulpes: ah, is my problem that my entire asm function isn't callee saving?
- [13:10] Vulpes: bbrb trying out
- [13:12] Jester01: seems to work here
- [13:13] Vulpes: eh? could I trouble you for your code?
- [13:13] Jester01: I just added push/pop esi to your test_floats and removed the unnecessary esp adjust
- [13:13] Jester01: note that the value of "c" is not preserved
- [13:14] Vulpes: that is fine.
- [13:14] Jester01: yah
- [13:14] Jester01: oh, and I have renamed your custom .txt to .text ;)
- [13:14] Jester01: which is probably irrelevant
- [13:15] Vulpes: I'm fuzzy on those pseudo ops, (not sure which fork to eat salad with)
- [13:15] Jester01: http://pastebin.com/uhgWMX9C
- [13:18] Vulpes: hmm
- [13:18] Vulpes: this is an interesting scenario
- [13:19] Jester01: I have checked, gcc here DID expect ESI to be unchanged
- [13:20] Vulpes: I wonder if it is the fact that I am running a VM
- [13:21] Vulpes: http://i.imgur.com/k60e9.png
- [13:22] Jester01: what happened with the code I pasted?
- [13:22] Jester01: crash? bad number?
- [13:22] Vulpes: xBFC82F38: -NAN
- [13:22] Vulpes: xBFC82F3C: -NAN
- [13:22] Vulpes: same rewrites to variables a & b
- [13:23] Jester01: http://pastebin.com/yHDdRQH4
- [13:24] Vulpes: thanks for that output paste, I am going to see if I can dissect that, brb
- [13:25] zach (817442c2@gateway/web/freenode/ip.129.116.66.194) left the chat room. (Quit: Page closed)
- [13:39] Jester01: or you can try this binary http://filesmelt.com/dl/a.out_.gz
- [13:39] Jester01: (static)
- [13:45] rendar ([email protected]) left the chat room.
- [13:46] Horgh^ ([email protected]) left the chat room. (Quit: ++)
- [13:49] Vulpes: thanks Jester01 your binary is perfect
- [13:50] Vulpes: I wonder if it's my arguments
- [13:50] Hack004 ([email protected]) left the chat room. (Ping timeout: 252 seconds)
- [13:50] Jester01: can you send me your binary?
- [13:50] Vulpes: ok hold up
- [13:50] Jester01: also, you can put a write watchpoint on the address of a or b in gdb
- [13:50] lane ([email protected]) joined the chat room.
- [13:50] Jester01: to catch who is overwriting it :)
- [13:53] Vulpes: http://filesmelt.com/dl/div_test.out_.tar.gz
- [13:55] Jester01: hmmm
- [13:55] Vulpes: you get the NANs?
- [13:55] Jester01: that only prints the registers for me
- [13:55] Jester01: no
- [13:55] Jester01: I only get a single general purpose register dump :-O
- [13:56] Vulpes: it doesn't even print the stack?
- [13:56] Vulpes: did it segfault?
- [13:56] Jester01: no
- [13:56] Jester01: and no
- [13:56] Vulpes: http://pastebin.com/sguEB2Tn
- [13:56] Jester01: it doesn't even print the *initial* C stuff about a,b,c
- [13:57] slidercrank ([email protected]) left the chat room. (Quit: NO CARRIER)
- [13:57] slidercrank ([email protected]) joined the chat room.
- [13:57] Jester01: http://pastebin.com/Zs67gJnQ
- [13:57] Jester01: that's all
- [13:58] Jester01: can you create a static version? just pass -static to gcc
- [13:58] Vulpes: 1 & 3 loaded in ecx & edx ... where they were supposed to have been loaded with ebp & esp before the subroutine call
- [13:58] Vulpes: I don't even.
- [13:59] Griwes (~griwes@unaffiliated/griwes) left the chat room. (Ping timeout: 244 seconds)
- [14:01] Philopon ([email protected]) left the chat room. (Quit: Philopon)
- [14:03] plusk ([email protected]) left the chat room. (Quit: Leaving)
- [14:07] lane ([email protected]) left the chat room. (Ping timeout: 252 seconds)
- [14:08] arek_deepinit ([email protected]) left the chat room. (Read error: Connection reset by peer)
- [14:09] Jester01: hm, valgrind has trouble with "enter"
- [14:09] • Jester01 gets rid of it ... the enter, not valgrind :)
- [14:10] LunaVorax ([email protected]) joined the chat room.
- [14:10] Vulpes: hmm, maybe I really should forsake "enter" & go with the push ebp ; mov ebp esp
- [14:11] Jester01: ==22766== Use of uninitialised value of size 4
- [14:11] Jester01: ==22766== Conditional jump or move depends on uninitialised value(s)
- [14:11] Jester01: both inside printf
- [14:11] Vulpes: oh you know what
- [14:12] Vulpes: I disregard scope when printing out the stack
- [14:12] Jester01: ah yes
- [14:12] Jester01: that looks harmless
- [14:12] Jester01: and no other errors reported
- [14:12] Reversy ([email protected]) joined the chat room.
- [14:12] Smartnow (~Smartnow@unaffiliated/smartnow) joined the chat room.
- [14:12] Reversy ([email protected]) left the chat room.
- [14:12] Jester01: so, do you create a static version for me?
- [14:13] Jester01: maybe libc differences make your version not run here
- [14:13] Jester01: but first get rid of the "enter" instructions :)
- [14:14] SunnyD ([email protected]) joined the chat room.
- [14:15] Vulpes: I'm a bit unsavvy with the term. is that an assembly argument?
- [14:15] Vulpes: assembler*
- [14:15] Vulpes: also I made up that "unsavvy" word & realized it is not in the dictionary
- [14:19] Vulpes: I presume: gcc -static-libgcc
- [14:21] ImTheBitch ([email protected]) joined the chat room.
- [14:22] Jester01: no, just -static
- [14:22] jadugar (~jadugar@gateway/tor-sasl/jadugar) left the chat room. (Quit: leaving)
- [14:24] Jokke (6d5af7d9@gateway/web/freenode/ip.109.90.247.217) left the chat room. (Ping timeout: 265 seconds)
- [14:25] Vulpes: http://filesmelt.com/dl/div_test.out_.tar1.gz
- [14:25] Jester01: ahhhhha! got the nans :)
- [14:26] BoarderX ([email protected]) left the chat room. (Ping timeout: 260 seconds)
- [14:26] Vulpes: heh, maybe I should subtract biinfiles from eachother & see what the difference is
- [14:27] Jester01: I got the nan here locally
- [14:27] Jester01: turns out it only happens if you are NOT optimizing
- [14:27] neuro_sys (~neuro@unaffiliated/neurosys/x-283974) joined the chat room.
- [14:28] Vulpes: if I'm not optimizing, I'll get a NAN written to my float variables in the .c ?
- [14:28] Jester01: strangely enough they are all right in memory
- [14:34] Jester01: mmh, you get FPU stack overflow
- [14:37] Fabba (unknown@unaffiliated/fabba) joined the chat room.
- [14:37] ThFabba (unknown@unaffiliated/fabba) left the chat room. (Disconnected by services)
- [14:37] Fabba is now known as ThFabba.
- [14:37] Vulpes: hmm, ok.
- [14:37] Vulpes: so stackoverflow occurs when I'm just pumping the 1s & 0s into the stack, right?
- [14:38] kramaus ([email protected]) joined the chat room.
- [14:38] monsterwizard ([email protected]) joined the chat room.
- [14:38] Jester01: oh, you fill the fpu stack with 8 numbers, then during printing you pop and push them back
- [14:38] nazriel ([email protected]) joined the chat room.
- [14:38] Jester01: so they are LEFT on the stack
- [14:39] Vulpes: therefore ... I think I'll try unloading the fpu stack first, but by how much? how do I access the fpu status register?
- [14:39] Jester01: nonono
- [14:39] Jester01: in this case you DO know you have put 8 values on the stack
- [14:39] Jester01: but you LEAVE them there!
- [14:39] Vulpes: yes
- [14:39] Jester01: that's bad.
- [14:39] Vulpes: I'm supposed to clear it all out save st0?
- [14:39] Jester01: test_floats puts the values there, it should also remove them
- [14:39] • Jester01 tries
- [14:40] Jester01: erm
- [14:40] Jester01: except for 1
- [14:40] Jester01: the function return value ;)
- [14:40] Jester01: yay that worked
- [14:41] • Vulpes gets excited
- [14:41] Jester01: I added 7 fstp st0 lines to the end of test_floats
- [14:42] Jester01: nevertheless, your print_fpstack should correctly handle the stack size
- [14:42] Vulpes: YES!!
- [14:42] Vulpes: thank you so much
Advertisement
Add Comment
Please, Sign In to add comment