Files
sdk/runtime/vm/mach_o.h
T
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

77 lines
2.2 KiB
C++

// Copyright (c) 2025, 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.
#ifndef RUNTIME_VM_MACH_O_H_
#define RUNTIME_VM_MACH_O_H_
#include "platform/globals.h"
#if defined(DART_PRECOMPILER)
#include "vm/allocation.h"
#include "vm/compiler/runtime_api.h"
#include "vm/datastream.h"
#include "vm/growable_array.h"
#include "vm/so_writer.h"
#include "vm/zone.h"
namespace dart {
class MachOHeader;
class MachOSymbolTable;
class MachOWriteStream;
class MachOWriter : public SharedObjectWriter {
public:
MachOWriter(Zone* zone,
BaseWriteStream* stream,
Type type,
const char* id,
const char* path = nullptr,
Dwarf* dwarf = nullptr,
MachOWriter* object = nullptr);
#if defined(TARGET_ARCH_ARM64)
static constexpr intptr_t kPageSize = 16 * KB;
#else
static constexpr intptr_t kPageSize = 4 * KB;
#endif
intptr_t page_size() const override { return kPageSize; }
Output output() const override { return Output::MachO; }
const MachOHeader& header() const { return header_; }
void AddText(const char* name,
intptr_t label,
const uint8_t* bytes,
intptr_t size,
const ZoneGrowableArray<Relocation>* relocations,
const ZoneGrowableArray<SymbolData>* symbol) override;
void AddROData(const char* name,
intptr_t label,
const uint8_t* bytes,
intptr_t size,
const ZoneGrowableArray<Relocation>* relocations,
const ZoneGrowableArray<SymbolData>* symbols) override;
void Finalize() override;
void AssertConsistency(const SharedObjectWriter* debug) const override;
const MachOWriter* AsMachOWriter() const override { return this; }
private:
static void AssertConsistency(const MachOWriter* snapshot,
const MachOWriter* debug_info);
MachOWriter* const object_writer_;
MachOHeader& header_;
};
} // namespace dart
#endif // DART_PRECOMPILER
#endif // RUNTIME_VM_MACH_O_H_