2019-09-18 14:56:27 +00:00
|
|
|
// Copyright (c) 2019, 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.
|
|
|
|
|
2020-03-24 16:58:25 +00:00
|
|
|
#include "vm/bss_relocs.h"
|
2020-05-26 08:47:30 +00:00
|
|
|
#include "vm/native_symbol.h"
|
2020-03-24 16:58:25 +00:00
|
|
|
#include "vm/runtime_entry.h"
|
|
|
|
#include "vm/thread.h"
|
2019-09-18 14:56:27 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2020-05-26 08:47:30 +00:00
|
|
|
void BSS::InitializeBSSEntry(BSS::Relocation relocation,
|
|
|
|
uword new_value,
|
|
|
|
uword* bss_start) {
|
2020-05-04 16:17:14 +00:00
|
|
|
std::atomic<uword>* slot = reinterpret_cast<std::atomic<uword>*>(
|
|
|
|
&bss_start[BSS::RelocationIndex(relocation)]);
|
2020-03-24 16:58:25 +00:00
|
|
|
uword old_value = slot->load(std::memory_order_relaxed);
|
2020-06-09 13:23:56 +00:00
|
|
|
// FullSnapshotReader::ReadProgramSnapshot, and thus BSS::Initialize, can
|
|
|
|
// get called multiple times for the same isolate in different threads, though
|
|
|
|
// the initialized value will be consistent and thus change only once. Avoid
|
|
|
|
// calling compare_exchange_strong unless we actually need to change the
|
|
|
|
// value, to avoid spurious read/write races by TSAN.
|
|
|
|
if (old_value == new_value) return;
|
2020-03-24 16:58:25 +00:00
|
|
|
if (!slot->compare_exchange_strong(old_value, new_value,
|
|
|
|
std::memory_order_relaxed)) {
|
|
|
|
RELEASE_ASSERT(old_value == new_value);
|
|
|
|
}
|
2019-09-18 14:56:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 08:47:30 +00:00
|
|
|
void BSS::Initialize(Thread* current, uword* bss_start, bool vm) {
|
|
|
|
auto const instructions = reinterpret_cast<uword>(
|
|
|
|
current->isolate_group()->source()->snapshot_instructions);
|
|
|
|
uword dso_base;
|
[vm] Add build ID to non-symbolic stack traces.
Since we've run out of room for more fields in the Image object header
on 64-bit architectures, the serializer instead creates an ImageHeader
object for precompiled snapshots that is placed at the start of text
segments. The new ImageHeader object contains the following information:
* The offset of the BSS segment from the text segment, previously
stored in the Image object header.
* The relocated address of the text segment in the dynamic shared
object. Due to restrictions when generating assembly snapshots, this
field is only set for ELF snapshots, and so it can also be used to
detect whether a snapshot was compiled to assembly or ELF.
* The offset of the build ID description field from the text segment.
* The length of the build ID description field.
We replace the BSS offset in the Image object header with the offset of
the ImageHeader object within the text segment, so that we can detect
when a given Image has an ImageHeader object available.
There are no methods available on ImageHeader objects, but instead the
Image itself controls access to the information. In particular, the
relocated address method either returns the relocated address
information from the ImageHeader object or from the initialized BSS
depending on the type of snapshot, so the caller need not do this work.
Also, instead of returning the raw offset to the BSS section and having
the caller turn that into an appropriate pointer, the method for
accessing the BSS segment now returns a pointer to the segment.
Bug: https://github.com/dart-lang/sdk/issues/43274
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-precomp-android-release-arm_x64-try
Change-Id: I15eae4ad0a088260b127f3d07da79374215b7f56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163207
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2020-09-22 17:14:44 +00:00
|
|
|
// Needed for assembly snapshots. For ELF snapshots, we set up the relocated
|
[vm] Merge ImageHeader into InstructionsSection.
Before, we only wrapped the Instructions payloads in an
InstructionsSection in precompiled snapshots with bare instructions mode
enabled. This CL changes that to always add an InstructionsSection
wrapper in precompiled snapshots, even when not in bare instructions
mode, and moves all the information from the old ImageHeader object into
the InstructionsSection object instead. Note that in non-bare mode, the
InstructionsSection has no payload, and the Instructions objects follow
the InstructionsSection object instead of being contained by it.
This CL also wraps all implementations of AssemblyImageWriter and
SnapshotTextObjectNamer methods in a single DART_PRECOMPILER ifdef
block, since we only generate assembly in precompiled mode. This
removes the need for the smaller DART_PRECOMPILER ifdef blocks scattered
across the AssemblyImageWriter method implementations.
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-mac-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-release-x64-try
Change-Id: I3676fb5c6675845463707acbbb4759a465cfa342
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165563
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-10-06 17:10:05 +00:00
|
|
|
// address information directly in the text segment InstructionsSection.
|
2020-05-26 08:47:30 +00:00
|
|
|
if (NativeSymbolResolver::LookupSharedObject(instructions, &dso_base)) {
|
|
|
|
InitializeBSSEntry(Relocation::InstructionsRelocatedAddress,
|
|
|
|
instructions - dso_base, bss_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
// Fill values at isolate-only indices.
|
|
|
|
InitializeBSSEntry(Relocation::DRT_GetThreadForNativeCallback,
|
|
|
|
reinterpret_cast<uword>(DLRT_GetThreadForNativeCallback),
|
|
|
|
bss_start);
|
|
|
|
}
|
2020-05-04 16:17:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 14:56:27 +00:00
|
|
|
} // namespace dart
|