Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 7 additions & 82 deletions loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ endif()
set(NORMAL_LOADER_SRCS
allocation.c
allocation.h
asm_offsets.c
cJSON.c
cJSON.h
debug_utils.c
Expand Down Expand Up @@ -215,30 +216,12 @@ end
endif()

if(ASM_COMPILER_WORKS)
add_executable(asm_offset asm_offset.c)
target_link_libraries(asm_offset PRIVATE loader_specific_options)
# If am emulator is provided (Like Wine), or running on native, run asm_offset to generate gen_defines.asm
if (CMAKE_CROSSCOMPILING_EMULATOR OR NOT CMAKE_CROSSCOMPILING)
add_custom_command(OUTPUT gen_defines.asm DEPENDS asm_offset COMMAND asm_offset ${LOADER_ASM_DIALECT})
else()
# Forces compiler to write the intermediate asm file, needed so that we can get sizeof/offset of info out of it.
target_compile_options(asm_offset PRIVATE "/Fa$<TARGET_FILE_DIR:asm_offset>/asm_offset.asm" /FA)
# Force off optimization so that the output assembly includes all the necessary info - optimizer would get rid of it otherwise.
target_compile_options(asm_offset PRIVATE /Od)

find_package(Python3 REQUIRED QUIET)
# Run parse_asm_values.py on asm_offset's assembly file to generate the gen_defines.asm, which the asm code depends on
add_custom_command(TARGET asm_offset POST_BUILD
COMMAND Python3::Interpreter ${PROJECT_SOURCE_DIR}/scripts/parse_asm_values.py "${CMAKE_CURRENT_BINARY_DIR}/gen_defines.asm"
"$<TARGET_FILE_DIR:asm_offset>/asm_offset.asm" "${LOADER_ASM_DIALECT}" "${CMAKE_C_COMPILER_ID}" "${SYSTEM_PROCESSOR}"
BYPRODUCTS gen_defines.asm
)
endif()
add_custom_target(loader_asm_gen_files DEPENDS gen_defines.asm)
set_target_properties(loader_asm_gen_files PROPERTIES FOLDER ${LOADER_HELPER_FOLDER})

if(SYSTEM_PROCESSOR MATCHES "arm")
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_marmasm.asm)
if(SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_marmasm64.asm)
else()
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_marmasm32.asm)
endif()
else()
list(APPEND OPT_LOADER_SRCS unknown_ext_chain_masm.asm)
endif()
Expand Down Expand Up @@ -296,67 +279,14 @@ elseif(UNIX OR MINGW OR (WIN32 AND USE_GAS)) # i.e.: Linux & Apple & MinGW & Win
endif()
endif()

# When compiling for x86 on x64, we can't use CMAKE_SYSTEM_PROCESSOR to determine which architecture to use,
# Instead, check the size of void* and if its 4, set ASM_OFFSET_SYSTEM_PROCESSOR to x86 if we aren't on arm
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(ASM_OFFSET_SYSTEM_PROCESSOR ${SYSTEM_PROCESSOR}) # x86_64 or aarch64/arm64
string(REPLACE amd64 x86_64 ASM_OFFSET_SYSTEM_PROCESSOR "${ASM_OFFSET_SYSTEM_PROCESSOR}")
else()
if(${SYSTEM_PROCESSOR} MATCHES "86")
set(ASM_OFFSET_SYSTEM_PROCESSOR "x86")
else()
set(ASM_OFFSET_SYSTEM_PROCESSOR ${SYSTEM_PROCESSOR})
endif()
endif()

if(ASSEMBLER_WORKS)
add_executable(asm_offset asm_offset.c)
target_link_libraries(asm_offset loader_specific_options)
# If not cross compiling, run asm_offset to generate gen_defines.asm
if (NOT CMAKE_CROSSCOMPILING)
add_custom_command(OUTPUT gen_defines.asm DEPENDS asm_offset COMMAND asm_offset GAS)
else()
# Forces compiler to write the intermediate asm file, needed so that we can get sizeof/offset of info out of it.
# If with lto, compiler will output IR instead of asm, so we need to explicitly disable lto here.
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(asm_offset PRIVATE -save-temps=obj -fno-lto)
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(asm_offset PRIVATE -save-temps=obj -fno-lto -fno-whole-program-vtables -fno-virtual-function-elimination)
else()
target_compile_options(asm_offset PRIVATE -save-temps=obj)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(ASM_OFFSET_EXECUTABLE_LOCATION "$<TARGET_FILE_DIR:asm_offset>/gen_defines.asm")
set(ASM_OFFSET_INTERMEDIATE_LOCATION "$<TARGET_FILE_DIR:asm_offset>/CMakeFiles/asm_offset.dir/asm_offset.c.s")
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(ASM_OFFSET_EXECUTABLE_LOCATION "$<TARGET_FILE_DIR:asm_offset>/gen_defines.asm")
set(ASM_OFFSET_INTERMEDIATE_LOCATION "$<TARGET_FILE_DIR:asm_offset>/CMakeFiles/asm_offset.dir/asm_offset.s")
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
# Need to use the current binary dir since the asm_offset.s file is in that folder rather than the bundle
set(ASM_OFFSET_EXECUTABLE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/gen_defines.asm")
set(ASM_OFFSET_INTERMEDIATE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/asm_offset.dir/asm_offset.s")
else()
message(FATAL_ERROR "C_COMPILER_ID not supported!")
endif()
message(STATUS "CMAKE_CROSSCOMPILING FALSE")

find_package(Python3 REQUIRED QUIET)
# Run parse_asm_values.py on asm_offset's assembly file to generate the gen_defines.asm, which the asm code depends on
add_custom_command(TARGET asm_offset POST_BUILD
COMMAND Python3::Interpreter ${PROJECT_SOURCE_DIR}/scripts/parse_asm_values.py "${ASM_OFFSET_EXECUTABLE_LOCATION}"
"${ASM_OFFSET_INTERMEDIATE_LOCATION}" "GAS" "${CMAKE_C_COMPILER_ID}" "${ASM_OFFSET_SYSTEM_PROCESSOR}"
BYPRODUCTS gen_defines.asm
)
endif()
add_custom_target(loader_asm_gen_files DEPENDS gen_defines.asm)

if (APPLE)
set(MODIFY_UNKNOWN_FUNCTION_DECLS ON)
endif()
set(UNKNOWN_FUNCTIONS_SUPPORTED ON)
else()
if(USE_GAS)
message(WARNING "Could not find working ${ASM_OFFSET_SYSTEM_PROCESSOR} GAS assembler\n${ASM_FAILURE_MSG}")
message(WARNING "Could not find working ${SYSTEM_PROCESSOR} GAS assembler\n${ASM_FAILURE_MSG}")
else()
message(WARNING "Assembly sources have been disabled\n${ASM_FAILURE_MSG}")
endif()
Expand Down Expand Up @@ -455,10 +385,6 @@ else()
add_library(vulkan-framework SHARED)
target_sources(vulkan-framework PRIVATE ${NORMAL_LOADER_SRCS} ${FRAMEWORK_HEADERS})

if (UNKNOWN_FUNCTIONS_SUPPORTED)
add_dependencies(vulkan-framework loader_asm_gen_files)
endif()

target_link_libraries(vulkan-framework ${CMAKE_DL_LIBS} Threads::Threads -lm "-framework CoreFoundation")
target_link_libraries(vulkan-framework loader_specific_options)

Expand Down Expand Up @@ -514,7 +440,6 @@ add_library(Vulkan::Loader ALIAS vulkan)

if (UNKNOWN_FUNCTIONS_SUPPORTED)
target_compile_definitions(vulkan PRIVATE UNKNOWN_FUNCTIONS_SUPPORTED)
add_dependencies(vulkan loader_asm_gen_files)
endif()

if (BUILD_TESTS)
Expand Down
172 changes: 0 additions & 172 deletions loader/asm_offset.c

This file was deleted.

48 changes: 48 additions & 0 deletions loader/asm_offsets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2017-2024 The Khronos Group Inc.
* Copyright (c) 2017-2024 Valve Corporation
* Copyright (c) 2017-2024 LunarG, Inc.
* Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Charles Giessen <charles@lunarg.com>
*/

#include <stddef.h>
#include "loader_common.h"
#include "log.h"

#if VK_USE_64_BIT_PTR_DEFINES == 1
#define INT_TYPE uint64_t
#else
#define INT_TYPE uint32_t
#endif

// Apple's ABI is to prefix the symbol with an underscore. Because we are using the symbols in assembly, we don't want to have to
// worry about it. The fix is to use `foo __asm__("foo")` in order to change the symbol name as it appears to the linker.
#if defined(__APPLE__)
#define DEF(x) x __asm__(#x)
#else
#define DEF(x) x
#endif

const INT_TYPE DEF(VULKAN_LOADER_ERROR_BIT_VALUE) = VULKAN_LOADER_ERROR_BIT;
const INT_TYPE DEF(FUNCTION_OFFSET_INSTANCE) = offsetof(struct loader_instance, phys_dev_ext_disp_functions);
const INT_TYPE DEF(PHYS_DEV_OFFSET_INST_DISPATCH) = offsetof(struct loader_instance_dispatch_table, phys_dev_ext);
const INT_TYPE DEF(PHYS_DEV_OFFSET_PHYS_DEV_TRAMP) = offsetof(struct loader_physical_device_tramp, phys_dev);
const INT_TYPE DEF(ICD_TERM_OFFSET_PHYS_DEV_TERM) = offsetof(struct loader_physical_device_term, this_icd_term);
const INT_TYPE DEF(PHYS_DEV_OFFSET_PHYS_DEV_TERM) = offsetof(struct loader_physical_device_term, phys_dev);
const INT_TYPE DEF(INSTANCE_OFFSET_ICD_TERM) = offsetof(struct loader_icd_term, this_instance);
const INT_TYPE DEF(DISPATCH_OFFSET_ICD_TERM) = offsetof(struct loader_icd_term, phys_dev_ext);
const INT_TYPE DEF(EXT_OFFSET_DEVICE_DISPATCH) = offsetof(struct loader_dev_dispatch_table, ext_dispatch);
Loading