Commit 4f0ee93b authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Introduce "-m32" compilation mode for Torque

Forge (Google3) can only run 64-bit executables. As Torque runs as part
of the build process, we need a 32-bit "cross-compile" mode when
we target 32-bit architectures. Note that this flag won't be needed
in Chromium/V8 land, since we build V8 with the same bit width as
the target architecture.

This CL adds a new runtime flag to torque "-m32". When enabled, the
flag forces 32-bit word sizes for various pointer/word sizes. By
default, the host system sizes from {src/commons/globals.h}
are used.

R=tebbi@chromium.org

Bug: v8:9641
Change-Id: I8701eec45e3fb59dc65049b0a679d34589c4127f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1763540
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63334}
parent 0a726b75
......@@ -11,9 +11,6 @@
namespace v8 {
namespace internal {
namespace torque {
DEFINE_CONTEXTUAL_VARIABLE(GlobalContext)
namespace {
template <class T>
......
......@@ -8,6 +8,9 @@ namespace v8 {
namespace internal {
namespace torque {
DEFINE_CONTEXTUAL_VARIABLE(GlobalContext)
DEFINE_CONTEXTUAL_VARIABLE(TargetArchitecture)
GlobalContext::GlobalContext(Ast ast)
: collect_language_server_data_(false),
force_assert_statements_(false),
......@@ -19,6 +22,10 @@ GlobalContext::GlobalContext(Ast ast)
RegisterDeclarable(base::make_unique<Namespace>(kBaseNamespaceName));
}
TargetArchitecture::TargetArchitecture(bool force_32bit)
: tagged_size_(force_32bit ? sizeof(int32_t) : kTaggedSize),
raw_ptr_size_(force_32bit ? sizeof(int32_t) : kSystemPointerSize) {}
} // namespace torque
} // namespace internal
} // namespace v8
......@@ -7,6 +7,7 @@
#include <map>
#include "src/common/globals.h"
#include "src/torque/ast.h"
#include "src/torque/contextual.h"
#include "src/torque/declarable.h"
......@@ -91,6 +92,18 @@ T* RegisterDeclarable(std::unique_ptr<T> d) {
return GlobalContext::Get().RegisterDeclarable(std::move(d));
}
class TargetArchitecture : public ContextualClass<TargetArchitecture> {
public:
explicit TargetArchitecture(bool force_32bit);
static int TaggedSize() { return Get().tagged_size_; }
static int RawPtrSize() { return Get().raw_ptr_size_; }
private:
const int tagged_size_;
const int raw_ptr_size_;
};
} // namespace torque
} // namespace internal
} // namespace v8
......
......@@ -53,6 +53,7 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
if (options.force_assert_statements) {
GlobalContext::SetForceAssertStatements();
}
TargetArchitecture::Scope target_architecture(options.force_32bit_output);
TypeOracle::Scope type_oracle;
// Two-step process of predeclaration + resolution allows to resolve type
......
......@@ -24,6 +24,12 @@ struct TorqueCompilerOptions {
// language server support for statements inside asserts, this flag
// can force generate them.
bool force_assert_statements = false;
// Forge (Google3) can only run 64-bit executables. As Torque runs as part
// of the build process, we need a "cross-compile" mode when we target 32-bit
// architectures. Note that this does not needed in Chromium/V8 land, since we
// always build with the same bit width as the target architecture.
bool force_32bit_output = false;
};
struct TorqueCompilerResult {
......
......@@ -19,19 +19,24 @@ std::string ErrorPrefixFor(TorqueMessage::Kind kind) {
}
int WrappedMain(int argc, const char** argv) {
std::string output_directory;
std::string v8_root;
TorqueCompilerOptions options;
options.collect_language_server_data = false;
options.force_assert_statements = false;
std::vector<std::string> files;
for (int i = 1; i < argc; ++i) {
// Check for options
if (std::string(argv[i]) == "-o") {
output_directory = argv[++i];
} else if (std::string(argv[i]) == "-v8-root") {
v8_root = std::string(argv[++i]);
const std::string argument(argv[i]);
if (argument == "-o") {
options.output_directory = argv[++i];
} else if (argument == "-v8-root") {
options.v8_root = std::string(argv[++i]);
} else if (argument == "-m32") {
options.force_32bit_output = true;
} else {
// Otherwise it's a .tq file. Remember it for compilation.
files.emplace_back(argv[i]);
files.emplace_back(std::move(argument));
if (!StringEndsWith(files.back(), ".tq")) {
std::cerr << "Unexpected command-line argument \"" << files.back()
<< "\", expected a .tq file.\n";
......@@ -40,12 +45,6 @@ int WrappedMain(int argc, const char** argv) {
}
}
TorqueCompilerOptions options;
options.output_directory = std::move(output_directory);
options.v8_root = std::move(v8_root);
options.collect_language_server_data = false;
options.force_assert_statements = false;
TorqueCompilerResult result = CompileTorque(files, options);
// PositionAsString requires the SourceFileMap to be set to
......
......@@ -314,7 +314,8 @@ void TypeVisitor::VisitClassFieldsAndMethods(
std::string machine_type;
std::tie(field_size, size_string) = field.GetFieldSizeInformation();
// Our allocations don't support alignments beyond kTaggedSize.
size_t alignment = std::min(size_t{kTaggedSize}, field_size);
size_t alignment = std::min(
static_cast<size_t>(TargetArchitecture::TaggedSize()), field_size);
if (alignment > 0 && class_offset % alignment != 0) {
ReportError("field ", field_expression.name_and_type.name,
" at offset ", class_offset, " is not ", alignment,
......
......@@ -4,9 +4,9 @@
#include <iostream>
#include "src/common/globals.h"
#include "src/torque/ast.h"
#include "src/torque/declarable.h"
#include "src/torque/global-context.h"
#include "src/torque/type-oracle.h"
#include "src/torque/type-visitor.h"
#include "src/torque/types.h"
......@@ -662,10 +662,10 @@ std::tuple<size_t, std::string> Field::GetFieldSizeInformation() const {
const Type* field_type = this->name_and_type.type;
size_t field_size = 0;
if (field_type->IsSubtypeOf(TypeOracle::GetTaggedType())) {
field_size = kTaggedSize;
field_size = TargetArchitecture::TaggedSize();
size_string = "kTaggedSize";
} else if (field_type->IsSubtypeOf(TypeOracle::GetRawPtrType())) {
field_size = kSystemPointerSize;
field_size = TargetArchitecture::RawPtrSize();
size_string = "kSystemPointerSize";
} else if (field_type->IsSubtypeOf(TypeOracle::GetVoidType())) {
field_size = 0;
......@@ -692,10 +692,10 @@ std::tuple<size_t, std::string> Field::GetFieldSizeInformation() const {
field_size = kDoubleSize;
size_string = "kDoubleSize";
} else if (field_type->IsSubtypeOf(TypeOracle::GetIntPtrType())) {
field_size = kIntptrSize;
field_size = TargetArchitecture::RawPtrSize();
size_string = "kIntptrSize";
} else if (field_type->IsSubtypeOf(TypeOracle::GetUIntPtrType())) {
field_size = kIntptrSize;
field_size = TargetArchitecture::RawPtrSize();
size_string = "kIntptrSize";
} else {
ReportError("fields of type ", *field_type, " are not (yet) supported");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment