Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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"', {
Expand Down
7 changes: 6 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,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:
Expand Down
Loading