Skip to content

Commit 0305226

Browse files
committed
CMakeLists.txt: only pass -z relro,-z now to ELF linkers
8716c87 added -Wl,-z,relro,-z,now unconditionally, but macOS ld64 does not support -z ("ld: unknown options: -z -z"), breaking the link on macOS. Gate the flag on NOT APPLE; RELRO/BIND_NOW are ELF hardening concepts with no Mach-O equivalent, and macOS builds PIE by default.
1 parent 39fbc34 commit 0305226

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ string(APPEND CMAKE_C_FLAGS " -fstack-protector-strong -D_FORTIFY_SOURCE=3 -fPIE
3535
set(CMAKE_C_FLAGS_DEBUG "-gdwarf-4 -DDEBUG")
3636
set(CMAKE_C_FLAGS_RELEASE "-O2")
3737

38-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -Wl,-z,relro,-z,now")
38+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE")
39+
if (NOT APPLE) # ld64 doesn't support -z; PIE binaries are the macOS default anyway
40+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now")
41+
endif()
3942

4043
if (CMAKE_C_COMPILER_ID MATCHES GNU)
4144
string(APPEND CMAKE_C_FLAGS " -Warray-bounds=2 -Wduplicated-cond -Wduplicated-branches -Wrestrict")

0 commit comments

Comments
 (0)