gpt4 book ai didi

c++ - Itanium 和 MSVC ABI 中跨模块边界的 RTTI

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:18:35 25 4
gpt4 key购买 nike

我正在阅读 Itanium ABI上面写着

It is intended that two type_info pointers point to equivalent type descriptions if and only if the pointers are equal. An implementation must satisfy this constraint, e.g. by using symbol preemption, COMDAT sections, or other mechanisms.

有谁知道在使用动态加载库时如何在流行平台(例如使用 GCC 和 GNU binutils 的 Linux)上实际实现这一点的详细信息?它有多可靠?

此外,我的印象是 MSVC 中的 typeid 比较是(曾经?)使用运行时字符串比较对损坏的符号名称实现的,正是因为不能保证满足此要求。这仍然是它完成的方式吗?是否有技术平台限制阻止 MSVC 使用与 Itanium ABI 平台相同的技术?

编辑 还有一个问题:跨模块边界的异常捕获(在任一 ABI 中)是否也依赖于 RTTI 信息,或者除了等效的运行时 dynamic_cast< 之外是否还涉及另一种机制s?

最佳答案

MSVC 首先使用指针比较,如果失败,则比较字符串。你可以在VS2012的CRT源中看到实现:

extern "C" _CRTIMP int __cdecl __TypeMatch(
HandlerType *pCatch, // Type of the 'catch' clause
CatchableType *pCatchable, // Type conversion under consideration
ThrowInfo *pThrow // General information about the thrown
// type.
) {
// First, check for match with ellipsis:
if (HT_IS_TYPE_ELLIPSIS(*pCatch)) {
return TRUE;
}

// Not ellipsis; the basic types match if it's the same record *or* the
// names are identical.
if (HT_PTD(*pCatch) != CT_PTD(*pCatchable)
&& strcmp(HT_NAME(*pCatch), CT_NAME(*pCatchable)) != 0) {
return FALSE;
}
...

Itanium ABI 总是只使用指针比较。它应该与 DLL 一起工作的方式是动态加载器应该确保程序地址空间中的每个异常都有一个 typeinfo 对象的单个实例。

如果您对异常 RTTI 的实际实现和捕获信息感兴趣,请查看我的 OpenRCE article (MSVC) 和 Recon 2012 presentation (海湾合作委员会,MSVC x64)。

关于c++ - Itanium 和 MSVC ABI 中跨模块边界的 RTTI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15211667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com