64 位代码如何在 OS-X 10.5 上运行?

发布于 2024-08-26 02:28:42 字数 394 浏览 4 评论 0原文

我最初认为 64 位指令无法在 OS-X 10.5 上运行。

我编写了一个小测试程序并使用 GCC -m64 编译它。 我使用 long long 表示 64 位整数。

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

我好像工作了

我仅使用 printf 来使用 %lld 显示 64 位值。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

停滞 2024-09-02 02:28:42

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

  • 32 位和 64 位用户空间可执行文件都可以在操作系统中的 32 位和 64 位内核上运行X 10.6,无仿真。在 10.4 和 10.5 上,32 位和 64 位可执行文件都可以在 32 位内核上运行。 (Windows 上并非如此)

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

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

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

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

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

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

二货你真萌 2024-09-02 02:28:42

Mac OS X 10.5 很好地支持 64 位用户态应用程序。事实上,Xcode 在 10.5 中以 64 位运行在兼容的架构上。

只是内置应用程序(Finder、Safari、框架、守护进程等)在 10.6 中也有 64 位版本。

Mac OS X 10.5 supports 64-bit user-land applications pretty well. In fact, Xcode runs in 64-bit in 10.5 on a compatible architecture.

It's only the built-in applications (Finder, Safari, frameworks, daemons etc.) also have the 64-bit version in 10.6.

假面具 2024-09-02 02:28:42

Meta:我不喜欢看到答案被删除。我想这已经在某处讨论过了。

不管怎样,KennyTM 和另一种鞋底让我开始了,虽然一个答案被删除了,但我很欣赏你的努力。

  1. 看起来这是 Mac 上的预期行为,甚至似乎也可以在 32 位 Linux 上运行(尽管我还没有进行广泛测试)

  2. 是的。对于 32 (-m32) 和 64 (-m64) 位模式,GCC 的行为有所不同(至少在我有限的观察中)。在 32 位中,我能够使用数组访问变量参数。在 64 位模式下,这不起作用。

我了解到您必须使用 stdarg.h 定义的 va_list 访问变量参数,因为它在两种模式下都有效。

现在我有一个命令行程序,可以在 Mac OS-X 上以 32 位和 64 位模式运行并通过所有测试用例。

该程序实现了一个链表垃圾收集器,从全局列表以及机器寄存器和堆栈中清除 16 字节对齐的 malloc 分配的对象 - 实际上,64 位模式下还有额外的寄存器,所以我还有一些工作要做做。

对象是 32 位或 64 位字的集合,它们链接在一起形成类似 LISP/Scheme 的数据结构。

总之,它是一个复杂的程序,对指针做了很多混乱,并且在 32 位和 64 位模式下工作相同。

  1. 提出多个问题并不能得到您可能想要的所有答案。

  2. 正如我所写,它似乎可以在 Linux 上运行。

再次感谢您在这件事上帮助我。

Meta: I don't like to see answers deleted. I guess this has been discussed somewhere.

Anyway, KennyTM and the other kind sole got me started and although one answer was deleted, I appreciated your efforts.

  1. It looks like this is expected behaviour on the Mac, and it even seems to work on a 32-bit Linux as well (although I have not tested extensively)

  2. Yep. GCC behaves different (at least in my limited observation) for 32 (-m32) and 64 (-m64) bit modes. In 32 bit, I was able to access variable arguments using an array. In 64 bit mode this just does not work.

I have learnt that you MUST access variable parameters using va_list as defined by stdarg.h because it works in both modes.

Now I have a command-line program that runs and passes all of my test cases in 32 bit and 64 bit modes on Mac OS-X.

The program implements a linked list garbage collector sweeping 16-byte aligned malloc-allocated objects from a global list as well as machine registers and the stack - actually, there are extra registers in 64 bit mode, so I still have a bit of work to do.

Objects are either a collection of 32 or 64 bit words which link together to form LISP/Scheme-like data structures.

In summary, it is a complex program that does a lot of messing with pointers and it works the same under 32 and 64 bit modes.

  1. Asking multiple questions does not get you all the answers you might want.

  2. It seems to work, as I wrote, on Linux.

Again, thank you for helping me with this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文