Fix dlext.ns_anonymous test for native bridge

The executable flag might not be present for the executable segment
if the code is being handled by native bridge implementation. Old
heuristics for this case was to assume first segment is executable.
This doesn't stand any more. Instead, look for segment that contains
the function test is going to call.

Test: bionic-unit-tests --gtest_filter=dlext.ns_anonymous
Change-Id: I960bebba86e225d739b73f6d093e145fff17b4a8
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 7e772b8..0b4cacb 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -2014,10 +2014,15 @@
     // For some natively bridged environments this code might be missing
     // the executable flag. This is because the guest code is not supposed
     // to be executed directly and making it non-executable is more secure.
-    // If this is the case we assume that the first segment is the one that
-    // has this flag.
-    ASSERT_TRUE((maps_to_copy[0].perms & PROT_WRITE) == 0);
-    maps_to_copy[0].perms |= PROT_EXEC;
+    // In this case we assume the segment with the function is executable.
+    for (auto& rec : maps_to_copy) {
+      if (ns_get_dlopened_string_addr >= rec.addr_start &&
+          ns_get_dlopened_string_addr < rec.addr_end) {
+        ASSERT_TRUE((rec.perms & PROT_WRITE) == 0);
+        rec.perms |= PROT_EXEC;
+        break;
+      }
+    }
   }
 
   // copy