dart-sdk/tests/standalone/pie_test.dart
Ryan Macnak e31c3713bf Reland "[build, vm] Access TLS with less code."
- Avoid TLS initialization checks by using inline initialization.
 - Avoid global offset table indirection by reducing -fPIC to -fPIE.

out/ReleaseXARM64/exe.stripped/dart_precompiled_runtime
11137992 -> 11274776 (-1.21%)

We still need -fPIC in some places because we build a few shared libraries for FFI, so copy some of Fuchsia's GN setup to use -fPIE or -fPIC as appropriate.

Account for older gcc that does not default to -fpie.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/51602
Change-Id: I85072153cb1aef9047c1adbf36c7496fbeb11e10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286221
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-03-02 23:07:16 +00:00

29 lines
934 B
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:io";
// Mmmm... pie!
main() {
if (!Platform.isLinux) return; // readelf is a Linux tool.
// Modern Mac and Android binaries are always PIE.
// Fuchsia binaries are always PIE.
var result = Process.runSync("readelf", ["-h", Platform.resolvedExecutable]);
print("stdout:");
print(result.stdout);
print("stderr:");
print(result.stderr);
if (result.exitCode != 0) {
throw "readelf failed";
}
// A position-dependent executable outputs "EXEC (Executable file)".
if (!result.stdout.contains("DYN (Position-Independent Executable file)") &&
!result.stdout.contains("DYN (Shared object file)")) {
throw "Standalone VM should be a position-independent executable";
}
}