Assembly 为什么Clang调用%eip+;1将double转换为ulonglong时?

Assembly 为什么Clang调用%eip+;1将double转换为ulonglong时?,assembly,x86,clang,long-integer,abi,Assembly,X86,Clang,Long Integer,Abi,结果存储在哪里?我读到它通常是%eax,但是64位uint太宽了。我在堆栈中也找不到结果 % clang --version Debian clang version 3.1-3eudoxos1 (branches/release_31) (based on LLVM 3.1) Target: i386-pc-linux-gnu Thread model: posix 叮当声输入(已更新,签名现在对应于名称): 编译和反汇编(已更新,添加了重新定位信息。现在使用fixuns*d*fdi。):

结果存储在哪里?我读到它通常是%eax,但是64位uint太宽了。我在堆栈中也找不到结果

% clang --version
Debian clang version 3.1-3eudoxos1 (branches/release_31) (based on LLVM 3.1)
Target: i386-pc-linux-gnu
Thread model: posix
叮当声输入(已更新,签名现在对应于名称):

编译和反汇编(已更新,添加了重新定位信息。现在使用fixuns*d*fdi。):

大会:

% as -g -o main.o -c main.s                            
链接:

% gcc -g -o executableelf stackoverflow.o main.o       
调试:

% gdb executableelf                             
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Reading symbols from /home/janus/asmplay/conv/executableelf...done.
(gdb) start
Temporary breakpoint 1 at 0x80483cc: file main.s, line 6.
Starting program: /home/janus/asmplay/conv/executableelf 

Temporary breakpoint 1, main () at main.s:6
6       pushl a+4
(gdb) list
1   .data
2       a: .double 6.283045
3   .text
4   .globl main
5   main:
6       pushl a+4
7       pushl a
8       call double2ulonglong
9       addl $8, %esp
10      ret
(gdb) break 8
Breakpoint 2 at 0x80483d8: file main.s, line 8.
(gdb) c
Continuing.

Breakpoint 2, main () at main.s:8
8       call double2ulonglong
(gdb) stepi
0x080483b4 in double2ulonglong (a=-1.9971046447753908)
(gdb) disass
Dump of assembler code for function double2ulonglong:
=> 0x080483b4 <+0>: sub    $0xc,%esp
   0x080483b7 <+3>: movsd  0x10(%esp),%xmm0
   0x080483bd <+9>: movsd  %xmm0,(%esp)
   0x080483c2 <+14>:    call   0x80483f0 <__fixunsdfdi>
   0x080483c7 <+19>:    add    $0xc,%esp
   0x080483ca <+22>:    ret    
End of assembler dump.
(gdb) break *($eip+19)
Breakpoint 3 at 0x80483c7: file stackoverflow.c, line 2.
(gdb) c
Continuing.

Breakpoint 3, 0x080483c7 in double2ulonglong (a=6.2830450000000004) at stackoverflow.c:2
2       return a;
(gdb) x/16x $esp
0xbffff374: 0x8c692f6f  0x401921d6  0xb7fb9ff4  0x080483dd
0xbffff384: 0x8c692f6f  0x401921d6  0xb7e324d3  0x00000001
0xbffff394: 0xbffff424  0xbffff42c  0xb7fdc858  0x00000000
0xbffff3a4: 0xbffff41c  0xbffff42c  0x00000000  0x0804820c
(gdb) 
%gdb executableelf
GNU gdb(Ubuntu/Linaro 7.4-2012.04-0ubuntu2)7.4-2012.04
从/home/janus/asmplay/conv/executableelf…读取符号完成。
(gdb)启动
临时断点1位于0x80483cc:file main.s,第6行。
启动程序:/home/janus/asmplay/conv/executableelf
main.s处的临时断点1,main():6
6推拉a+4
(gdb)清单
1.数据
2 a:双6.283045
3.文本
4.环球大道
5主要:
6推拉a+4
7推拉
8呼叫double2ulonglong
9加8美元,特别是
10 ret
(gdb)中断8
断点2位于0x80483d8:file main.s,第8行。
(gdb)c
持续的。
断点2,main()位于main.s:8
8呼叫double2ulonglong
(gdb)stepi
0x080483b4在double2ulonglong中(a=-1.9971046447753908)
(gdb)disass
函数double2ulonglong的汇编程序代码转储:
=>0x080483b4:sub$0xc,%esp
0x080483b7:movsd 0x10(%esp),%xmm0
0x080483bd:movsd%xmm0,(%esp)
0x080483c2:调用0x80483f0
0x080483c7:添加$0xc,%esp
0x080483ca:ret
汇编程序转储结束。
(gdb)中断*($eip+19)
断点3位于0x80483c7:文件stackoverflow.c,第2行。
(gdb)c
持续的。
stackoverflow处double2ulonglong(a=6.2830450000004)中的断点3,0x080483c7。c:2
2返回a;
(gdb)x/16x$esp
0xbffff374:0x8c692f6f 0x401921d6 0xb7fb9ff4 0x080483dd
0xbffff384:0x8c692f6f 0x401921d6 0xb7e324d3 0x00000001
0xbffff394:0xbffff424 0xbffff42c 0xb7fdc858 0x00000000
0xbffff3a4:0xbffff41c 0xbffff42c 0x00000000 0x0804820c
(gdb)
编辑:修复C函数中的签名,链接后显示反汇编

剩余问题:

  • 为什么堆栈中没有未签名的int 6?
    • 回答:它在%eax中

您正在查看尚未链接的对象文件的内容,因此外部引用尚未解析。该函数可能正在调用某些编译器帮助程序,该调用将在链接时解析。如果将
-r
开关添加到objdump,它将在呼叫站点打印重新定位信息


至于结果,i386的约定是使用
edx:eax
对返回64位整数。

我不明白
e8 fc ff
将直接调用
fc
字节,对吗?我不明白这有什么意义。是的,我想是的。但是要小心,
%eip+1
只是我的解释,因为
objdump
表示指令的开头是0xe。当在
gdb
(链接后)中调试它时,它看起来是这样的:
0x080483c2:call 0x80483f0
,这是因为
hex(0x080483b4+0xf)=0x80483c3
哦,它没有链接,好吧,这里没什么问题,但是你看到链接后它也在调用
%eip+1
?什么是
\uuuuuuu fixunssfdi
\uuuu fix
转换为固定
uns
无符号
sf
单精度浮点到
di
64位整数。在返回主
信息寄存器之前,
给出:eax=0x6 edx=0x0。我一直认为结肠的右侧是最不重要的部分,但实际上它看起来是相反的。那么eax是最低有效位吗?是的,eax持有较低的部分。我想我应该修改我的答案,让它不那么混乱。。。
% as -g -o main.o -c main.s                            
% gcc -g -o executableelf stackoverflow.o main.o       
% gdb executableelf                             
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Reading symbols from /home/janus/asmplay/conv/executableelf...done.
(gdb) start
Temporary breakpoint 1 at 0x80483cc: file main.s, line 6.
Starting program: /home/janus/asmplay/conv/executableelf 

Temporary breakpoint 1, main () at main.s:6
6       pushl a+4
(gdb) list
1   .data
2       a: .double 6.283045
3   .text
4   .globl main
5   main:
6       pushl a+4
7       pushl a
8       call double2ulonglong
9       addl $8, %esp
10      ret
(gdb) break 8
Breakpoint 2 at 0x80483d8: file main.s, line 8.
(gdb) c
Continuing.

Breakpoint 2, main () at main.s:8
8       call double2ulonglong
(gdb) stepi
0x080483b4 in double2ulonglong (a=-1.9971046447753908)
(gdb) disass
Dump of assembler code for function double2ulonglong:
=> 0x080483b4 <+0>: sub    $0xc,%esp
   0x080483b7 <+3>: movsd  0x10(%esp),%xmm0
   0x080483bd <+9>: movsd  %xmm0,(%esp)
   0x080483c2 <+14>:    call   0x80483f0 <__fixunsdfdi>
   0x080483c7 <+19>:    add    $0xc,%esp
   0x080483ca <+22>:    ret    
End of assembler dump.
(gdb) break *($eip+19)
Breakpoint 3 at 0x80483c7: file stackoverflow.c, line 2.
(gdb) c
Continuing.

Breakpoint 3, 0x080483c7 in double2ulonglong (a=6.2830450000000004) at stackoverflow.c:2
2       return a;
(gdb) x/16x $esp
0xbffff374: 0x8c692f6f  0x401921d6  0xb7fb9ff4  0x080483dd
0xbffff384: 0x8c692f6f  0x401921d6  0xb7e324d3  0x00000001
0xbffff394: 0xbffff424  0xbffff42c  0xb7fdc858  0x00000000
0xbffff3a4: 0xbffff41c  0xbffff42c  0x00000000  0x0804820c
(gdb)