Commit 2a854a8ddf1 for nodejs

commit 2a854a8ddf1970ff72009f1d6a0b8bd9a32a1f3a
Author: Chengzhong Wu <legendecas@gmail.com>
Date:   Sun Nov 15 17:00:55 2026 -0500

    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>

diff --git a/common.gypi b/common.gypi
index 91efcb7cb87..3bec24c0620 100644
--- a/common.gypi
+++ b/common.gypi
@@ -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"', {
diff --git a/configure.py b/configure.py
index c6916b093cf..cecb6ae1b39 100755
--- a/configure.py
+++ b/configure.py
@@ -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: