To what extent does the Itanium ABI really specify padding and alignment?

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:02:44

padding and alignment are unspecified by the ISO standard C++ specification and hence unreliable.

The use of the word "exact" in the quote is exaggeration. The Itanium ABI (which GCC uses) may specify these things (as within specifying ranges) as needed rather than always and exact ly.

Packing is in fact reliable and predictable within the use of toolchains assuming predetermined target architecture & environment- viz. ABI. When all target specific details applicable to the tool-chain are predetermined __attribute__ ((packed)) like any other construct will generate output predictably for the tool-chain to work correctly.

You need to follow the documentation to the standards incorporated by reference.

Most types' size and alignment is specified in the Intel System V ABI specifications; for example, long long and long double types' size and alignment are documented in the Unix System V Application Binary Interface, Itanium Processor Supplement (no. 245370-001), table 3-1 Additional Fundamental Data Types.

It's a little difficult to find authoritative copies of standards, especially as there isn't a real standards process. A good reference that includes the sizes and alignments of all types in the LP64 ABI is http://www.x86-64.org/documentation/abi.pdf although it doesn't cover the ILP32 ABI.

__attribute__((packed)) is of course gcc-specific, as is #pragma pack for MSVC. You may be able to use compiler compatibility features to get consistent layout of structs across compilers, but assuming that behavior is the same just because a compatibility feature is implemented is not a good idea; you should test that sizes and key offsets are the same.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!