64位代码如何在OS-X 10.5上工作? [英] How does 64 bit code work on OS-X 10.5?

查看:143
本文介绍了64位代码如何在OS-X 10.5上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初认为64位指令在OS-X 10.5上不起作用。我写了一个小测试程序并用编译了它, GCC -m64
对于我的64位整数,我使用了 long long



使用的汇编指令看起来像是64位。例如。 imultq movq 8(%rbp),%rax



我只使用 printf 来显示64位值,使用%lld


  1. 这是预期行为吗?
  2. 是否有任何 gotcha的会导致此失败?

  3. 我允许在问题中提出多个问题吗?

  4. 这是否适用于其他操作系统?


解决方案

为了使这一点完全清楚,下面是OS X上32位和64位可执行文件的情况:


  • 32 - 和64位用户空间可执行文件可以在OS X 10.6的32位和64位内核上运行,无需仿真。在10.4和10.5上,32位和64位可执行文件都可以在32位内核上运行。 (在Windows上不是这样)

  • 用户空间系统库和框架在10.5和10.6上构建为32/64位胖。无论您是在构建32位,64位还是两者,您都可以正常关联它们。一些库(基本上是POSIX层)在10.4上也被构建为32/64位胖,但其中很多不是。 在10.6上,构建工具默认生成64位可执行文件。在10.5和更早版本中,缺省值是32位。 在10.6上,默认情况下,构建fat的可执行文件将运行64位版本。在10.5和更早版本中,默认情况下会执行32位方面。 code> arch 命令。例如。 arch -arch i386 someCommandToRunThatIWantToRunIn32BitMode 。对于应用程序包,您可以从命令行启动它们,或者如果您在应用程序中获取信息,则可以选择首选项。

  • OS X和Linux为64位可执行文件使用LP64模型。指针和 long 是64位宽, int 仍然是32位, long long 仍然是64位。 (Windows使用LLP64模型,而不是 - long 在64位Windows中为32位宽)。



I initially thought that 64 bit instructions would not work on OS-X 10.5.

I wrote a little test program and compiled it with GCC -m64. I used long long for my 64 bit integers.

The assembly instructions used look like they are 64 bit. eg. imultq and movq 8(%rbp),%rax.

I seems to work.

I am only using printf to display the 64 bit values using %lld.

  1. Is this the expected behaviour?
  2. Are there any gotcha's that would cause this to fail?
  3. Am I allowed to ask multiple questions in a question?
  4. Does this work on other OS's?

解决方案

Just to make this completely clear, here is the situation for 32- and 64-bit executables on OS X:

  • Both 32- and 64-bit user space executables can be run on both 32- and 64-bit kernels in OS X 10.6, without emulation. On 10.4 and 10.5, both 32- and 64-bit executables can run on the 32-bit kernel. (This is not true on Windows)

  • The user space system libraries and frameworks are built 32/64-bit fat on 10.5 and 10.6. You can link against them normally, whether you're building for 32-bit, 64-bit, or both. A few libraries (basically the POSIX layer) are also built 32/64-bit fat on 10.4, but many of them are not.

  • On 10.6, the build tools produce 64-bit executables by default. On 10.5 and earlier, the default is 32-bit.

  • On 10.6, executables that are built fat will run the 64-bit side by default. On 10.5 and earlier, the 32-bit side is executed by default.

  • You can always manually specify which slice of a fat executable to use by using the arch command. eg. arch -arch i386 someCommandToRunThatIWantToRunIn32BitMode. For application bundles, you can either launch them from the command line, or there is a preference if you "get info" on the application.

  • OS X and Linux use the LP64 model for 64-bit executables. Pointers and long are 64 bits wide, int is still 32 bits, and long long is still 64 bits. (Windows uses the LLP64 model instead -- long is 32 bits wide in 64 bit Windows).

这篇关于64位代码如何在OS-X 10.5上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆