loader: add support for cross-compiling with LTO and ASM
authorAndarwinux <Andarwinux@users.noreply.github.com>
Thu, 21 Mar 2024 00:00:00 +0000 (00:00 +0000)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 22 Mar 2024 18:29:35 +0000 (13:29 -0500)
BUILD.md
loader/CMakeLists.txt

index 6915392204626a351825804df2872a9ea3e1f23f..9165b1cfb880a2b6d8e007939288ea4ca62456a3 100644 (file)
--- a/BUILD.md
+++ b/BUILD.md
@@ -637,11 +637,6 @@ can be manually disabled by setting `USE_GAS` or `USE_MASM` to `OFF`.
 Platforms not listed will use a fallback C Code path that relies on tail-call optimization to work.
 No guarantees are made about the use of the fallback code paths.
 
-### Link Time Optimization
-
-When cross compiling, the use of Link Time Optimization (LTO) and unknown function handling
-is not supported. Either LTO needs to be turned off, or the assembly should be disabled.
-
 ## Tests
 
 To build tests, make sure that the `BUILD_TESTS` option is set to true. Using
index fba0fabf6553cffc3be58ef6fa0f52ce7fa9da00..da4144b392bd7aa69c26a03fc1c199e66d5e8481 100644 (file)
@@ -264,7 +264,14 @@ elseif(UNIX OR MINGW) # i.e.: Linux & Apple & MinGW
             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.
-            target_compile_options(asm_offset PRIVATE -save-temps=obj)
+            # 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")