Skip to content

Commit 94de8e2

Browse files
Avoid overriding _FORTIFY_SOURCE if already set (#455)
* CI: Add regression test for _FORTIFY_SOURCE build flag * Avoid overriding _FORTIFY_SOURCE if already set If the environment defines flags other than `_FORTIFY_SOURCE=2` (e.g. on Arch Linux, which sets it to 3), compilation fails because the flag cannot be re-defined. ``` make: Entering directory '/tmp/node-argon2/build' CC(target) Release/obj.target/libargon2/argon2/src/opt.o <command-line>: warning: "_FORTIFY_SOURCE" redefined <command-line>: note: this is the location of the previous definition CC(target) Release/obj.target/libargon2/argon2/src/argon2.o <command-line>: warning: "_FORTIFY_SOURCE" redefined <command-line>: note: this is the location of the previous definition CC(target) Release/obj.target/libargon2/argon2/src/blake2/blake2b.o <command-line>: warning: "_FORTIFY_SOURCE" redefined <command-line>: note: this is the location of the previous definition CC(target) Release/obj.target/libargon2/argon2/src/core.o <command-line>: warning: "_FORTIFY_SOURCE" redefined <command-line>: note: this is the location of the previous definition CC(target) Release/obj.target/libargon2/argon2/src/encoding.o <command-line>: warning: "_FORTIFY_SOURCE" redefined <command-line>: note: this is the location of the previous definition CC(target) Release/obj.target/libargon2/argon2/src/thread.o <command-line>: warning: "_FORTIFY_SOURCE" redefined <command-line>: note: this is the location of the previous definition rm -f Release/obj.target/argon2.a Release/obj.target/argon2.a.ar-file-list; mkdir -p `dirname Release/obj.target/argon2.a` ar crs Release/obj.target/argon2.a @Release/obj.target/argon2.a.ar-file-list COPY Release/argon2.a CXX(target) Release/obj.target/argon2/argon2.o <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror] <command-line>: note: this is the location of the previous definition cc1plus: all warnings being treated as errors make: *** [argon2.target.mk:138: Release/obj.target/argon2/argon2.o] Error 1 make: Leaving directory '/tmp/node-argon2/build' ``` By only setting it conditionally, we can avoid this issue.
1 parent 638f20f commit 94de8e2

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

.github/workflows/ci.yml

+23
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,26 @@ jobs:
133133
npm ci
134134
npm test
135135
sync: sshfs
136+
137+
build-with-fortify-source:
138+
strategy:
139+
matrix:
140+
cppflags: ['', '-D _FORTIFY_SOURCE=2', '-D _FORTIFY_SOURCE=3', '-D_FORTIFY_SOURCE=2', '-D_FORTIFY_SOURCE=3']
141+
142+
name: Test that setting _FORTIFY_SOURCE will not break the build
143+
runs-on: ubuntu-latest
144+
145+
steps:
146+
- name: Checkout
147+
uses: actions/checkout@v4
148+
with:
149+
submodules: true
150+
151+
- name: Use Node.js 22
152+
uses: actions/setup-node@v4
153+
with:
154+
cache: npm
155+
node-version: 22
156+
157+
- name: Install
158+
run: CPPFLAGS="${{ matrix.cppflags }}" npm ci

binding.gyp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"variables": {
3+
"fortify_source_defined": "<!(node -p \"/-D\\s*_FORTIFY_SOURCE=/.test((process.env.CFLAGS || '') + (process.env.CPPFLAGS || '') + (process.env.CXXFLAGS || ''))\")",
4+
},
25
"target_defaults": {
36
"include_dirs": ["argon2/include"],
47
"target_conditions": [
@@ -19,9 +22,11 @@
1922
"configurations": {
2023
"Release": {
2124
"target_conditions": [
25+
# Define _FORTIFY_SOURCE on non-Darwin, but avoid overriding it if already set
2226
["OS not in 'ios mac'", {
23-
# Avoid defining _FORTIFY_SOURCE on Darwin
24-
"defines+": ["_FORTIFY_SOURCE=2"]
27+
"conditions": [
28+
["fortify_source_defined=='false'", {"defines+": ["_FORTIFY_SOURCE=2"]}]
29+
]
2530
}],
2631
["OS not in 'win ios mac aix'", {
2732
# On Darwin with Xcode CLT/LLVM, "-fvisibility=hidden" hide all symbols that

0 commit comments

Comments
 (0)