Merge "Test all four supported relocation encodings."
diff --git a/tests/Android.bp b/tests/Android.bp
index 2bfe42b..c254839 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -613,8 +613,10 @@
         "libdl_preempt_test_2",
         "libdl_test_df_1_global",
         "libgnu-hash-table-library",
-        "librelr-new",
-        "librelr-old",
+        "librelocations-ANDROID_RELR",
+        "librelocations-ANDROID_REL",
+        "librelocations-RELR",
+        "librelocations-fat",
         "libsysv-hash-table-library",
         "libtestshared",
         "libtest_atexit",
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp
index 2b963c7..ed60e8e 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -347,3 +347,52 @@
   eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, EXIT_FAILURE, error_message.c_str());
 #endif
 }
+
+static void RelocationsTest(const char* lib, const char* expectation) {
+#if defined(__BIONIC__)
+  // Does readelf think the .so file looks right?
+  const std::string path = GetTestlibRoot() + "/" + lib;
+  ExecTestHelper eth;
+  eth.SetArgs({ "readelf", "-SW", path.c_str(), nullptr });
+  eth.Run([&]() { execvpe("readelf", eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
+  ASSERT_TRUE(eth.GetOutput().find(expectation) != std::string::npos) << eth.GetOutput();
+
+  // Can we load it?
+  void* handle = dlopen(lib, RTLD_NOW);
+  ASSERT_TRUE(handle != nullptr) << dlerror();
+#else
+  UNUSED(lib);
+  UNUSED(expectation);
+  GTEST_SKIP() << "test is not supported on glibc";
+#endif
+}
+
+TEST(dl, relocations_RELR) {
+  RelocationsTest("librelocations-RELR.so",
+      ".relr.dyn            RELR");
+}
+
+TEST(dl, relocations_ANDROID_RELR) {
+  RelocationsTest("librelocations-ANDROID_RELR.so",
+      ".relr.dyn            ANDROID_RELR");
+}
+
+TEST(dl, relocations_ANDROID_REL) {
+  RelocationsTest("librelocations-ANDROID_REL.so",
+#if __LP64__
+      ".rela.dyn            ANDROID_RELA"
+#else
+      ".rel.dyn             ANDROID_REL"
+#endif
+      );
+}
+
+TEST(dl, relocations_fat) {
+  RelocationsTest("librelocations-fat.so",
+#if __LP64__
+      ".rela.dyn            RELA"
+#else
+      ".rel.dyn             REL"
+#endif
+      );
+}
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index e36883a..d815dba 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -1765,13 +1765,3 @@
 }
 
 #endif
-
-TEST(dlfcn, relr_old) {
-  void* handle = dlopen("librelr-old.so", RTLD_NOW);
-  ASSERT_TRUE(handle != nullptr) << dlerror();
-}
-
-TEST(dlfcn, relr_new) {
-  void* handle = dlopen("librelr-new.so", RTLD_NOW);
-  ASSERT_TRUE(handle != nullptr) << dlerror();
-}
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 29224f5..9be85c8 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -1500,15 +1500,21 @@
 
 
 // -----------------------------------------------------------------------------
-// Check that we support both the old and new SHT_RELR constants.
+// Check that we support all kinds of relocations: regular, "relocation packer",
+// and both the old and new SHT_RELR constants.
 // -----------------------------------------------------------------------------
 
+// This is what got standardized for SHT_RELR.
 cc_test_library {
-    name: "librelr-new",
-    ldflags: ["-Wl,--no-use-android-relr-tags"],
+    name: "librelocations-RELR",
+    ldflags: [
+        "-Wl,--pack-dyn-relocs=relr",
+        "-Wl,--no-use-android-relr-tags",
+    ],
     host_supported: false,
     defaults: ["bionic_testlib_defaults"],
-    srcs: ["relr.cpp"],
+    srcs: ["relocations.cpp"],
+
     // Hack to ensure we're using llvm-objcopy because our binutils prebuilt
     // only supports the old numbers (http://b/141010852).
     strip: {
@@ -1516,10 +1522,32 @@
     },
 }
 
+// This is the same encoding as SHT_RELR, but using OS-specific constants.
 cc_test_library {
-    name: "librelr-old",
-    ldflags: ["-Wl,--use-android-relr-tags"],
+    name: "librelocations-ANDROID_RELR",
+    ldflags: [
+        "-Wl,--pack-dyn-relocs=relr",
+        "-Wl,--use-android-relr-tags",
+    ],
     host_supported: false,
     defaults: ["bionic_testlib_defaults"],
-    srcs: ["relr.cpp"],
+    srcs: ["relocations.cpp"],
+}
+
+// This is the old relocation packer encoding (DT_ANDROID_REL/DT_ANDROID_RELA).
+cc_test_library {
+    name: "librelocations-ANDROID_REL",
+    ldflags: ["-Wl,--pack-dyn-relocs=android"],
+    host_supported: false,
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["relocations.cpp"],
+}
+
+// This is not packed at all.
+cc_test_library {
+    name: "librelocations-fat",
+    ldflags: ["-Wl,--pack-dyn-relocs=none"],
+    host_supported: false,
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["relocations.cpp"],
 }
diff --git a/tests/libs/relr.cpp b/tests/libs/relocations.cpp
similarity index 95%
rename from tests/libs/relr.cpp
rename to tests/libs/relocations.cpp
index 7ea07b5..3c9d604 100644
--- a/tests/libs/relr.cpp
+++ b/tests/libs/relocations.cpp
@@ -26,6 +26,6 @@
  * SUCH DAMAGE.
  */
 
-extern "C" const char* relr() {
-  return "relr";
+extern "C" const char* function() {
+  return "relocations";
 }