Files
sdk/runtime/vm/datastream.cc
Tess Strickland bc021bbc01 [vm] Output accompaning relocatable object for Mach-O snapshots.
In order to appropriately generate .dSYMs for a snapshot and allow
the strip tool to be used on the snapshot afterwards, add a mode that
not only outputs the snapshot (sans DWARF information) but also
an associated relocatable object file that contains the program's DWARF
information. That allows dsymutil to retrieve the DWARF information
from the relocatable object when run on the snapshot prior to stripping.

To specify that the relocatable object file should be output, use
the new --macho-object command line argument to gen_snapshot
to specify where the object file should be written.

This CL also adds an additional command line argument,
--macho-reduce-padding, which reduces the alignment used for segments
and the text/const sections in Mach-O outputs from 16KB to 64 bytes.
The larger padding is needed for some uses, like non-native loading
of Mach-O objects, but can be elided for other uses like Flutter builds.

TEST=vm/dart/use_dwarf_stack_traces_flag_test
     vm/dart/use_macho_reduce_padding_flag_test

Change-Id: I2bf4bacb70c41299b8b6fdb7635c2374acf7a07d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457420
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-11-19 07:45:52 -08:00

65 lines
2.0 KiB
C++

// Copyright (c) 2018, 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/datastream.h"
#include "vm/compiler/runtime_api.h"
#include "vm/zone.h"
namespace dart {
void BaseWriteStream::WriteTargetWord(word value) {
ASSERT(Utils::BitLength(value) <= compiler::target::kBitsPerWord);
WriteFixed(static_cast<compiler::target::word>(value));
}
MallocWriteStream::~MallocWriteStream() {
free(buffer_);
}
void MallocWriteStream::Realloc(intptr_t new_size) {
const intptr_t old_offset = current_ - buffer_;
buffer_ = reinterpret_cast<uint8_t*>(realloc(buffer_, new_size));
capacity_ = buffer_ != nullptr ? new_size : 0;
current_ = buffer_ != nullptr ? buffer_ + old_offset : nullptr;
}
void ZoneWriteStream::Realloc(intptr_t new_size) {
const intptr_t old_offset = current_ - buffer_;
buffer_ = zone_->Realloc(buffer_, capacity_, new_size);
capacity_ = buffer_ != nullptr ? new_size : 0;
current_ = buffer_ != nullptr ? buffer_ + old_offset : nullptr;
}
StreamingWriteStream::~StreamingWriteStream() {
// Allow a StreamingWriteStream to be created for nullptr callback
// data as long as no data is ever written.
ASSERT(callback_data_ != nullptr || Position() == 0);
if (BaseWriteStream::Position() != 0) {
Flush();
}
free(buffer_);
}
void StreamingWriteStream::Realloc(intptr_t new_size) {
Flush();
// Check whether resetting the internal buffer by flushing gave enough space.
if (new_size <= capacity_) {
return;
}
const intptr_t new_capacity = Utils::RoundUp(new_size, 64 * KB);
buffer_ = reinterpret_cast<uint8_t*>(realloc(buffer_, new_capacity));
capacity_ = buffer_ != nullptr ? new_capacity : 0;
current_ = buffer_; // Flushing reset the internal buffer offset to 0.
}
void StreamingWriteStream::Flush() {
intptr_t size = current_ - buffer_;
callback_(callback_data_, buffer_, size);
flushed_size_ += size;
current_ = buffer_;
}
} // namespace dart