Skip to content

Commit

Permalink
Set TARGET_OS_* from GN, falling back to HOST_OS_*.
Browse files Browse the repository at this point in the history
Use TARGET_OS_* instead of HOST_OS_* to decide on the assembly variant to use. Allows, say, a gen_snapshot compiled for a Mac to target Android when generating AOT as assembly.

R=fschneider@google.com, zra@google.com

Review-Url: https://codereview.chromium.org/2757783003 .
  • Loading branch information
rmacnak-google committed Mar 20, 2017
1 parent 5bbf6ec commit 9f2668c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 82 deletions.
27 changes: 19 additions & 8 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,34 @@ config("dart_config") {
dart_target_arch = "dbc"
}

if (target_os == "android") {
defines += [ "TARGET_OS_ANDROID" ]
} else if (target_os == "fuchsia") {
defines += [ "TARGET_OS_FUCHSIA" ]
} else if (target_os == "ios") {
defines += [ "TARGET_OS_MACOS" ]
defines += [ "TARGET_OS_MACOS_IOS" ]
} else if (target_os == "linux") {
defines += [ "TARGET_OS_LINUX" ]
} else if (target_os == "mac") {
defines += [ "TARGET_OS_MACOS" ]
} else if (target_os == "win") {
defines += [ "TARGET_OS_WINDOWS" ]
} else {
print("Unknown target_os: $target_os")
assert(false)
}

if (dart_target_arch != "") {
if (dart_target_arch == "arm" || dart_target_arch == "simarm") {
defines += [ "TARGET_ARCH_ARM" ]
if (target_os == "mac" || target_os == "ios") {
defines += [ "TARGET_ABI_IOS" ]
} else {
defines += [ "TARGET_ABI_EABI" ]
}
} else if (dart_target_arch == "armv6" || dart_target_arch == "simarmv6") {
defines += [ "TARGET_ARCH_ARM" ]
defines += [ "TARGET_ARCH_ARM_6" ]
defines += [ "TARGET_ABI_EABI" ]
} else if (dart_target_arch == "armv5te" ||
dart_target_arch == "simarmv5te") {
defines += [ "TARGET_ARCH_ARM" ]
defines += [ "TARGET_ARCH_ARM_5TE" ]
defines += [ "TARGET_ABI_EABI" ]
} else if (dart_target_arch == "arm64" || dart_target_arch == "simarm64") {
defines += [ "TARGET_ARCH_ARM64" ]
} else if (dart_target_arch == "mips" || dart_target_arch == "simmips") {
Expand All @@ -140,7 +151,7 @@ config("dart_config") {
defines += [ "TARGET_ARCH_DBC" ]
defines += [ "USING_SIMULATOR" ]
} else {
print("Invalid $dart_target_arch")
print("Invalid dart_target_arch: $dart_target_arch")
assert(false)
}
}
Expand Down
43 changes: 21 additions & 22 deletions runtime/platform/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@
// the value defined in TargetConditionals.h
#define HOST_OS_MACOS 1
#if TARGET_OS_IPHONE
// Test for this #define by saying '#if TARGET_OS_IOS' rather than the usual
// '#if defined(TARGET_OS_IOS)'. TARGET_OS_IOS is defined to be 0 in
// XCode >= 7.0. See Issue #24453.
#define HOST_OS_IOS 1
#endif

Expand Down Expand Up @@ -310,12 +307,9 @@ typedef simd128_value_t fpu_register_t;
#error Automatic compiler detection failed.
#endif

#if !defined(TARGET_ARCH_MIPS)
#if !defined(TARGET_ARCH_ARM)
#if !defined(TARGET_ARCH_X64)
#if !defined(TARGET_ARCH_IA32)
#if !defined(TARGET_ARCH_ARM64)
#if !defined(TARGET_ARCH_DBC)
#if !defined(TARGET_ARCH_MIPS) && !defined(TARGET_ARCH_ARM) && \
!defined(TARGET_ARCH_X64) && !defined(TARGET_ARCH_IA32) && \
!defined(TARGET_ARCH_ARM64) && !defined(TARGET_ARCH_DBC)
// No target architecture specified pick the one matching the host architecture.
#if defined(HOST_ARCH_MIPS)
#define TARGET_ARCH_MIPS 1
Expand All @@ -331,11 +325,6 @@ typedef simd128_value_t fpu_register_t;
#error Automatic target architecture detection failed.
#endif
#endif
#endif
#endif
#endif
#endif
#endif

// Verify that host and target architectures match, we cannot
// have a 64 bit Dart VM generating 32 bit code or vice-versa.
Expand Down Expand Up @@ -384,17 +373,27 @@ typedef simd128_value_t fpu_register_t;
#endif


#if defined(TARGET_ARCH_ARM)
#if defined(TARGET_ABI_IOS) && defined(TARGET_ABI_EABI)
#error Both TARGET_ABI_IOS and TARGET_ABI_EABI defined.
#elif !defined(TARGET_ABI_IOS) && !defined(TARGET_ABI_EABI)
#if defined(HOST_OS_MAC)
#define TARGET_ABI_IOS 1
#if !defined(TARGET_OS_ANDROID) && !defined(TARGET_OS_FUCHSIA) && \
!defined(TARGET_OS_MACOS_IOS) && !defined(TARGET_OS_LINUX) && \
!defined(TARGET_OS_MACOS) && !defined(TARGET_OS_WINDOWS)
// No target OS specified; pick the one matching the host OS.
#if defined(HOST_OS_ANDROID)
#define TARGET_OS_ANDROID 1
#elif defined(HOST_OS_FUCHSIA)
#define TARGET_OS_FUCHSIA 1
#elif defined(HOST_OS_IOS)
#define TARGET_OS_MACOS 1
#define TARGET_OS_MACOS_IOS 1
#elif defined(HOST_OS_LINUX)
#define TARGET_OS_LINUX 1
#elif defined(HOST_OS_MACOS)
#define TARGET_OS_MACOS 1
#elif defined(HOST_OS_WINDOWS)
#define TARGET_OS_WINDOWS 1
#else
#define TARGET_ABI_EABI 1
#error Automatic target OS detection failed.
#endif
#endif
#endif // TARGET_ARCH_ARM


// Short form printf format specifiers
Expand Down
16 changes: 6 additions & 10 deletions runtime/vm/constants_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ enum Register {
kNoRegister = -1, // Signals an illegal register.

// Aliases.
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
FP = R7,
NOTFP = R11,
#elif defined(TARGET_ABI_EABI)
#else
FP = R11,
NOTFP = R7,
#else
#error Unknown ABI
#endif
IP = R12,
SP = R13,
Expand Down Expand Up @@ -305,17 +303,15 @@ const RegList kAllCpuRegistersList = 0xFFFF;
// C++ ABI call registers.
const RegList kAbiArgumentCpuRegs =
(1 << R0) | (1 << R1) | (1 << R2) | (1 << R3);
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
const RegList kAbiPreservedCpuRegs =
(1 << R4) | (1 << R5) | (1 << R6) | (1 << R8) | (1 << R10) | (1 << R11);
const int kAbiPreservedCpuRegCount = 6;
#elif defined(TARGET_ABI_EABI)
#else
const RegList kAbiPreservedCpuRegs = (1 << R4) | (1 << R5) | (1 << R6) |
(1 << R7) | (1 << R8) | (1 << R9) |
(1 << R10);
const int kAbiPreservedCpuRegCount = 7;
#else
#error Unknown ABI
#endif
const QRegister kAbiFirstPreservedFpuReg = Q4;
const QRegister kAbiLastPreservedFpuReg = Q7;
Expand All @@ -329,9 +325,9 @@ const RegList kDartAvailableCpuRegs =
// Registers available to Dart that are not preserved by runtime calls.
const RegList kDartVolatileCpuRegs =
kDartAvailableCpuRegs & ~kAbiPreservedCpuRegs;
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
const int kDartVolatileCpuRegCount = 6;
#elif defined(TARGET_ABI_EABI)
#else
const int kDartVolatileCpuRegCount = 5;
#endif
const QRegister kDartFirstVolatileFpuReg = Q0;
Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/cpu_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ DEFINE_FLAG(bool,
#endif

#if defined(USING_SIMULATOR)
#if defined(TARGET_ARCH_ARM_5TE)
DEFINE_FLAG(bool, sim_use_hardfp, false, "Use the softfp ABI.");
#if defined(TARGET_ARCH_ARM_5TE) || defined(TARGET_OS_ANDROID)
DEFINE_FLAG(bool, sim_use_hardfp, false, "Use the hardfp ABI.");
#else
DEFINE_FLAG(bool, sim_use_hardfp, true, "Use the softfp ABI.");
DEFINE_FLAG(bool, sim_use_hardfp, true, "Use the hardfp ABI.");
#endif
#endif

Expand Down
6 changes: 2 additions & 4 deletions runtime/vm/dart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,10 @@ const char* Dart::FeaturesString(Isolate* isolate, Snapshot::Kind kind) {

// Generated code must match the host architecture and ABI.
#if defined(TARGET_ARCH_ARM)
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
buffer.AddString(" arm-ios");
#elif defined(TARGET_ABI_EABI)
buffer.AddString(" arm-eabi");
#else
#error Unknown ABI
buffer.AddString(" arm-eabi");
#endif
buffer.AddString(TargetCPUFeatures::hardfp_supported() ? " hardfp"
: " softfp");
Expand Down
6 changes: 2 additions & 4 deletions runtime/vm/disassembler_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ void ARMDecoder::PrintCondition(Instr* instr) {
// formatting, except for register alias pp (r5).
// See for example the command "objdump -d <binary file>".
static const char* reg_names[kNumberOfCpuRegisters] = {
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
"r0", "r1", "r2", "r3", "r4", "pp", "r6", "fp",
"r8", "r9", "thr", "r11", "ip", "sp", "lr", "pc",
#elif defined(TARGET_ABI_EABI)
#else
"r0", "r1", "r2", "r3", "r4", "pp", "r6", "r7",
"r8", "r9", "thr", "fp", "ip", "sp", "lr", "pc",
#else
#error Unknown ABI
#endif
};

Expand Down
18 changes: 12 additions & 6 deletions runtime/vm/dwarf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ void Dwarf::WriteAbbreviations() {
// DIEs. Each DIE begins with an abbreviation code, and the abbreviation
// describes the attributes of that DIE and their representation.

#if defined(HOST_OS_MACOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
Print(".section __DWARF,__debug_abbrev,regular,debug\n");
#else
#elif defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID)
Print(".section .debug_abbrev,\"\"\n");
#else
UNIMPLEMENTED();
#endif

uleb128(kCompilationUnit); // Abbrev code.
Expand Down Expand Up @@ -227,10 +229,12 @@ void Dwarf::WriteAbbreviations() {
void Dwarf::WriteCompilationUnit() {
// 7.5.1.1 Compilation Unit Header

#if defined(HOST_OS_MACOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
Print(".section __DWARF,__debug_info,regular,debug\n");
#else
#elif defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID)
Print(".section .debug_info,\"\"\n");
#else
UNIMPLEMENTED();
#endif
Print(".Ldebug_info:\n");

Expand Down Expand Up @@ -455,10 +459,12 @@ void Dwarf::WriteInliningNode(InliningNode* node,


void Dwarf::WriteLines() {
#if defined(HOST_OS_MACOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
Print(".section __DWARF,__debug_line,regular,debug\n");
#else
#elif defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID)
Print(".section .debug_line,\"\"\n");
#else
UNIMPLEMENTED();
#endif

// 6.2.4 The Line Number Program Header
Expand Down
8 changes: 4 additions & 4 deletions runtime/vm/simulator_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3776,7 +3776,7 @@ int64_t Simulator::Call(int32_t entry,
int32_t r6_val = get_register(R6);
int32_t r7_val = get_register(R7);
int32_t r8_val = get_register(R8);
#if defined(TARGET_ABI_EABI)
#if !defined(TARGET_OS_MACOS) && !defined(TARGET_OS_MACOS_IOS)
int32_t r9_val = get_register(R9);
#endif
int32_t r10_val = get_register(R10);
Expand Down Expand Up @@ -3810,7 +3810,7 @@ int64_t Simulator::Call(int32_t entry,
set_register(R6, callee_saved_value);
set_register(R7, callee_saved_value);
set_register(R8, callee_saved_value);
#if defined(TARGET_ABI_EABI)
#if !defined(TARGET_OS_MACOS) && !defined(TARGET_OS_MACOS_IOS)
set_register(R9, callee_saved_value);
#endif
set_register(R10, callee_saved_value);
Expand Down Expand Up @@ -3838,7 +3838,7 @@ int64_t Simulator::Call(int32_t entry,
ASSERT(callee_saved_value == get_register(R6));
ASSERT(callee_saved_value == get_register(R7));
ASSERT(callee_saved_value == get_register(R8));
#if defined(TARGET_ABI_EABI)
#if !defined(TARGET_OS_MACOS) && !defined(TARGET_OS_MACOS_IOS)
ASSERT(callee_saved_value == get_register(R9));
#endif
ASSERT(callee_saved_value == get_register(R10));
Expand All @@ -3861,7 +3861,7 @@ int64_t Simulator::Call(int32_t entry,
set_register(R6, r6_val);
set_register(R7, r7_val);
set_register(R8, r8_val);
#if defined(TARGET_ABI_EABI)
#if !defined(TARGET_OS_MACOS) && !defined(TARGET_OS_MACOS_IOS)
set_register(R9, r9_val);
#endif
set_register(R10, r10_val);
Expand Down
30 changes: 15 additions & 15 deletions runtime/vm/snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -901,13 +901,13 @@ void AssemblyImageWriter::WriteText(WriteStream* clustered_stream, bool vm) {

FrameUnwindEpilogue();

#if defined(HOST_OS_LINUX)
#if defined(TARGET_OS_LINUX) || defined(TARGET_OS_ANDROID) || \
defined(TARGET_OS_FUCHSIA)
assembly_stream_.Print(".section .rodata\n");
#elif defined(HOST_OS_MACOS)
#elif defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
assembly_stream_.Print(".const\n");
#else
// Unsupported platform.
UNREACHABLE();
UNIMPLEMENTED();
#endif

const char* data_symbol =
Expand Down Expand Up @@ -959,14 +959,14 @@ void AssemblyImageWriter::FrameUnwindPrologue() {
assembly_stream_.Print(".cfi_escape 0x10, 31, 2, 0x23, 16\n");

#elif defined(TARGET_ARCH_ARM)
#if defined(TARGET_ABI_EABI)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
COMPILE_ASSERT(FP == R7);
assembly_stream_.Print(".cfi_def_cfa r7, 0\n"); // CFA is fp+j0
assembly_stream_.Print(".cfi_offset r7, 0\n"); // saved fp is *(CFA+0)
#else
COMPILE_ASSERT(FP == R11);
assembly_stream_.Print(".cfi_def_cfa r11, 0\n"); // CFA is fp+0
assembly_stream_.Print(".cfi_offset r11, 0\n"); // saved fp is *(CFA+0)
#elif defined(TARGET_ABI_IOS)
COMPILE_ASSERT(FP == R7);
assembly_stream_.Print(".cfi_def_cfa r7, 0\n"); // CFA is fp+0
assembly_stream_.Print(".cfi_offset r7, 0\n"); // saved fp is *(CFA+0)
#endif
assembly_stream_.Print(".cfi_offset lr, 4\n"); // saved pc is *(CFA+4)
// saved sp is CFA+8
Expand All @@ -980,16 +980,16 @@ void AssemblyImageWriter::FrameUnwindPrologue() {
assembly_stream_.Print(".cfi_escape 0x10, 13, 2, 0x23, 8\n");

// libunwind on ARM may use .ARM.exidx instead of .debug_frame
#if defined(TARGET_ABI_EABI)
COMPILE_ASSERT(FP == R11);
assembly_stream_.Print(".fnstart\n");
assembly_stream_.Print(".save {r11, lr}\n");
assembly_stream_.Print(".setfp r11, sp, #0\n");
#elif defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
COMPILE_ASSERT(FP == R7);
assembly_stream_.Print(".fnstart\n");
assembly_stream_.Print(".save {r7, lr}\n");
assembly_stream_.Print(".setfp r7, sp, #0\n");
#else
COMPILE_ASSERT(FP == R11);
assembly_stream_.Print(".fnstart\n");
assembly_stream_.Print(".save {r11, lr}\n");
assembly_stream_.Print(".setfp r11, sp, #0\n");
#endif

#elif defined(TARGET_ARCH_MIPS)
Expand Down
6 changes: 2 additions & 4 deletions runtime/vm/stack_frame_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ static const int kParamEndSlotFromFp = 1; // One slot past last parameter.
static const int kCallerSpSlotFromFp = 2;

// Entry and exit frame layout.
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
static const int kExitLinkSlotFromEntryFp = -26;
COMPILE_ASSERT(kAbiPreservedCpuRegCount == 6);
COMPILE_ASSERT(kAbiPreservedFpuRegCount == 4);
#elif defined(TARGET_ABI_EABI)
#else
static const int kExitLinkSlotFromEntryFp = -27;
COMPILE_ASSERT(kAbiPreservedCpuRegCount == 7);
COMPILE_ASSERT(kAbiPreservedFpuRegCount == 4);
#else
#error Unknown ABI
#endif

} // namespace dart
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/stub_code_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,9 @@ void StubCode::GenerateInvokeDartCodeStub(Assembler* assembler) {

// kExitLinkSlotFromEntryFp must be kept in sync with the code below.
__ Push(R4);
#if defined(TARGET_ABI_IOS)
#if defined(TARGET_OS_MACOS) || defined(TARGET_OS_MACOS_IOS)
ASSERT(kExitLinkSlotFromEntryFp == -26);
#elif defined(TARGET_ABI_EABI)
#else
ASSERT(kExitLinkSlotFromEntryFp == -27);
#endif
__ Push(R9);
Expand Down

0 comments on commit 9f2668c

Please sign in to comment.