Remove dependency on zipalign.
Roll our own version of zipalign so that we can break the dependency
on the build tools zipalign. This breaks the transitive dependency
on androidfw so that building bionic unit tests in brillo works again.
Also modify the DlExtTest.ExtInfoUseFdWithOffset test so it dynamically
gets the offset of the shared library inside of the zip instead of
hard-coding the value.
Bug: 25446938
Change-Id: Idfb5d3089960a94eefa2c76e03da1ad2f4d7fb2f
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 261aa55..00eea58 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -30,6 +30,7 @@
#include <sys/wait.h>
#include <pagemap/pagemap.h>
+#include <ziparchive/zip_archive.h>
#include "TemporaryFile.h"
#include "utils.h"
@@ -61,8 +62,7 @@
#define LIBPATH NATIVE_TESTS_PATH "/libdlext_test_fd/libdlext_test_fd.so"
#define LIBZIPPATH NATIVE_TESTS_PATH "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip"
#define LIBZIPPATH_WITH_RUNPATH NATIVE_TESTS_PATH "/libdlext_test_runpath_zip/libdlext_test_runpath_zip_zipaligned.zip"
-
-#define LIBZIP_OFFSET PAGE_SIZE
+#define LIBZIP_SIMPLE_ZIP "libdir/libatest_simple_zip.so"
class DlExtTest : public ::testing::Test {
protected:
@@ -128,7 +128,17 @@
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD | ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
extinfo.library_fd = TEMP_FAILURE_RETRY(open(lib_path.c_str(), O_RDONLY | O_CLOEXEC));
- extinfo.library_fd_offset = LIBZIP_OFFSET;
+
+ // Find the offset of the shared library in the zip.
+ ZipArchiveHandle handle;
+ ASSERT_EQ(0, OpenArchive(lib_path.c_str(), &handle));
+ ZipEntry zip_entry;
+ ZipString zip_name;
+ zip_name.name = reinterpret_cast<const uint8_t*>(LIBZIP_SIMPLE_ZIP);
+ zip_name.name_length = sizeof(LIBZIP_SIMPLE_ZIP) - 1;
+ ASSERT_EQ(0, FindEntry(handle, zip_name, &zip_entry));
+ extinfo.library_fd_offset = zip_entry.offset;
+ CloseArchive(handle);
handle_ = android_dlopen_ext(lib_path.c_str(), RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
@@ -178,10 +188,11 @@
close(extinfo.library_fd);
}
-TEST_F(DlExtTest, ExtInfoUseOffsetWihtoutFd) {
+TEST_F(DlExtTest, ExtInfoUseOffsetWithoutFd) {
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
- extinfo.library_fd_offset = LIBZIP_OFFSET;
+ // This offset will not be used, so it doesn't matter.
+ extinfo.library_fd_offset = 0;
handle_ = android_dlopen_ext("/some/lib/that/does_not_exist", RTLD_NOW, &extinfo);
ASSERT_TRUE(handle_ == nullptr);