GeezerVison is showing github.com — build: enable pie on linux · nodejs/node@4f282b8
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: common.gypi +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
686 | 686 | 'cflags': [ '-fPIC' ], |
687 | 687 | 'ldflags': [ '-fPIC' ], |
688 | 688 | }], |
| 689 | + # Link executables as PIE so that ASLR randomizes the executable |
| 690 | + # image too. Every object in a PIE must be built with `-fPIC` or |
| 691 | + # `-fPIE`. PIE flags should not apply to shared library objects, |
| 692 | + # like addons. `--fully-static` uses `-static-pie`, see configure.py. |
| 693 | + [ 'OS=="linux" and configuring_node', { |
| 694 | + 'target_conditions': [ |
| 695 | + ['_type=="executable"', { |
| 696 | + 'ldflags': [ '-pie' ], |
| 697 | + }], |
| 698 | + ], |
| 699 | + 'conditions': [ |
| 700 | + # Use `-fPIE` unless the condition above uses `-fPIC`. |
| 701 | + [ 'node_shared!="true" and node_enable_v8debughelper!="true"', { |
| 702 | + 'cflags': [ '-fPIE' ], |
| 703 | + }], |
| 704 | + ], |
| 705 | + }], |
689 | 706 | ], |
690 | 707 | }], |
691 | 708 | [ 'OS in "aix os400"', { |
|
Collapse file
Copy file name to clipboardExpand all lines: configure.py +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2546,7 +2546,12 @@ def configure_static(o): |
2546 | 2546 | return |
2547 | 2547 |
|
2548 | 2548 | if options.fully_static: |
2549 | | - o['libraries'] += ['-static'] |
| 2549 | + if flavor == 'linux': |
| 2550 | + # `-static` drops the `-pie` from common.gypi, e.g. clang: |
| 2551 | + # https://github.com/llvm/llvm-project/blob/68b03cf380e61c86aa59f94a10e8ce2d4c10cbb0/clang/lib/Driver/ToolChains/Gnu.cpp#L351-L366 |
| 2552 | + o['libraries'] += ['-static-pie'] |
| 2553 | + else: |
| 2554 | + o['libraries'] += ['-static'] |
2550 | 2555 | elif options.partly_static: |
2551 | 2556 | o['libraries'] += ['-static-libgcc', '-static-libstdc++'] |
2552 | 2557 | if options.enable_asan: |
|