请教,X64平台上,写一个C程序,为什么用32bits来存放变量的地址?
X64平台上,写一个C程序,为什么用32bits来存放变量的地址?
如下的gval1的地址(第6行,对应bf 00 00 00 00 mov $0x0,%edi)
如果链接的时候把gval1放在高于4G的地址空间中,那不是程序就不对了?
gcc为什么不用 mov reg, imm64而用mov reg, imm32指令呢?# cat -n 1.c
1long int gval1 = 567;
2long int gval2 = 763;
3long int simple_l(long int *p, long int v);
4long int call_simple_l()
5{
6 long int z = simple_l(&gval1, 12L);
7 return z + gval2;
8}
# gcc -c -O3 1.c
# objdump -d 1.o
1.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <call_simple_l>:
0: 48 83 ec 08 sub $0x8,%rsp
4: be 0c 00 00 00 mov $0xc,%esi
9: bf 00 00 00 00 mov $0x0,%edi
e: e8 00 00 00 00 callq13 <call_simple_l+0x13>
13: 48 03 05 00 00 00 00 add 0x0(%rip),%rax # 1a <call_simple_l+0x1a>
1a: 48 83 c4 08 add $0x8,%rsp
1e: c3 retq
gcc 版本# gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.4 (SUSE Linux)
I got it.
使用-mcmodel={large,medium,kernel,small} 来控制
页:
[1]