From 84404136e9230eb948bcf7a90d047b0bfc2fd612 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 13 Nov 2023 14:25:28 +0000 Subject: [PATCH] [vm] Fix some cross compilation issues from Linux to Windows Upstreamed changes from cl/579854752. The cross-compiler checks some things that are check on Windows. * Correct capitalization of filenames in includes. * Field initialization order in constructors. In the cross compilation process, some binaries are run on the host. This unveiled missing `UnwindingRecords::GenerateRecordsInto`. Finally, when emitting blob data with a symbol in assembly, the `.type` directive is not supported but the format should still be unix style assemble. So this CL introduces "win_gnu". This tool is directly invoked from the build-rules in cl/579854752, and will not be used until we address https://github.com/dart-lang/sdk/issues/28617. TEST=windows bots Change-Id: I94256589e8c231b45b8e14a63727c782416c2e98 Cq-Include-Trybots: luci.dart.try:vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,pkg-win-release-try,pkg-win-release-arm64-try,vm-win-debug-arm64-try,vm-win-debug-x64c-try,vm-win-debug-x64-try,vm-msvc-windows-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335520 Commit-Queue: Daco Harkes Reviewed-by: Martin Kustermann --- runtime/bin/eventhandler_win.cc | 7 +++---- runtime/bin/file_system_watcher_win.cc | 2 +- runtime/bin/file_win.cc | 6 +++--- runtime/platform/globals.h | 4 ++-- runtime/tools/bin_to_assembly.py | 11 ++++++++++- runtime/vm/unwinding_records.cc | 4 ++++ 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/runtime/bin/eventhandler_win.cc b/runtime/bin/eventhandler_win.cc index df164ea89a0..c720994c8ee 100644 --- a/runtime/bin/eventhandler_win.cc +++ b/runtime/bin/eventhandler_win.cc @@ -116,6 +116,7 @@ int OverlappedBuffer::GetRemainingLength() { Handle::Handle(intptr_t handle) : ReferenceCounted(), DescriptorInfoBase(handle), + monitor_(), handle_(reinterpret_cast(handle)), completion_port_(INVALID_HANDLE_VALUE), event_handler_(nullptr), @@ -123,12 +124,11 @@ Handle::Handle(intptr_t handle) pending_read_(nullptr), pending_write_(nullptr), last_error_(NOERROR), - flags_(0), read_thread_id_(Thread::kInvalidThreadId), read_thread_handle_(nullptr), read_thread_starting_(false), read_thread_finished_(false), - monitor_() {} + flags_(0) {} Handle::~Handle() { } @@ -528,8 +528,7 @@ void ListenSocket::AcceptComplete(OverlappedBuffer* buffer, // Insert the accepted socket into the list. ClientSocket* client_socket = new ClientSocket( - buffer->client(), - std::move(std::unique_ptr(raw_remote_addr))); + buffer->client(), std::unique_ptr(raw_remote_addr)); client_socket->mark_connected(); client_socket->CreateCompletionPort(completion_port); if (accepted_head_ == nullptr) { diff --git a/runtime/bin/file_system_watcher_win.cc b/runtime/bin/file_system_watcher_win.cc index 8d9977573a7..84a4c82a2ea 100644 --- a/runtime/bin/file_system_watcher_win.cc +++ b/runtime/bin/file_system_watcher_win.cc @@ -7,7 +7,7 @@ #include "bin/file_system_watcher.h" -#include // NOLINT +#include // NOLINT #include "bin/builtin.h" #include "bin/eventhandler.h" diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc index 7ffd66a0bd5..c0b2438fe24 100644 --- a/runtime/bin/file_win.cc +++ b/runtime/bin/file_win.cc @@ -10,9 +10,9 @@ #include #include // NOLINT -#include // NOLINT #include // NOLINT #include // NOLINT +#include // NOLINT #undef StrDup // defined in Shlwapi.h as StrDupW #include // NOLINT #include // NOLINT @@ -328,8 +328,8 @@ class StringRAII { s_ = origin.release(); } - explicit StringRAII(const char* s) : s_(s), own_(false) {} - explicit StringRAII(char* s) : s_(s), own_(true) {} + explicit StringRAII(const char* s) : own_(false), s_(s) {} + explicit StringRAII(char* s) : own_(true), s_(s) {} ~StringRAII() { if (own_) { free(const_cast(s_)); diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h index 39c5bec66ca..4adb51ffdce 100644 --- a/runtime/platform/globals.h +++ b/runtime/platform/globals.h @@ -64,10 +64,10 @@ #define UNICODE #endif -#include -#include #include +#include #include +#include #include #include #endif // defined(_WIN32) diff --git a/runtime/tools/bin_to_assembly.py b/runtime/tools/bin_to_assembly.py index cd1bdd9a28a..6e3b373d823 100755 --- a/runtime/tools/bin_to_assembly.py +++ b/runtime/tools/bin_to_assembly.py @@ -69,6 +69,15 @@ def Main(): output_file.write(".const\n") output_file.write("public %s\n" % options.symbol_name) output_file.write("%s label byte\n" % options.symbol_name) + elif options.target_os in ["win_gnu"]: + # Cross compilation from Linux to Windows. + if options.executable: + output_file.write(".text\n") + else: + output_file.write(".section .rodata\n") + output_file.write(".global %s\n" % options.symbol_name) + output_file.write(".balign 32\n") + output_file.write("%s:\n" % options.symbol_name) else: if options.executable: output_file.write(".text\n") @@ -97,7 +106,7 @@ def Main(): if incbin: output_file.write(".incbin \"%s\"\n" % options.input) - if options.target_os not in ["mac", "ios", "win"]: + if options.target_os not in ["mac", "ios", "win", "win_gnu"]: output_file.write(".size {0}, .-{0}\n".format(options.symbol_name)) if options.size_symbol_name: diff --git a/runtime/vm/unwinding_records.cc b/runtime/vm/unwinding_records.cc index 58836ca408e..434e7ee7870 100644 --- a/runtime/vm/unwinding_records.cc +++ b/runtime/vm/unwinding_records.cc @@ -9,6 +9,10 @@ namespace dart { +const void* UnwindingRecords::GenerateRecordsInto(intptr_t offset, + uint8_t* target_buffer) { + return nullptr; +} void UnwindingRecords::RegisterExecutablePage(Page* page) {} void UnwindingRecords::UnregisterExecutablePage(Page* page) {}