[Lldb-commits] [PATCH] D11309: Detect if necessary to build inferior with -pie for Android.

Chaoren Lin chaorenl at google.com
Fri Jul 17 13:17:12 PDT 2015


chaoren created this revision.
chaoren added reviewers: clayborg, sivachandra, tberghammer.
chaoren added a subscriber: lldb-commits.
Herald added subscribers: srhines, danalbert, tberghammer.

- Add target_is_android check (with cached results).
- Make android_device_api also cache results.
- Also removes the need to pass --env OS=Android when testing against Android.

http://reviews.llvm.org/D11309

Files:
  test/lldbtest.py
  test/make/Makefile.rules

Index: test/make/Makefile.rules
===================================================================
--- test/make/Makefile.rules
+++ test/make/Makefile.rules
@@ -251,7 +251,9 @@
 # Android specific options
 #----------------------------------------------------------------------
 ifeq "$(OS)" "Android"
-    LDFLAGS += -pie
+    ifdef PIE
+        LDFLAGS += -pie
+    endif
     replace_with = $(if $(findstring clang,$(1)), \
                         $(subst clang,$(2),$(1)), \
                         $(if $(findstring gcc,$(1)), \
Index: test/lldbtest.py
===================================================================
--- test/lldbtest.py
+++ test/lldbtest.py
@@ -431,21 +431,30 @@
     stdout, stderr = p.communicate()
     return p.returncode, stdout, stderr
 
+def target_is_android():
+    if not hasattr(target_is_android, 'result'):
+        triple = self.dbg.GetSelectedPlatform().GetTriple()
+        match = re.match(".*-.*-.*-android", triple)
+        target_is_android.result = match is not None
+    return target_is_android.result
+
 def android_device_api():
-    assert lldb.platform_url is not None
-    device_id = None
-    parsed_url = urlparse.urlparse(lldb.platform_url)
-    if parsed_url.scheme == "adb":
-        device_id = parsed_url.netloc.split(":")[0]
-    retcode, stdout, stderr = run_adb_command(
-        ["shell", "getprop", "ro.build.version.sdk"], device_id)
-    if retcode == 0:
-        return int(stdout)
-    else:
-        raise LookupError(
-            ">>> Unable to determine the API level of the Android device.\n"
-            ">>> stdout:\n%s\n"
-            ">>> stderr:\n%s\n" % (stdout, stderr))
+    if not hasattr(android_device_api, 'result'):
+        assert lldb.platform_url is not None
+        device_id = None
+        parsed_url = urlparse.urlparse(lldb.platform_url)
+        if parsed_url.scheme == "adb":
+            device_id = parsed_url.netloc.split(":")[0]
+        retcode, stdout, stderr = run_adb_command(
+            ["shell", "getprop", "ro.build.version.sdk"], device_id)
+        if retcode == 0:
+            android_device_api.result = int(stdout)
+        else:
+            raise LookupError(
+                ">>> Unable to determine the API level of the Android device.\n"
+                ">>> stdout:\n%s\n"
+                ">>> stderr:\n%s\n" % (stdout, stderr))
+    return android_device_api.result
 
 #
 # Decorators for categorizing test cases.
@@ -690,9 +699,7 @@
             for which a test is expected to fail.
     """
     def fn(self):
-        triple = self.dbg.GetSelectedPlatform().GetTriple()
-        match = re.match(".*-.*-.*-android", triple)
-        if match:
+        if target_is_android():
             if not api_levels:
                 return True
             device_api = android_device_api()
@@ -1036,8 +1043,7 @@
         def wrapper(*args, **kwargs):
             from unittest2 import case
             self = args[0]
-            triple = self.dbg.GetSelectedPlatform().GetTriple()
-            if re.match(".*-.*-.*-android", triple):
+            if target_is_android():
                 if api_levels:
                     device_api = android_device_api()
                     if device_api and (device_api in api_levels):
@@ -1982,6 +1988,10 @@
         if lldb.skip_build_and_cleanup:
             return
         module = builder_module()
+        if target_is_android():
+            dictionary["OS"] = "Android"
+            if android_device_api() > 14:
+                dictionary["PIE"] = 1
         if not module.buildDwarf(self, architecture, compiler, dictionary, clean):
             raise Exception("Don't know how to build binary with dwarf")
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11309.30027.patch
Type: text/x-patch
Size: 3698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150717/06f4530a/attachment.bin>


More information about the lldb-commits mailing list