mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-23 14:00:47 +02:00
Works around static-pie crashing
static-pie is crashing early due to an issue with pthread symbols being exposed as weak. For some reason the weak symbols never get resolved and jump to zero or ELF base. When linking static-pie, force search for the pthread symbols using an undefined glob. With this, static-pie works as long as you link with a new enough version of lld (version 13.0)
This commit is contained in:
1 parent
2fd41de5e0
commit
310cfcbcc4
4 files changed
+16
-8
No files matched your search
@@ -56,12 +56,17 @@ if (ENABLE_XRAY)
|
||||
link_libraries(-fxray-instrument)
|
||||
endif()
|
||||
|
||||
set (PTHREAD_LIB pthread)
|
||||
if (ENABLE_LLD)
|
||||
set (LD_OVERRIDE "-fuse-ld=lld")
|
||||
link_libraries(${LD_OVERRIDE})
|
||||
endif()
|
||||
|
||||
if (ENABLE_STATIC_PIE)
|
||||
if (NOT ENABLE_LLD)
|
||||
message (FATAL_ERROR "static-pie requires linking with lld")
|
||||
endif()
|
||||
|
||||
file(WRITE ${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/Determine_iplt.c
|
||||
"int main(int argc, char* argv[])
|
||||
{
|
||||
@@ -121,6 +126,9 @@ if (ENABLE_STATIC_PIE)
|
||||
if (SYMBOLS_FINE)
|
||||
# We can now exnable static-pie
|
||||
set (STATIC_PIE_OPTIONS "-static-pie")
|
||||
# Pthreads has an issue with exposing symbols
|
||||
# We need to make some concessions to the pthread gods
|
||||
set (PTHREAD_LIB -Wl,--undefined-glob=pthread_* pthread)
|
||||
else()
|
||||
message (FATAL_ERROR "Application has __rela_iplt_{start,end} symbols. Which means static-pie can't be enabled")
|
||||
endif()
|
||||
|
||||
+2
-2
@@ -269,7 +269,7 @@ function(AddObject Name Type)
|
||||
add_dependencies(${Name} IR_INC)
|
||||
add_dependencies(${Name} CONFIG_INC)
|
||||
|
||||
target_link_libraries(${Name} pthread vixl dl fmt::fmt xxhash FEX_jemalloc)
|
||||
target_link_libraries(${Name} vixl dl fmt::fmt xxhash)
|
||||
set_target_properties(${Name} PROPERTIES OUTPUT_NAME FEXCore)
|
||||
set_target_properties(${Name} PROPERTIES C_VISIBILITY_PRESET hidden)
|
||||
set_target_properties(${Name} PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
@@ -310,7 +310,7 @@ endfunction()
|
||||
|
||||
function(AddLibrary Name Type)
|
||||
add_library(${Name} ${Type} $<TARGET_OBJECTS:${PROJECT_NAME}_object>)
|
||||
target_link_libraries(${Name} pthread vixl dl fmt::fmt xxhash FEX_jemalloc)
|
||||
target_link_libraries(${Name} vixl dl fmt::fmt xxhash)
|
||||
set_target_properties(${Name} PROPERTIES OUTPUT_NAME FEXCore)
|
||||
set_target_properties(${Name} PROPERTIES C_VISIBILITY_PRESET hidden)
|
||||
set_target_properties(${Name} PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
@@ -6,7 +6,7 @@ add_executable(FEXLoader FEXLoader.cpp)
|
||||
target_include_directories(FEXLoader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
target_include_directories(FEXLoader PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
|
||||
target_link_libraries(FEXLoader ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS})
|
||||
target_link_libraries(FEXLoader ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS} ${PTHREAD_LIB})
|
||||
|
||||
if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
|
||||
target_link_options(FEXLoader
|
||||
@@ -63,7 +63,7 @@ add_executable(FEXBash FEXBash.cpp)
|
||||
target_include_directories(FEXBash PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
target_include_directories(FEXBash PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
|
||||
target_link_libraries(FEXBash ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS})
|
||||
target_link_libraries(FEXBash ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS} ${PTHREAD_LIB})
|
||||
|
||||
if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
|
||||
target_link_options(FEXBash
|
||||
@@ -83,12 +83,12 @@ add_executable(TestHarnessRunner TestHarnessRunner.cpp)
|
||||
target_include_directories(TestHarnessRunner PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
target_include_directories(TestHarnessRunner PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
|
||||
target_link_libraries(TestHarnessRunner ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS})
|
||||
target_link_libraries(TestHarnessRunner ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS} ${PTHREAD_LIB})
|
||||
|
||||
add_executable(UnitTestGenerator UnitTestGenerator.cpp)
|
||||
target_include_directories(UnitTestGenerator PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
|
||||
target_link_libraries(UnitTestGenerator ${LIBS} ${STATIC_PIE_OPTIONS})
|
||||
target_link_libraries(UnitTestGenerator ${LIBS} ${STATIC_PIE_OPTIONS} ${PTHREAD_LIB})
|
||||
|
||||
add_executable(IRLoader
|
||||
IRLoader.cpp
|
||||
@@ -97,5 +97,5 @@ add_executable(IRLoader
|
||||
target_include_directories(IRLoader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/)
|
||||
target_include_directories(IRLoader PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
|
||||
target_link_libraries(IRLoader ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS})
|
||||
target_link_libraries(IRLoader ${LIBS} LinuxEmulation ${STATIC_PIE_OPTIONS} ${PTHREAD_LIB})
|
||||
|
||||
@@ -57,7 +57,7 @@ add_library(LinuxEmulation STATIC
|
||||
Syscalls/Stubs.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(LinuxEmulation FEXCore pthread FEX_Utils)
|
||||
target_link_libraries(LinuxEmulation FEXCore FEX_Utils)
|
||||
target_include_directories(LinuxEmulation PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
target_include_directories(LinuxEmulation PRIVATE ${PROJECT_SOURCE_DIR}/External/drm-headers/include/)
|
||||
|
||||
|
||||
Reference in new issue
Block a user