dart-sdk/runtime/vm/bss_relocs.cc

50 lines
2 KiB
C++
Raw Normal View History

// 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.
#include "vm/bss_relocs.h"
#include "vm/native_symbol.h"
#include "vm/runtime_entry.h"
#include "vm/thread.h"
namespace dart {
void BSS::InitializeBSSEntry(BSS::Relocation relocation,
uword new_value,
uword* bss_start) {
std::atomic<uword>* slot = reinterpret_cast<std::atomic<uword>*>(
&bss_start[BSS::RelocationIndex(relocation)]);
uword old_value = slot->load(std::memory_order_relaxed);
// 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;
if (!slot->compare_exchange_strong(old_value, new_value,
std::memory_order_relaxed)) {
RELEASE_ASSERT(old_value == new_value);
}
}
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
// address information directly in the text segment InstructionsSection.
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);
}
}
} // namespace dart