From f7a201dad195a354e2603f2e3b5a26968260ee4c Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Fri, 15 Sep 2023 20:14:09 +0200 Subject: [PATCH 1/5] trigger ci --- pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 48645351f5..c213ff09a3 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -19,6 +19,7 @@ import 'package:test/test.dart'; import '../helpers.dart'; void main() { + // TODO: Fix test('Langauge.toString', () { expect(Language.c.toString(), 'c'); expect(Language.cpp.toString(), 'c++'); From c797facb0803c94c40c05a96fdde8e3d9ec71bba Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Fri, 15 Sep 2023 21:22:46 +0200 Subject: [PATCH 2/5] Pass `-no-pie` --- pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index 801504c58c..b5e137044b 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -168,6 +168,7 @@ class RunCBuilder { if (compiler.tool == clang) ...[ '-z', 'notext', + if (executable != null) '-no-pie', ] ], if (std != null) '-std=$std', From 229c9f32073f7889fcf62f28d965f26a552b6803 Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Fri, 15 Sep 2023 21:47:48 +0200 Subject: [PATCH 3/5] Explicitly specify to linker whether to create a position or position independent executable --- .../lib/src/cbuilder/run_cbuilder.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index b5e137044b..b5ccd6c169 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -161,15 +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', - if (executable != null) '-no-pie', - ] + // Tell the linker to generate a position-dependent executable. + if (executable != null) '-no-pie', ], if (std != null) '-std=$std', if (language == Language.cpp) ...[ From 16b6ea3783d5840eda8fe471cdd4ac5ffd488bd3 Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Fri, 15 Sep 2023 21:58:58 +0200 Subject: [PATCH 4/5] Update changelog --- pkgs/native_toolchain_c/CHANGELOG.md | 5 +++++ pkgs/native_toolchain_c/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/native_toolchain_c/CHANGELOG.md b/pkgs/native_toolchain_c/CHANGELOG.md index 4d2cf753f1..9eda8f0750 100644 --- a/pkgs/native_toolchain_c/CHANGELOG.md +++ b/pkgs/native_toolchain_c/CHANGELOG.md @@ -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. diff --git a/pkgs/native_toolchain_c/pubspec.yaml b/pkgs/native_toolchain_c/pubspec.yaml index 8195f08782..44f71e9d72 100644 --- a/pkgs/native_toolchain_c/pubspec.yaml +++ b/pkgs/native_toolchain_c/pubspec.yaml @@ -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: From 195fca778934cec1159e78ad4479da6df2841439 Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Fri, 15 Sep 2023 22:07:40 +0200 Subject: [PATCH 5/5] Cleanup --- pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index c213ff09a3..48645351f5 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -19,7 +19,6 @@ import 'package:test/test.dart'; import '../helpers.dart'; void main() { - // TODO: Fix test('Langauge.toString', () { expect(Language.c.toString(), 'c'); expect(Language.cpp.toString(), 'c++');