设置标志__randomize_layout时,Marco Offsetof如何工作?

发布于 2025-01-30 19:30:01 字数 353 浏览 3 评论 0原文

当我研究内核源代码时,这是一个疑问。 我知道,如果定义了compiler_offsetof,Marco将调用__ compiler_offsetof ,否则将运行((size_t)&((类型 *)0) - > member)。 但是,当我启用_randomize_layout标记到一个结构时,编译器会将其在结构内部供电。那么,在这种情况下,Marco如何工作? 我的理解之一是,如果定义了compiler_offsetof,编译器将在内部解决它。但是我不知道compiler_offsetof未定义。

This is a doubt when I studying kernel source codes.
I know that if a compiler_offsetof is defined, the marco will call __compiler_offsetof, otherwise it will run ((size_t)&((TYPE *)0)->MEMBER).
But when I enable _randomize_layout flag to a struct, the compiler will shuffle the items inside the struct. So how does the marco work in this condition?
One of my understanding is that compiler will solve it internally if compiler_offsetof was defined. But I have no idea when compiler_offsetof is not defined.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文