From b1dc0d62a0b7b2b62067696001726ecca3b30e13 Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Sat, 23 Jun 2018 14:36:31 +0300 Subject: [PATCH] Link binary resources rodata with GNU-stack note Improve the linking of binary resources so the content is in .rodata and the object contains a read-only flagged GNU-stack note. This causes GNU ld to not mark the stack executable in the final binary. Resolves #55 --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f2d59..98cdf76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,11 @@ macro(generate_compressed_bins BASEDIR) DEPENDS ${BASEDIR}/${FILE} ) add_custom_command(OUTPUT ${OUTPUT_FILE} - COMMAND ld -r -b binary -o ${OUTPUT_FILE} ${COMPRESSED_FILE} + COMMAND ${CMAKE_LINKER} -r -b binary -o ${OUTPUT_FILE} ${COMPRESSED_FILE} + COMMAND ${CMAKE_OBJCOPY} + --rename-section .data=.rodata.alloc,load,readonly,data,contents + --add-section .note.GNU-stack=/dev/null + --set-section-flags .note.GNU-stack=contents,readonly ${OUTPUT_FILE} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPRESSED_FILE} ) list(APPEND COMPRESSED_BINS ${OUTPUT_FILE})