Skip to content

Commit 3822938

Browse files
authored
[native_toolchain_c] Explicitly tell linker to create position dependent or position independent executable (#139)
1 parent 88d8a22 commit 3822938

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pkgs/native_toolchain_c/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.4+1
2+
3+
- Explicitly tell linker to create position dependent or position independent executable
4+
([#113](https://github.com/dart-lang/native/issues/133)).
5+
16
## 0.2.4
27

38
- Added `includes` for specifying include directories.

pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,18 @@ class RunCBuilder {
161161
// which the static library is linked is PIC, PIE or neither. Then
162162
// we could use the same option for the static library.
163163
if (staticLibrary != null) '-fPIC',
164-
if (executable != null) '-fPIE',
164+
if (executable != null) ...[
165+
// Generate position-independent code for executables.
166+
'-fPIE',
167+
// Tell the linker to generate a position-independent executable.
168+
'-pie',
169+
],
165170
] else ...[
171+
// Disable generation of any kind of position-independent code.
166172
'-fno-PIC',
167173
'-fno-PIE',
168-
if (compiler.tool == clang) ...[
169-
'-z',
170-
'notext',
171-
]
174+
// Tell the linker to generate a position-dependent executable.
175+
if (executable != null) '-no-pie',
172176
],
173177
if (std != null) '-std=$std',
174178
if (language == Language.cpp) ...[

pkgs/native_toolchain_c/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: native_toolchain_c
22
description: >-
33
A library to invoke the native C compiler installed on the host machine.
4-
version: 0.2.4
4+
version: 0.2.4+1
55
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c
66

77
topics:

0 commit comments

Comments
 (0)