Merge "Fix dlext.ns_anonymous test for native bridge"
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