dart-sdk/runtime/platform
Tess Strickland b0c4ddf919 [pkg/dart2native] Avoid overwriting section contents in MachO files.
To create a Dart standalone executable on MacOS, we modify the
dartaotruntime executable to add the snapshot contents, and the
VM looks into the executable on disk to find the snapshot to load.

Previously, we did this by adding a new 64-bit segment load command
with a single section, where the section's file offset and size
describes the inserted snapshot. This meant the Mach-O header size increased by 152 bytes.

Originally, this wasn't an issue as there was plenty of padding, but
later clang updates removed most of this padding, and so writing the
new header actually overwrote the initial contents of the first section
in the file, which happens to be the __text section. In addition, since
the first section's offset was now declared to be within the header,
utilities that strictly validated the Mach-O format, like codesign,
would report errors.

This CL changes it so that we actually reserve space in the
dartaotruntime header using the -add_empty_section flag to the linker.
In addition, we change from using a segment load command to using a
(40 byte) note load command. This is because a segment load command
specifies that the contents should be loaded in memory, but we don't
use that loaded version. Instead, the VM reloads it from the executable
on disk so it can appropriately mmap the different parts of the
snapshot. A note section instead just declares a section of the
executable as arbitrary data that the owner can read from the file
and use as desired, which is semantically closer to our current usage.

This CL also adds a test to pkg/dartdev/test/commands/compile_test to
ensure that corrupting a random part of the snapshot in the executable
causes signature verification to fail.

This CL also reverts CL 256208, thus relanding the clang changes
starting from June that originally raised awareness of the issue by
greatly reduced the amount of padding after the load commands.

TEST=pkg/dartdev/test/commands/compile_test

Bug: https://github.com/dart-lang/sdk/issues/49783
Change-Id: Iee554d87b0eabaecd7a534ca4e4facfefbce6385
Cq-Include-Trybots: luci.dart.try:analyzer-mac-release-try,dart-sdk-mac-arm64-try,dart-sdk-mac-try,pkg-mac-release-arm64-try,pkg-mac-release-try,vm-kernel-precomp-mac-product-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260108
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2022-09-29 08:32:47 +00:00
..
address_sanitizer.h [vm] Fix LSAN when used without ASAN. 2020-05-12 17:38:19 +00:00
allocation.cc [vm] Clean up ClassTable 2022-09-10 15:12:35 +00:00
allocation.h [vm] Clean up ClassTable 2022-09-10 15:12:35 +00:00
assert.cc [vm/compiler] Reduce number of subtype comparisons in AOT. 2021-08-19 18:32:01 +00:00
assert.h [gardening] Fix MSAN failure in assert.h. 2021-12-15 13:49:56 +00:00
atomic.h [ VM / Service ] Allow for CpuSamples to be streamed when samples are about to be overwritten. 2021-07-16 20:50:58 +00:00
BUILD.gn [fuchsia] allow injecting the inspect node 2021-03-22 17:38:24 +00:00
elf.h [vm] Mark ELF libraries produced directly by the VM as not requiring an executable stack. 2022-04-19 18:51:47 +00:00
floating_point.h [gardening] Fix import to fix Flutter build 2019-09-06 09:08:49 +00:00
floating_point_win.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
floating_point_win.h
globals.h [vm] Remove dynamic field unboxing in JIT 2022-09-20 13:42:45 +00:00
growable_array.h [vm/concurrency] Implement a fast transitive object copy for isolate message passing 2021-07-13 19:04:20 +00:00
hashmap.cc [vm] Produce clearer error messages when operator new fails. 2020-11-13 19:07:20 +00:00
hashmap.h [vm] Experimental ability to spawn isolate from kernel blob in memory 2022-02-23 16:55:52 +00:00
leak_sanitizer.h [vm] Fix LSAN when used without ASAN. 2020-05-12 17:38:19 +00:00
mach_o.h [pkg/dart2native] Avoid overwriting section contents in MachO files. 2022-09-29 08:32:47 +00:00
memory_sanitizer.h [vm, compiler] Inform MSan about parameters coming from FFI. 2022-09-23 21:31:14 +00:00
pe.h [dart2native] Allow for signing of Windows standalone executables. 2022-03-24 10:08:01 +00:00
platform_sources.gni [vm] Produce clearer error messages for malloc/realloc failures. 2020-11-13 22:10:54 +00:00
priority_queue.h [vm] Make event handler use appropriate data structure for timers 2020-12-16 10:55:12 +00:00
safe_stack.h [vm] Fix various UBSan failures. 2020-05-07 19:40:18 +00:00
signal_blocker.h [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
splay-tree-inl.h
splay-tree.h
syslog.h
syslog_android.cc [standalone] Fix reuse of va_list in syslog_android.cc. 2021-12-15 22:22:36 +00:00
syslog_fuchsia.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
syslog_linux.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
syslog_macos.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
syslog_win.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
text_buffer.cc [vm] Add buffering of --trace_precompiler_to output in memory 2020-12-11 18:19:39 +00:00
text_buffer.h [vm] Add buffering of --trace_precompiler_to output in memory 2020-12-11 18:19:39 +00:00
thread_sanitizer.h Reland "[vm] When run under TSAN use longjmp() to skip over C++ frames before manually unwinding to the catch entry" 2021-12-08 20:41:18 +00:00
unaligned.h [vm] Fix various UBSan failures. 2020-05-07 19:40:18 +00:00
undefined_behavior_sanitizer.h [vm] Fix various UBSan failures. 2020-05-07 19:40:18 +00:00
unicode.cc
unicode.h [vm] Adjust internal UTF-8 encoder to match dart:convert. 2020-06-29 16:10:13 +00:00
utils.cc [vm] Fix kNumberOfReservedCpuRegisters on ARM64 2022-08-10 18:04:09 +00:00
utils.h [vm] Fix kNumberOfReservedCpuRegisters on ARM64 2022-08-10 18:04:09 +00:00
utils_android.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
utils_android.h [vm/compiler] bit utilities 2019-10-07 18:13:06 +00:00
utils_fuchsia.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
utils_fuchsia.h [fuchsia] allow injecting the inspect node 2021-03-22 17:38:24 +00:00
utils_linux.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
utils_linux.h [vm/compiler] bit utilities 2019-10-07 18:13:06 +00:00
utils_macos.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
utils_macos.h [vm/compiler] bit utilities 2019-10-07 18:13:06 +00:00
utils_win.cc [vm] Reland: Prefix HOST_OS_* and TARGET_OS_* with DART_ 2021-07-02 19:06:45 +00:00
utils_win.h [vm/compiler] bit utilities 2019-10-07 18:13:06 +00:00