diff --git a/pkg/dart2native/lib/dart2native_macho.dart b/pkg/dart2native/lib/dart2native_macho.dart index fe240c352cf..6cd0cbe15ca 100644 --- a/pkg/dart2native/lib/dart2native_macho.dart +++ b/pkg/dart2native/lib/dart2native_macho.dart @@ -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 diff --git a/pkg/dart2native/lib/macho.dart b/pkg/dart2native/lib/macho.dart index b408b8a4fca..765f86b67fc 100644 --- a/pkg/dart2native/lib/macho.dart +++ b/pkg/dart2native/lib/macho.dart @@ -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) { @@ -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); @@ -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; }