Can a C compiler generate an executable 64-bits where pointers are 32-bits?

后端 未结 10 1156
陌清茗
陌清茗 2021-02-12 16:51

Most programs fits well on <4GB address space but needs to use new features just available on x64 architecture.

Are there compilers/platforms where I can use x64 regi

10条回答
  •  佛祖请我去吃肉
    2021-02-12 17:28

    It depends on the platform. On Mac OS X, the first 4 GB of a 64-bit process' address space is reserved and unmapped, presumably as a safety feature so no 32-bit value is ever mistaken for a pointer. If you try, there may be a way to defeat this. I worked around it once by writing a C++ "pointer" class which adds 0x100000000 to the stored value. (This was significantly faster than indexing into an array, which also requires finding the array-base address and multiplying before the addition.)

    On the ISA level, you can certainly choose to load and zero-extend a 32-bit value and then use it as a 64-bit pointer. It's a good feature for a platform to have.

    No change should be necessary to a program unless you wish to use 64-bit and 32-bit pointers simultaneously. In that case you are back to the bad old days of having near and far pointers.

    Also, you will certainly break ABI compatibility with APIs that take pointers to pointers.

提交回复
热议问题