Skip to content

Commit 169a417

Browse files
committed
Fix embedding of files with ld when compiling with position independent executable (PIE) is enabled
1 parent a821f6e commit 169a417

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

cmake/Embed.cmake

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,22 @@ function(generate_embed_source EMBED_NAME EMBED_DIR BASE_DIRECTORY)
105105
string(APPEND RC_FILE_MAPPING "IDR_${SYMBOL} TEXTFILE \"${NATIVE_FILE}\"\n")
106106
string(APPEND INIT_KERNELS "\n {\"${BASE_NAME}\", resource::read(IDR_${SYMBOL})},")
107107
math(EXPR RESOURCE_ID "${RESOURCE_ID} + 1" OUTPUT_FORMAT DECIMAL)
108-
else()
108+
elseif(EMBED_USE STREQUAL "LD")
109109
set(START_SYMBOL "_binary_${SYMBOL}_start")
110-
set(LENGTH_SYMBOL "_binary_${SYMBOL}_length")
111-
if(EMBED_USE STREQUAL "LD")
112-
string(APPEND EXTERNS "
110+
set(END_SYMBOL "_binary_${SYMBOL}_end")
111+
string(APPEND EXTERNS "
113112
extern const char ${START_SYMBOL}[];
114-
extern const size_t _binary_${SYMBOL}_size;
115-
const auto ${LENGTH_SYMBOL} = reinterpret_cast<size_t>(&_binary_${SYMBOL}_size);
113+
extern const char ${END_SYMBOL}[];
116114
")
117-
else()
118-
string(APPEND EXTERNS "
115+
string(APPEND INIT_KERNELS "
116+
{ \"${BASE_NAME}\", { ${START_SYMBOL}, static_cast<size_t>(${END_SYMBOL} - ${START_SYMBOL})} },")
117+
else() # CArrays
118+
set(START_SYMBOL "_binary_${SYMBOL}_start")
119+
set(LENGTH_SYMBOL "_binary_${SYMBOL}_length")
120+
string(APPEND EXTERNS "
119121
extern const char ${START_SYMBOL}[];
120122
extern const size_t ${LENGTH_SYMBOL};
121123
")
122-
endif()
123124
string(APPEND INIT_KERNELS "
124125
{ \"${BASE_NAME}\", { ${START_SYMBOL}, ${LENGTH_SYMBOL}} },")
125126
endif()

0 commit comments

Comments
 (0)