Skip to content

Commit

Permalink
Version 3.0.0-29.0.dev
Browse files Browse the repository at this point in the history
Merge bd81c8b into dev
  • Loading branch information
Dart CI committed Dec 15, 2022
2 parents 1dd5b1b + bd81c8b commit 13f4f97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
15 changes: 3 additions & 12 deletions pkg/dart2native/lib/dart2native_macho.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,14 @@ Future writeAppendedMachOExecutable(
// First, write the new headers.
outputHeaders.writeSync(output);
// If the newer headers are smaller, add appropriate padding to fit.
//
// TODO(49783): Once linker flags are in place in g3, this check should always
// succeed and should be removed.
if (outputHeaders.size <= aotRuntimeHeaders.size) {
addPadding(outputHeaders.size, aotRuntimeHeaders.size);
}
// TODO(49783): Once linker flags are in place in g3, this should always be
// aotRuntimeHeaders.size, but for now allow for the possibility of
// overwriting part of the original contents with the header as before.
final originalStart = max(aotRuntimeHeaders.size, outputHeaders.size);
addPadding(outputHeaders.size, aotRuntimeHeaders.size);

// Now write the original contents from the header to the __LINKEDIT segment
// contents.
final aotRuntimeStream = await aotRuntimeFile.open();
await aotRuntimeStream.setPosition(originalStart);
await aotRuntimeStream.setPosition(aotRuntimeHeaders.size);
await pipeStream(aotRuntimeStream, output,
numToWrite: oldLinkEdit.fileOffset - originalStart);
numToWrite: oldLinkEdit.fileOffset - aotRuntimeHeaders.size);

// Now insert the snapshot contents at this position in the file.
// There may be additional padding needed between the old __LINKEDIT file
Expand Down
21 changes: 10 additions & 11 deletions pkg/dart2native/lib/macho.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1527,8 +1527,9 @@ class MachOFile {
}

final reserved = reservedSegment;
// TODO(49783): Once linker flags are in place in g3, we should throw a
// FormatException if the segment used to reserve header space is not found.
if (reserved == null) {
throw FormatException("$reservedSegmentName segment not found");
}

final linkedit = linkEditSegment;
if (linkedit == null) {
Expand All @@ -1549,13 +1550,9 @@ class MachOFile {
header.cpu,
header.machine,
header.type,
// If the reserved section exists, we remove it and replace it with
// the note.
//
// TODO(49783): Once linker flags are in place in g3, reserved should
// never be null.
header.loadCommandsCount + (reserved == null ? 1 : 0),
header.loadCommandsSize - (reserved?.size ?? 0) + note.size,
// We remove the reserved section and replace it with the note.
header.loadCommandsCount,
header.loadCommandsSize - reserved.size + note.size,
header.flags,
header.reserved);

Expand All @@ -1582,8 +1579,10 @@ class MachOFile {

final newFile = MachOFile._(newHeader, newCommands, hasCodeSignature);

// TODO(49783): Once linker flags are in place in g3, we should throw a
// FormatException if [newFile.size] is greater than [size].
if (newFile.size > size) {
throw FormatException("Cannot add new note load command to header: "
"new size ${newFile.size} > the old size $size)");
}

return newFile;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 0
PATCH 0
PRERELEASE 28
PRERELEASE 29
PRERELEASE_PATCH 0

0 comments on commit 13f4f97

Please sign in to comment.