Skip to content

Commit 6b6a955

Browse files
committed
tools: update openssl x86 assembly ifdef workaround
Some sed lines were previously used to change from C-style #ifdef to nasm-style %ifdef in x86asm.pl for 32-bit Windows builds, but this creates problems when the C preprocessor is used before the assembler to build x86 assembly files. OpenSSL is using C preprocessor before nasm and uses #ifdef in this context. The perl line added to update-openssl.sh will work around the ifdef issue in a way that enables building for win32 and other x86. After update-openssl.sh script is run with "regenerate", x86asm.pl will end up with a modified "endbranch" subroutine that can use 2 types of ifdef (nasm-style %ifdef for win32 and gcc-style #ifdef for others). Then, after x86asm.pl is run during the node openssl build process, x86 assembly files may change their ifdef and endif lines depending on the system they are built for. Issues that lead to this commit: * openssl/openssl#18459 * nodejs#43603 (comment) * nodejs#44822
1 parent 77a0a0f commit 6b6a955

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

tools/dep_updaters/update-openssl.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,26 @@ regenerate() {
7070
echo "Regenerating platform-dependent files..."
7171

7272
make -C "$DEPS_DIR/openssl/config" clean
73-
# Needed for compatibility with nasm on 32-bit Windows
74-
# See https://github.com/nodejs/node/blob/main/doc/contributing/maintaining/maintaining-openssl.md#2-execute-make-in-depsopensslconfig-directory
75-
sed -i 's/#ifdef/%ifdef/g' "$DEPS_DIR/openssl/openssl/crypto/perlasm/x86asm.pl"
76-
sed -i 's/#endif/%endif/g' "$DEPS_DIR/openssl/openssl/crypto/perlasm/x86asm.pl"
73+
74+
# There is an issue with #ifdef and #endif in assembler files when doing win32 builds.
75+
# More information:
76+
# * https://github.com/openssl/openssl/issues/18459
77+
# * https://github.com/nodejs/node/pull/43603#issuecomment-1170670844
78+
# * https://github.com/nodejs/node/issues/44822
79+
80+
# Instead of replacing #ifdef and #endif with %ifdef and %endif, replace them with perl variables.
81+
# Including the brackets and double quotes enables this to be run even after the perl command that follows.
82+
sed -i 's/("#ifdef/("\$ifdef/g' "$DEPS_DIR/openssl/openssl/crypto/perlasm/x86asm.pl"
83+
sed -i 's/("#endif/("\$endif/g' "$DEPS_DIR/openssl/openssl/crypto/perlasm/x86asm.pl"
84+
85+
# The perl command needs to run after the sed commands. It initializes the ifdef and endif variables
86+
# and places and if statement to use %ifdef and %endif only when it is building assembler files for win32.
87+
perl -0777 -i -pe 's/sub ::endbranch\n\{/sub ::endbranch # modified by node update openssl script\n\{\n my \$ifdef = "#ifdef";\n my \$endif = "#endif";\n if (\$::win32) \{ \$ifdef="%ifdef"; \$endif="%endif"; \}\n/s' "$DEPS_DIR/openssl/openssl/crypto/perlasm/x86asm.pl"
88+
# -0777 is needed for multi-line input replacement (sed can't be used)
89+
90+
# It's also possible to replace the entire endbranch subroutine whether or not it was modified:
91+
# perl -0777 -i -pe 's/sub ::endbranch.*?\n\}/sub ::endbranch\n{\n# modified by node update openssl script\n if (\$::win32) { &::generic(\"%ifdef __CET__\\n\"); &::data_byte(0xf3,0x0f,0x1e,0xfb); &::generic(\"%endif\\n\"); }\n else { \&::generic(\"#ifdef __CET__\\n\"); \&::data_byte(0xf3,0x0f,0x1e,0xfb); \&::generic(\"#endif\\n\"); }\n}/s' "$DEPS_DIR/openssl/openssl/crypto/perlasm/x86asm.pl"
92+
7793
make -C "$BASE_DIR" gen-openssl
7894

7995
echo "All done!"

0 commit comments

Comments
 (0)