[Lldb-commits] [lldb] r242580 - Detect if necessary to build inferior with -pie for Android.

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


Author: chaoren
Date: Fri Jul 17 17:13:29 2015
New Revision: 242580

URL: http://llvm.org/viewvc/llvm-project?rev=242580&view=rev
Log:
Detect if necessary to build inferior with -pie for Android.

Summary:
- 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.

Reviewers: sivachandra, tberghammer, clayborg, danalbert

Subscribers: chaoren, tberghammer, danalbert, srhines, lldb-commits

Differential Revision: http://reviews.llvm.org/D11309

Modified:
    lldb/trunk/cmake/platforms/Android.cmake
    lldb/trunk/test/lldbtest.py
    lldb/trunk/test/make/Makefile.rules

Modified: lldb/trunk/cmake/platforms/Android.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/platforms/Android.cmake?rev=242580&r1=242579&r2=242580&view=diff
==============================================================================
--- lldb/trunk/cmake/platforms/Android.cmake (original)
+++ lldb/trunk/cmake/platforms/Android.cmake Fri Jul 17 17:13:29 2015
@@ -39,8 +39,8 @@ set( ANDROID True )
 set( __ANDROID_NDK__ True )
 
 # linking lldb-server statically for Android avoids the need to ship two
-# binaries (pie for API 21+ and non-pie for API 14-). It's possible to use
-# a non-pie shim on API 14-, but that requires lldb-server to dynamically export
+# binaries (pie for API 21+ and non-pie for API 16-). It's possible to use
+# a non-pie shim on API 16-, but that requires lldb-server to dynamically export
 # its symbols, which significantly increases the binary size. Static linking, on
 # the other hand, has little to no effect on the binary size.
 if ( NOT DEFINED LLVM_BUILD_STATIC )
@@ -110,8 +110,8 @@ endif()
 
 if ( NOT LLVM_BUILD_STATIC )
  # PIE is required for API 21+ so we enable it if we're not statically linking
- # unfortunately, it is not supported before API 14 so we need to do something else there
- # see http://llvm.org/pr23457
+ # unfortunately, it is not supported before API 16 so we need to do something
+ # else there see http://llvm.org/pr23457
  set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -pie -fPIE" )
 endif()
 

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=242580&r1=242579&r2=242580&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri Jul 17 17:13:29 2015
@@ -431,21 +431,30 @@ def run_adb_command(cmd, device_id):
     stdout, stderr = p.communicate()
     return p.returncode, stdout, stderr
 
+def target_is_android():
+    if not hasattr(target_is_android, 'result'):
+        triple = lldb.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 @@ def expectedFailureAndroid(bugnumber=Non
             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 skipIfTargetAndroid(api_levels=None)
         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):
@@ -1984,6 +1990,12 @@ class Base(unittest2.TestCase):
         if lldb.skip_build_and_cleanup:
             return
         module = builder_module()
+        if target_is_android():
+            if dictionary is None:
+                dictionary = {}
+            dictionary["OS"] = "Android"
+            if android_device_api() >= 16:
+                dictionary["PIE"] = 1
         if not module.buildDwarf(self, architecture, compiler, dictionary, clean):
             raise Exception("Don't know how to build binary with dwarf")
 

Modified: lldb/trunk/test/make/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/Makefile.rules?rev=242580&r1=242579&r2=242580&view=diff
==============================================================================
--- lldb/trunk/test/make/Makefile.rules (original)
+++ lldb/trunk/test/make/Makefile.rules Fri Jul 17 17:13:29 2015
@@ -251,7 +251,9 @@ endif
 # 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)), \





More information about the lldb-commits mailing list