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

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

问题描述

我最初认为 64 位指令不适用于 OS-X 10.5.

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

我写了一个小测试程序并用GCC -m64编译它.我使用 long long 作为我的 64 位整数.

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

所使用的汇编指令看起来像是 64 位的.例如.imultqmovq 8(%rbp),%rax.

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

我似乎在工作.

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

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

  1. 这是预期的行为吗?
  2. 是否有任何陷阱会导致此操作失败?
  3. 我可以在一个问题中提出多个问题吗?
  4. 这是否适用于其他操作系统?

推荐答案

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

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

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

  • 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)

用户空间系统库和框架是在 10.5 和 10.6 上构建的 32/64 位胖子.您可以正常链接它们,无论您是为 32 位、64 位还是两者都构建.一些库(基本上是 POSIX 层)也在 10.4 上构建了 32/64 位胖子,但其中许多不是.

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.

在 10.6 上,构建工具默认生成 64 位可执行文件.在 10.5 及更早版本上,默认值为 32 位.

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

在 10.6 上,默认情况下,构建为胖的可执行文件将运行 64 位端.在 10.5 及更早版本中,默认执行 32 位端.

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.

您始终可以使用 arch 命令手动指定要使用的胖可执行文件的哪个切片.例如.arch -arch i386 someCommandToRunThatIWantToRunIn32BitMode.对于应用程序包,您可以从命令行启动它们,或者如果您获取有关应用程序的信息",则有一个首选项.

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 和 Linux 对 64 位可执行文件使用 LP64 模型.指针和long是64位宽,int仍然是32位,long long仍然是64位.(Windows 改为使用 LLP64 模型——long 在 64 位 Windows 中为 32 位宽).

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天全站免登陆