Commit 47e272b2 authored by jgruber's avatar jgruber Committed by Commit Bot

Reland "Reland "[builtins] Add .incbin cctest""

This is a reland of ef06fede.

Original change's description:
> Reland "[builtins] Add .incbin cctest"
>
> This is a reland of b0128161.
>
> Original change's description:
> > [builtins] Add .incbin cctest
> >
> > Just to ensure this is portable across all platforms.
> >
> > Credits go to https://github.com/graphitemaster/incbin, bits of the
> > .incbin code were taken from there. Thanks!
> >
> > Reland of https://crrev.com/c/881181
> >
> > Bug: v8:6666
> > Change-Id: I5c0dbf56b1c987fd88607dca69b39d65b59cdefc
> > Reviewed-on: https://chromium-review.googlesource.com/895597
> > Commit-Queue: Jakob Gruber <jgruber@chromium.org>
> > Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#51042}
>
> Cq-Include-Trybots: luci.v8.try:v8_win64_msvc_compile_rel
> Bug: v8:6666
> Change-Id: I8fc0963e28996a84ed56c2e740d895e26611abf0
> Reviewed-on: https://chromium-review.googlesource.com/897630
> Commit-Queue: Jakob Gruber <jgruber@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#51054}

Bug: v8:6666
Change-Id: Icc6816e260dac2d8b8f6c9c4a2725b271dac4664
Cq-Include-Trybots: luci.v8.try:v8_win64_msvc_compile_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/898927
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51075}
parent ebebc864
......@@ -6,6 +6,18 @@
'variables': {
'v8_code': 1,
'generated_file': '<(SHARED_INTERMEDIATE_DIR)/resources.cc',
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-arm.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-arm64.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-ia32.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-mips.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-mips64.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-ppc.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-s390.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-x64-win.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/f-x64.bin',
'<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/string.bin',
],
'cctest_sources': [
'../test/cctest/compiler/c-signature.h',
'../test/cctest/compiler/call-tester.h',
......@@ -302,6 +314,7 @@
'type': 'executable',
'dependencies': [
'resources',
'test-isolate-independent-builtins-files',
'v8.gyp:v8_libbase',
'v8.gyp:v8_libplatform',
],
......@@ -411,6 +424,27 @@
}],
],
},
{
'target_name': 'test-isolate-independent-builtins-files',
'type': 'none',
'copies': [
{
'destination': '<(SHARED_INTERMEDIATE_DIR)/test-isolate-independent-builtins/',
'files': [
'../test/cctest/test-isolate-independent-builtins/f-arm.bin',
'../test/cctest/test-isolate-independent-builtins/f-arm64.bin',
'../test/cctest/test-isolate-independent-builtins/f-ia32.bin',
'../test/cctest/test-isolate-independent-builtins/f-mips.bin',
'../test/cctest/test-isolate-independent-builtins/f-mips64.bin',
'../test/cctest/test-isolate-independent-builtins/f-ppc.bin',
'../test/cctest/test-isolate-independent-builtins/f-s390.bin',
'../test/cctest/test-isolate-independent-builtins/f-x64-win.bin',
'../test/cctest/test-isolate-independent-builtins/f-x64.bin',
'../test/cctest/test-isolate-independent-builtins/string.bin',
],
},
],
},
{
'target_name': 'resources',
'type': 'none',
......
......@@ -35,6 +35,20 @@ v8_executable("cctest") {
v8_source_set("cctest_sources") {
testonly = true
# Create a dependency from this target to the generated files below.
inputs = [
"$root_gen_dir/test-isolate-independent-builtins/f-arm64.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-arm.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-ia32.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-mips64.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-mips.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-ppc.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-s390.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-x64.bin",
"$root_gen_dir/test-isolate-independent-builtins/f-x64-win.bin",
"$root_gen_dir/test-isolate-independent-builtins/string.bin",
]
sources = [
"$target_gen_dir/resources.cc",
......@@ -361,6 +375,7 @@ v8_source_set("cctest_sources") {
public_deps = [
":resources",
":test-isolate-independent-builtins-files",
"../..:v8_initializers",
"../..:v8_libbase",
"../..:v8_libplatform",
......@@ -409,6 +424,25 @@ v8_source_set("cctest_sources") {
}
}
copy("test-isolate-independent-builtins-files") {
sources = [
"test-isolate-independent-builtins/f-arm.bin",
"test-isolate-independent-builtins/f-arm64.bin",
"test-isolate-independent-builtins/f-ia32.bin",
"test-isolate-independent-builtins/f-mips.bin",
"test-isolate-independent-builtins/f-mips64.bin",
"test-isolate-independent-builtins/f-ppc.bin",
"test-isolate-independent-builtins/f-s390.bin",
"test-isolate-independent-builtins/f-x64-win.bin",
"test-isolate-independent-builtins/f-x64.bin",
"test-isolate-independent-builtins/string.bin",
]
outputs = [
"$root_gen_dir/test-isolate-independent-builtins/{{source_file_part}}",
]
}
action("resources") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
......
......@@ -4,11 +4,43 @@
#include "test/cctest/cctest.h"
#include "src/assembler.h"
#include "src/assembler-inl.h"
#include "src/handles-inl.h"
#include "src/isolate.h"
#include "src/macro-assembler-inl.h"
#include "src/simulator.h"
#include "src/snapshot/snapshot.h"
// To generate the binary files for the test function (used in the IncbinInText
// below), enable this section and run GenerateTestFunctionData once on each
// arch.
#define GENERATE_TEST_FUNCTION_DATA false
// Arch-specific defines.
#if V8_TARGET_ARCH_IA32
#define TEST_FUNCTION_FILE "f-ia32.bin"
#elif V8_TARGET_ARCH_X64 && _WIN64
#define TEST_FUNCTION_FILE "f-x64-win.bin"
#elif V8_TARGET_ARCH_X64
#define TEST_FUNCTION_FILE "f-x64.bin"
#elif V8_TARGET_ARCH_ARM64
#define TEST_FUNCTION_FILE "f-arm64.bin"
#elif V8_TARGET_ARCH_ARM
#define TEST_FUNCTION_FILE "f-arm.bin"
#elif V8_TARGET_ARCH_PPC
#define TEST_FUNCTION_FILE "f-ppc.bin"
#elif V8_TARGET_ARCH_MIPS
#define TEST_FUNCTION_FILE "f-mips.bin"
#elif V8_TARGET_ARCH_MIPS64
#define TEST_FUNCTION_FILE "f-mips64.bin"
#elif V8_TARGET_ARCH_S390
#define TEST_FUNCTION_FILE "f-s390.bin"
#else
#error "Unknown architecture."
#endif
#define __ masm.
namespace v8 {
namespace internal {
namespace test_isolate_independent_builtins {
......@@ -76,6 +108,166 @@ TEST(VerifyBuiltinsIsolateIndependence) {
CHECK(!found_mismatch);
}
// .incbin macros.
// V8_CC_MSVC is true for both MSVC and clang on windows. clang can handle
// .incbin but MSVC cannot, and thus we need a more precise compiler detection
// that can distinguish between the two. clang on windows sets both __clang__
// and _MSC_VER, MSVC sets only _MSC_VER.
#if defined(_MSC_VER) && !defined(__clang__)
#define V8_COMPILER_IS_MSVC
#endif
#ifndef V8_COMPILER_IS_MSVC
#if defined(V8_OS_MACOSX)
#define INCBIN_RODATA_SECTION ".const_data\n"
#define INCBIN_TEXT_SECTION ".text\n"
#define INCBIN_MANGLE "_"
#define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE NAME "\n"
#elif defined(V8_OS_WIN)
#define INCBIN_RODATA_SECTION ".section .rodata\n"
#define INCBIN_TEXT_SECTION ".section .text\n"
#if defined(V8_TARGET_ARCH_X64)
#define INCBIN_MANGLE ""
#else
#define INCBIN_MANGLE "_"
#endif
#define INCBIN_GLOBAL(NAME) ".global " INCBIN_MANGLE NAME "\n"
#else
#define INCBIN_RODATA_SECTION ".section .rodata\n"
#define INCBIN_TEXT_SECTION ".section .text\n"
#define INCBIN_MANGLE ""
#define INCBIN_GLOBAL(NAME) ".global " INCBIN_MANGLE NAME "\n"
#endif
// clang-format off
#define INCBIN_RODATA(LABEL, FILE) \
__asm__(INCBIN_RODATA_SECTION \
INCBIN_GLOBAL(#LABEL) \
".balign 16\n" \
INCBIN_MANGLE #LABEL ":\n" \
".incbin \"" FILE "\"\n"); \
extern "C" V8_ALIGNED(16) const char LABEL[]
#define INCBIN_TEXT(LABEL, FILE) \
__asm__(INCBIN_TEXT_SECTION \
INCBIN_GLOBAL(#LABEL) \
".balign 16\n" \
INCBIN_MANGLE #LABEL ":\n" \
".incbin \"" FILE "\"\n"); \
extern "C" V8_ALIGNED(16) const char LABEL[]
// clang-format on
INCBIN_RODATA(test_string_bytes,
"gen/test-isolate-independent-builtins/string.bin");
INCBIN_TEXT(test_function_bytes,
"gen/test-isolate-independent-builtins/" TEST_FUNCTION_FILE);
#if GENERATE_TEST_FUNCTION_DATA
TEST(GenerateTestFunctionData) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
#if V8_TARGET_ARCH_IA32
v8::internal::byte buffer[256];
Assembler masm(isolate, buffer, sizeof(buffer));
__ mov(eax, Operand(esp, 4));
__ add(eax, Operand(esp, 8));
__ ret(0);
#elif V8_TARGET_ARCH_X64
size_t allocated;
byte* buffer = AllocateAssemblerBuffer(&allocated);
Assembler masm(isolate, buffer, static_cast<int>(allocated));
#ifdef _WIN64
static const Register arg1 = rcx;
static const Register arg2 = rdx;
#else
static const Register arg1 = rdi;
static const Register arg2 = rsi;
#endif
__ movq(rax, arg2);
__ addq(rax, arg1);
__ ret(0);
#elif V8_TARGET_ARCH_ARM64
MacroAssembler masm(isolate, nullptr, 0,
v8::internal::CodeObjectRequired::kYes);
__ Add(x0, x0, x1);
__ Ret();
#elif V8_TARGET_ARCH_ARM
Assembler masm(isolate, nullptr, 0);
__ add(r0, r0, Operand(r1));
__ mov(pc, Operand(lr));
#elif V8_TARGET_ARCH_PPC
Assembler masm(isolate, nullptr, 0);
__ function_descriptor();
__ add(r3, r3, r4);
__ blr();
#elif V8_TARGET_ARCH_MIPS
MacroAssembler masm(isolate, nullptr, 0,
v8::internal::CodeObjectRequired::kYes);
__ addu(v0, a0, a1);
__ jr(ra);
__ nop();
#elif V8_TARGET_ARCH_MIPS64
MacroAssembler masm(isolate, nullptr, 0,
v8::internal::CodeObjectRequired::kYes);
__ addu(v0, a0, a1);
__ jr(ra);
__ nop();
#elif V8_TARGET_ARCH_S390
Assembler masm(isolate, nullptr, 0);
__ lhi(r1, Operand(3));
__ llilf(r2, Operand(4));
__ lgr(r2, r2);
__ ar(r2, r1);
__ b(r14);
#else // Unknown architecture.
#error "Unknown architecture."
#endif // Target architecture.
CodeDesc desc;
masm.GetCode(isolate, &desc);
std::ofstream of(TEST_FUNCTION_FILE, std::ios::out | std::ios::binary);
of.write(reinterpret_cast<char*>(desc.buffer), desc.instr_size);
}
#endif // GENERATE_TEST_FUNCTION_DATA
#undef __
#undef GENERATE_TEST_FUNCTION_DATA
#undef INCBIN_GLOBAL
#undef INCBIN_MANGLE
#undef INCBIN_RODATA
#undef INCBIN_RODATA_SECTION
#undef INCBIN_TEXT
#undef INCBIN_TEXT_SECTION
#undef TEST_FUNCTION_FILE
TEST(IncbinInRodata) {
CHECK_EQ(0, std::strcmp("0123456789\n", test_string_bytes));
}
TEST(IncbinInText) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
auto f = GeneratedCode<int(int, int)>::FromAddress(
isolate, const_cast<char*>(test_function_bytes));
CHECK_EQ(7, f.Call(3, 4));
CHECK_EQ(11, f.Call(5, 6));
}
#endif // #ifndef V8_COMPILER_IS_MSVC
#undef V8_COMPILER_IS_MSVC
} // namespace test_isolate_independent_builtins
} // namespace internal
} // namespace v8
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