Merge "Patch for compiling art to run on linux target"
diff --git a/build/Android.common_build.mk b/build/Android.common_build.mk
index dde3cdb..0235a30 100644
--- a/build/Android.common_build.mk
+++ b/build/Android.common_build.mk
@@ -363,11 +363,20 @@
ifndef LIBART_IMG_TARGET_BASE_ADDRESS
$(error LIBART_IMG_TARGET_BASE_ADDRESS unset)
endif
+
+ART_TARGET_CFLAGS += $(art_cflags) -DART_TARGET \
+ -DART_BASE_ADDRESS=$(LIBART_IMG_TARGET_BASE_ADDRESS) \
+
+ifeq ($(ART_TARGET_LINUX),true)
+# Setting ART_TARGET_LINUX to true compiles art/ assuming that the target device
+# will be running linux rather than android.
+ART_TARGET_CFLAGS += -DART_TARGET_LINUX
+else
# The ART_TARGET_ANDROID macro is passed to target builds, which check
# against it instead of against __ANDROID__ (which is provided by target
# toolchains).
-ART_TARGET_CFLAGS += $(art_cflags) -DART_TARGET -DART_TARGET_ANDROID \
- -DART_BASE_ADDRESS=$(LIBART_IMG_TARGET_BASE_ADDRESS) \
+ART_TARGET_CFLAGS += -DART_TARGET_ANDROID
+endif
ART_TARGET_CFLAGS += $(art_target_cflags)
ART_TARGET_ASFLAGS += $(art_asflags)
diff --git a/runtime/globals.h b/runtime/globals.h
index e7ea6f3..477cbdf 100644
--- a/runtime/globals.h
+++ b/runtime/globals.h
@@ -51,11 +51,31 @@
static constexpr bool kIsDebugBuild = true;
#endif
-// Whether or not this is a target (vs host) build. Useful in conditionals where ART_TARGET isn't.
+// ART_TARGET - Defined for target builds of ART.
+// ART_TARGET_LINUX - Defined for target Linux builds of ART.
+// ART_TARGET_ANDROID - Defined for target Android builds of ART.
+// Note: Either ART_TARGET_LINUX or ART_TARGET_ANDROID need to be set when ART_TARGET is set.
+// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
+// (usually only available on Android kernels).
#if defined(ART_TARGET)
+// Useful in conditionals where ART_TARGET isn't.
static constexpr bool kIsTargetBuild = true;
+#if defined(ART_TARGET_LINUX)
+static constexpr bool kIsTargetLinux = true;
+#elif defined(ART_TARGET_ANDROID)
+static constexpr bool kIsTargetLinux = false;
+#else
+#error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds."
+#endif
#else
static constexpr bool kIsTargetBuild = false;
+#if defined(ART_TARGET_LINUX)
+#error "ART_TARGET_LINUX defined for host build."
+#elif defined(ART_TARGET_ANDROID)
+#error "ART_TARGET_ANDROID defined for host build."
+#else
+static constexpr bool kIsTargetLinux = false;
+#endif
#endif
// Garbage collector constants.
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc
index 5d89c21..771f8ed 100644
--- a/runtime/mem_map.cc
+++ b/runtime/mem_map.cc
@@ -302,8 +302,9 @@
if (use_ashmem) {
if (!kIsTargetBuild) {
- // When not on Android ashmem is faked using files in /tmp. Ensure that such files won't
- // fail due to ulimit restrictions. If they will then use a regular mmap.
+ // When not on Android (either host or assuming a linux target) ashmem is faked using
+ // files in /tmp. Ensure that such files won't fail due to ulimit restrictions. If they
+ // will then use a regular mmap.
struct rlimit rlimit_fsize;
CHECK_EQ(getrlimit(RLIMIT_FSIZE, &rlimit_fsize), 0);
use_ashmem = (rlimit_fsize.rlim_cur == RLIM_INFINITY) ||
diff --git a/runtime/mem_map.h b/runtime/mem_map.h
index 3eaf576..597f0d4 100644
--- a/runtime/mem_map.h
+++ b/runtime/mem_map.h
@@ -68,7 +68,7 @@
bool low_4gb,
bool reuse,
std::string* error_msg,
- bool use_ashmem = true);
+ bool use_ashmem = !kIsTargetLinux);
// Create placeholder for a region allocated by direct call to mmap.
// This is useful when we do not have control over the code calling mmap,
@@ -172,7 +172,7 @@
const char* tail_name,
int tail_prot,
std::string* error_msg,
- bool use_ashmem = true);
+ bool use_ashmem = !kIsTargetLinux);
static bool CheckNoGaps(MemMap* begin_map, MemMap* end_map)
REQUIRES(!Locks::mem_maps_lock_);