From c48c53c21f4658ecc9b29890118e5f0051e15716 Mon Sep 17 00:00:00 2001 From: James Park Date: Fri, 2 Sep 2022 21:37:22 -0700 Subject: [PATCH] vulkan: Augment _WIN32 stub comparison Make current check robust to incremental linking. Compare JMP targets if the first byte is opcode 0xE9. Reviewed-by: Jesse Natalie Part-of: --- src/vulkan/util/vk_dispatch_table_gen.py | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/vulkan/util/vk_dispatch_table_gen.py b/src/vulkan/util/vk_dispatch_table_gen.py index 08082ffbf72..80488a33fe9 100644 --- a/src/vulkan/util/vk_dispatch_table_gen.py +++ b/src/vulkan/util/vk_dispatch_table_gen.py @@ -463,6 +463,29 @@ VKAPI_ATTR void VKAPI_CALL vk_entrypoint_stub(void) { unreachable(!"Entrypoint not implemented"); } + +static const void *get_function_target(const void *func) +{ + const uint8_t *address = func; +#ifdef _M_X64 + /* Incremental linking may indirect through relative jump */ + if (*address == 0xE9) + { + /* Compute JMP target if the first byte is opcode 0xE9 */ + uint32_t offset; + memcpy(&offset, address + 1, 4); + address += offset + 5; + } +#else + /* Add other platforms here if necessary */ +#endif + return address; +} + +static bool vk_function_is_stub(PFN_vkVoidFunction func) +{ + return (func == vk_entrypoint_stub) || (get_function_target(func) == get_function_target(vk_entrypoint_stub)); +} #endif <%def name="dispatch_table_from_entrypoints(type)"> @@ -479,7 +502,7 @@ void vk_${type}_dispatch_table_from_entrypoints( for (unsigned i = 0; i < ARRAY_SIZE(${type}_compaction_table); i++) { #ifdef _MSC_VER assert(entry[i] != NULL); - if (entry[i] == vk_entrypoint_stub) + if (vk_function_is_stub(entry[i])) #else if (entry[i] == NULL) #endif @@ -493,7 +516,7 @@ void vk_${type}_dispatch_table_from_entrypoints( unsigned disp_index = ${type}_compaction_table[i]; #ifdef _MSC_VER assert(entry[i] != NULL); - if (disp[disp_index] == NULL && entry[i] != vk_entrypoint_stub) + if (disp[disp_index] == NULL && !vk_function_is_stub(entry[i])) #else if (disp[disp_index] == NULL) #endif