linker: Make text relocations denial optional

 * Use the TARGET_NEEDS_TEXT_RELOCATIONS := true
    configuration to allow a device to use
    legacy proprietary libraries like camera

 * Partial revert "Remove textrels support for platform libs"
    commit 8068786ae67835291521e52f39c695e40f3ad20d.

Change-Id: I994ab1a600a0b237b496ceebe2dd54febc28a6bd
diff --git a/linker/linker.cpp b/linker/linker.cpp
index eb7692f..ae3dbef 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -4015,7 +4015,12 @@
   if (has_text_relocations) {
     // Fail if app is targeting sdk version > 22
 #if !defined(__i386__) // ffmpeg says that they require text relocations on x86
+#if defined(TARGET_NEEDS_TEXT_RELOCATIONS)
+    if (get_application_target_sdk_version() != __ANDROID_API__
+        && get_application_target_sdk_version() > 22) {
+#else
     if (get_application_target_sdk_version() > 22) {
+#endif
       PRINT("%s: has text relocations", get_realpath());
       DL_ERR("%s: has text relocations", get_realpath());
       return false;
@@ -4023,7 +4028,13 @@
 #endif
     // Make segments writable to allow text relocations to work properly. We will later call
     // phdr_table_protect_segments() after all of them are applied.
+#if defined(TARGET_NEEDS_TEXT_RELOCATIONS)
+    // Silence the warning for targets that need
+    // text relocations since it can't really be helped
+    DEBUG("%s has text relocations. This is wasting memory and prevents "
+#else
     DL_WARN("%s has text relocations. This is wasting memory and prevents "
+#endif
             "security hardening. Please fix.", get_realpath());
     add_dlwarning(get_realpath(), "text relocations");
     if (phdr_table_unprotect_segments(phdr, phnum, load_bias) < 0) {