libdl: platform headers

Defining headers provides the most type safety.

Previously, libdl exposed APIs via extern. However, this is
errorprone. We have much better tools in the Android build
to guard API usage. Specifically, apps, mainline modules,
vendor code, and other unbundled code paths would avoid
using these headers.

Moving function to header as requested by NDK API Council
for new methods.

Future steps that would make sense would be cleaning up
dlext_private_tests and combining it here, and also
removing other 'extern' uses of libdl symbols.

Bug: 382285049
Test: links

Change-Id: I23eb1d8a2c3a81e4f2892a726c46be89f2c992fa
diff --git a/tests/dlext_private.h b/tests/dlext_private_tests.h
similarity index 100%
rename from tests/dlext_private.h
rename to tests/dlext_private_tests.h
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 8b26cb0..b8826c1 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -44,7 +44,7 @@
 #include "bionic/mte.h"
 #include "bionic/page.h"
 #include "core_shared_libs.h"
-#include "dlext_private.h"
+#include "dlext_private_tests.h"
 #include "dlfcn_symlink_support.h"
 #include "gtest_globals.h"
 #include "utils.h"
diff --git a/tests/libs/ns_hidden_child_helper.cpp b/tests/libs/ns_hidden_child_helper.cpp
index c2140f1..77608e2 100644
--- a/tests/libs/ns_hidden_child_helper.cpp
+++ b/tests/libs/ns_hidden_child_helper.cpp
@@ -33,7 +33,7 @@
 #include <string>
 
 #include "../core_shared_libs.h"
-#include "../dlext_private.h"
+#include "../dlext_private_tests.h"
 
 extern "C" void global_function();
 extern "C" void internal_function();
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 3f1ba79..2ce789e 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -53,7 +53,7 @@
 #if defined(__BIONIC__)
 
 #include "SignalUtils.h"
-#include "dlext_private.h"
+#include "dlext_private_tests.h"
 
 #include "platform/bionic/malloc.h"
 #include "platform/bionic/mte.h"
diff --git a/tests/page_size_16kib_compat_test.cpp b/tests/page_size_16kib_compat_test.cpp
index a5d91b8..cfd52e2 100644
--- a/tests/page_size_16kib_compat_test.cpp
+++ b/tests/page_size_16kib_compat_test.cpp
@@ -26,11 +26,17 @@
  * SUCH DAMAGE.
  */
 
+#if __has_include (<android/dlext_private.h>)
+#define IS_ANDROID_DL
+#endif
+
 #include "page_size_compat_helpers.h"
 
 #include <android-base/properties.h>
 
-extern "C" void android_set_16kb_appcompat_mode(bool enable_app_compat);
+#if defined(IS_ANDROID_DL)
+#include <android/dlext_private.h>
+#endif
 
 TEST(PageSize16KiBCompatTest, ElfAlignment4KiB_LoadElf) {
   if (getpagesize() != 0x4000) {
@@ -52,11 +58,17 @@
     GTEST_SKIP() << "This test is only applicable to 16kB page-size devices";
   }
 
+#if defined(IS_ANDROID_DL)
   android_set_16kb_appcompat_mode(true);
+#endif
+
   std::string lib = GetTestLibRoot() + "/libtest_elf_max_page_size_4kib.so";
   void* handle = nullptr;
 
   OpenTestLibrary(lib, false /*should_fail*/, &handle);
   CallTestFunction(handle);
+
+#if defined(IS_ANDROID_DL)
   android_set_16kb_appcompat_mode(false);
+#endif
 }