Merge "Test all four supported relocation encodings."
This commit is contained in:
commit
35a09a3493
5 changed files with 90 additions and 21 deletions
|
@ -613,8 +613,10 @@ cc_defaults {
|
|||
"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",
|
||||
|
|
|
@ -347,3 +347,52 @@ TEST(dl, disable_ld_config_file) {
|
|||
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
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1765,13 +1765,3 @@ TEST(dlfcn, segment_gap) {
|
|||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
|
|
|
@ -1500,15 +1500,21 @@ cc_test_library {
|
|||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// 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 @@ cc_test_library {
|
|||
},
|
||||
}
|
||||
|
||||
// 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"],
|
||||
}
|
||||
|
|
|
@ -26,6 +26,6 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
extern "C" const char* relr() {
|
||||
return "relr";
|
||||
extern "C" const char* function() {
|
||||
return "relocations";
|
||||
}
|
Loading…
Reference in a new issue