build: enable pie on linux

Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67386
Refs: https://github.com/nodejs/node/issues/66951
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
This commit is contained in:
Chengzhong Wu authored and Antoine du Hamel committed 2026-11-16 10:14:33 +01:00
1 parent e0c71bcd1c
commit a5672e8023
2 files changed
+23 -1

No files matched your search

+17
View File
@@ -699,6 +699,23 @@
'cflags': [ '-fPIC' ],
'ldflags': [ '-fPIC' ],
}],
# Link executables as PIE so that ASLR randomizes the executable
# image too. Every object in a PIE must be built with `-fPIC` or
# `-fPIE`. PIE flags should not apply to shared library objects,
# like addons. `--fully-static` uses `-static-pie`, see configure.py.
[ 'OS=="linux" and configuring_node', {
'target_conditions': [
['_type=="executable"', {
'ldflags': [ '-pie' ],
}],
],
'conditions': [
# Use `-fPIE` unless the condition above uses `-fPIC`.
[ 'node_shared!="true" and node_enable_v8debughelper!="true"', {
'cflags': [ '-fPIE' ],
}],
],
}],
],
}],
[ 'OS in "aix os400"', {
+6 -1
View File
@@ -2538,7 +2538,12 @@ def configure_static(o):
return
if options.fully_static:
o['libraries'] += ['-static']
if flavor == 'linux':
# `-static` drops the `-pie` from common.gypi, e.g. clang:
# https://github.com/llvm/llvm-project/blob/68b03cf380e61c86aa59f94a10e8ce2d4c10cbb0/clang/lib/Driver/ToolChains/Gnu.cpp#L351-L366
o['libraries'] += ['-static-pie']
else:
o['libraries'] += ['-static']
elif options.partly_static:
o['libraries'] += ['-static-libgcc', '-static-libstdc++']
if options.enable_asan: