Skip to content

[native_toolchain_c] Explicitly tell linker to create position dependent or position independent executable #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 16, 2023
Merged
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
5 changes: 5 additions & 0 deletions pkgs/native_toolchain_c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.4+1

- Explicitly tell linker to create position dependent or position independent executable
([#113](https://github.com/dart-lang/native/issues/133)).

## 0.2.4

- Added `includes` for specifying include directories.
Expand Down
14 changes: 9 additions & 5 deletions pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ class RunCBuilder {
// which the static library is linked is PIC, PIE or neither. Then
// we could use the same option for the static library.
if (staticLibrary != null) '-fPIC',
if (executable != null) '-fPIE',
if (executable != null) ...[
// Generate position-independent code for executables.
'-fPIE',
// Tell the linker to generate a position-independent executable.
'-pie',
],
] else ...[
// Disable generation of any kind of position-independent code.
'-fno-PIC',
'-fno-PIE',
if (compiler.tool == clang) ...[
'-z',
'notext',
]
// Tell the linker to generate a position-dependent executable.
if (executable != null) '-no-pie',
],
if (std != null) '-std=$std',
if (language == Language.cpp) ...[
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_toolchain_c/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: native_toolchain_c
description: >-
A library to invoke the native C compiler installed on the host machine.
version: 0.2.4
version: 0.2.4+1
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c

topics:
Expand Down