blob: ad16501716210697a9e01deaf1f67faeaeca505f [file] [log] [blame]
Dmitriy Ivanov0416d882014-11-04 09:38:18 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
Jiyong Park4945d8f2017-08-30 11:30:53 +090019#if defined(__BIONIC__)
20#include <android-base/properties.h>
21#endif
22
Dmitriy Ivanov0416d882014-11-04 09:38:18 -080023#include <dlfcn.h>
24#include <libgen.h>
25#include <limits.h>
26#include <stdio.h>
27#include <stdint.h>
Dmytro Chystiakov595c3812019-10-01 11:28:49 -070028#include <sys/stat.h>
Dmitriy Ivanov0416d882014-11-04 09:38:18 -080029
Jiyong Park02586a22017-05-20 01:01:24 +090030#include <fstream>
Elliott Hughesec580d32021-04-12 15:55:29 -070031#include <iostream>
32#include <regex>
33#include <string>
Dmitriy Ivanov0416d882014-11-04 09:38:18 -080034
Elliott Hugheseb04ed52017-03-29 13:48:02 -070035#include "gtest_globals.h"
Mark Salyzyn68a3bcc2018-11-13 07:35:21 -080036#include <android-base/file.h>
Dimitry Ivanov2a6955e2017-02-23 11:53:43 -080037#include "utils.h"
38
Dmitriy Ivanov0416d882014-11-04 09:38:18 -080039extern "C" int main_global_default_serial() {
40 return 3370318;
41}
42
43extern "C" int main_global_protected_serial() {
44 return 2716057;
45}
46
47// The following functions are defined in DT_NEEDED
48// libdl_preempt_test.so library.
49
50// This one calls main_global_default_serial
51extern "C" int main_global_default_get_serial();
52
53// This one calls main_global_protected_serial
54extern "C" int main_global_protected_get_serial();
55
56// This one calls lib_global_default_serial
57extern "C" int lib_global_default_get_serial();
58
59// This one calls lib_global_protected_serial
60extern "C" int lib_global_protected_get_serial();
61
62// This test verifies that the global default function
63// main_global_default_serial() is preempted by
64// the function defined above.
65TEST(dl, main_preempts_global_default) {
66 ASSERT_EQ(3370318, main_global_default_get_serial());
67}
68
69// This one makes sure that the global protected
70// symbols do not get preempted
71TEST(dl, main_does_not_preempt_global_protected) {
72 ASSERT_EQ(3370318, main_global_protected_get_serial());
73}
74
75// check same things for lib
76TEST(dl, lib_preempts_global_default) {
77 ASSERT_EQ(3370318, lib_global_default_get_serial());
78}
79
80TEST(dl, lib_does_not_preempt_global_protected) {
81 ASSERT_EQ(3370318, lib_global_protected_get_serial());
82}
83
Dimitry Ivanov2a6955e2017-02-23 11:53:43 -080084#if defined(__BIONIC__)
85#if defined(__LP64__)
86 static constexpr const char* kPathToLinker = "/system/bin/linker64";
87#else
88 static constexpr const char* kPathToLinker = "/system/bin/linker";
89#endif
Dmytro Chystiakov595c3812019-10-01 11:28:49 -070090
91#if defined (__aarch64__)
92 static constexpr const char* kAlternatePathToLinker = "/system/bin/arm64/linker64";
93#elif defined (__arm__)
94 static constexpr const char* kAlternatePathToLinker = "/system/bin/arm/linker";
95#elif defined (__x86_64__)
96 static constexpr const char* kAlternatePathToLinker = "/system/bin/x86_64/linker64";
97#elif defined (__i386__)
98 static constexpr const char* kAlternatePathToLinker = "/system/bin/x86/linker";
Dmytro Chystiakov595c3812019-10-01 11:28:49 -070099#else
100#error "Unknown architecture"
101#endif
102
103const char* PathToLinker() {
104 // On the systems with emulated architecture linker would be of different
105 // architecture. Try to use alternate paths first.
106 struct stat buffer;
107 if (stat(kAlternatePathToLinker, &buffer) == 0) {
108 return kAlternatePathToLinker;
109 }
110 return kPathToLinker;
111}
112#endif // defined(__BIONIC__)
Ryan Prichard8f639a42018-10-01 23:10:05 -0700113
114TEST(dl, exec_linker) {
115#if defined(__BIONIC__)
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700116 const char* path_to_linker = PathToLinker();
117 std::string usage_prefix = std::string("Usage: ") + path_to_linker;
Dimitry Ivanov2a6955e2017-02-23 11:53:43 -0800118 ExecTestHelper eth;
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700119 eth.SetArgs({ path_to_linker, nullptr });
120 eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
Ryan Prichard8f639a42018-10-01 23:10:05 -0700121 ASSERT_EQ(0u, eth.GetOutput().find(usage_prefix)) << "Test output:\n" << eth.GetOutput();
122#endif
123}
124
125TEST(dl, exec_linker_load_file) {
126#if defined(__BIONIC__)
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700127 const char* path_to_linker = PathToLinker();
Colin Crossbadcb382021-09-24 17:49:58 -0700128 std::string helper = GetTestlibRoot() + "/exec_linker_helper";
Ryan Prichard8f639a42018-10-01 23:10:05 -0700129 std::string expected_output =
130 "ctor: argc=1 argv[0]=" + helper + "\n" +
131 "main: argc=1 argv[0]=" + helper + "\n" +
Elliott Hughes75064c12020-01-22 20:46:12 -0800132 "__progname=exec_linker_helper\n" +
Ryan Prichard8f639a42018-10-01 23:10:05 -0700133 "helper_func called\n";
134 ExecTestHelper eth;
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700135 eth.SetArgs({ path_to_linker, helper.c_str(), nullptr });
136 eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
Dimitry Ivanov2a6955e2017-02-23 11:53:43 -0800137#endif
138}
139
Ryan Prichard8f639a42018-10-01 23:10:05 -0700140TEST(dl, exec_linker_load_from_zip) {
141#if defined(__BIONIC__)
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700142 const char* path_to_linker = PathToLinker();
Ryan Prichard8f639a42018-10-01 23:10:05 -0700143 std::string helper = GetTestlibRoot() +
144 "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip!/libdir/exec_linker_helper";
145 std::string expected_output =
146 "ctor: argc=1 argv[0]=" + helper + "\n" +
147 "main: argc=1 argv[0]=" + helper + "\n" +
Elliott Hughes75064c12020-01-22 20:46:12 -0800148 "__progname=exec_linker_helper\n" +
Ryan Prichard8f639a42018-10-01 23:10:05 -0700149 "helper_func called\n";
150 ExecTestHelper eth;
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700151 eth.SetArgs({ path_to_linker, helper.c_str(), nullptr });
152 eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
Ryan Prichard8f639a42018-10-01 23:10:05 -0700153#endif
154}
155
156TEST(dl, exec_linker_load_self) {
157#if defined(__BIONIC__)
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700158 const char* path_to_linker = PathToLinker();
Ryan Prichard8f639a42018-10-01 23:10:05 -0700159 std::string error_message = "error: linker cannot load itself\n";
160 ExecTestHelper eth;
Dmytro Chystiakov595c3812019-10-01 11:28:49 -0700161 eth.SetArgs({ path_to_linker, path_to_linker, nullptr });
162 eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, EXIT_FAILURE, error_message.c_str());
Ryan Prichard8f639a42018-10-01 23:10:05 -0700163#endif
164}
165
Elliott Hugheseb04ed52017-03-29 13:48:02 -0700166TEST(dl, preinit_system_calls) {
167#if defined(__BIONIC__)
Elliott Hughesbcaa4542019-03-08 15:20:23 -0800168 SKIP_WITH_HWASAN << "hwasan not initialized in preinit_array, b/124007027";
Colin Crossbadcb382021-09-24 17:49:58 -0700169 std::string helper = GetTestlibRoot() + "/preinit_syscall_test_helper";
Elliott Hugheseb04ed52017-03-29 13:48:02 -0700170 chmod(helper.c_str(), 0755); // TODO: "x" lost in CTS, b/34945607
171 ExecTestHelper eth;
172 eth.SetArgs({ helper.c_str(), nullptr });
173 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
174#endif
175}
176
Ryan Prichard5a664902018-11-22 02:14:14 -0800177TEST(dl, preinit_getauxval) {
Elliott Hugheseb04ed52017-03-29 13:48:02 -0700178#if defined(__BIONIC__)
Elliott Hughesbcaa4542019-03-08 15:20:23 -0800179 SKIP_WITH_HWASAN << "hwasan not initialized in preinit_array, b/124007027";
Colin Crossbadcb382021-09-24 17:49:58 -0700180 std::string helper = GetTestlibRoot() + "/preinit_getauxval_test_helper";
Elliott Hugheseb04ed52017-03-29 13:48:02 -0700181 chmod(helper.c_str(), 0755); // TODO: "x" lost in CTS, b/34945607
182 ExecTestHelper eth;
183 eth.SetArgs({ helper.c_str(), nullptr });
184 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
Christopher Ferris01db9bd2018-11-07 14:39:43 -0800185#else
186 // Force a failure when not compiled for bionic so the test is considered a pass.
187 ASSERT_TRUE(false);
Elliott Hugheseb04ed52017-03-29 13:48:02 -0700188#endif
189}
190
Jiyong Park02586a22017-05-20 01:01:24 +0900191
192TEST(dl, exec_without_ld_preload) {
193#if defined(__BIONIC__)
Colin Crossbadcb382021-09-24 17:49:58 -0700194 std::string helper = GetTestlibRoot() + "/ld_preload_test_helper";
Jiyong Park02586a22017-05-20 01:01:24 +0900195 chmod(helper.c_str(), 0755);
196 ExecTestHelper eth;
197 eth.SetArgs({ helper.c_str(), nullptr });
198 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, "12345");
199#endif
200}
201
202TEST(dl, exec_with_ld_preload) {
203#if defined(__BIONIC__)
Colin Crossbadcb382021-09-24 17:49:58 -0700204 std::string helper = GetTestlibRoot() + "/ld_preload_test_helper";
Christopher Ferris6d2c0bd2018-08-21 18:13:10 -0700205 std::string env = std::string("LD_PRELOAD=") + GetTestlibRoot() + "/ld_preload_test_helper_lib2.so";
Jiyong Park02586a22017-05-20 01:01:24 +0900206 chmod(helper.c_str(), 0755);
207 ExecTestHelper eth;
208 eth.SetArgs({ helper.c_str(), nullptr });
209 eth.SetEnv({ env.c_str(), nullptr });
210 // ld_preload_test_helper calls get_value_from_lib() and returns the value.
211 // The symbol is defined by two libs: ld_preload_test_helper_lib.so and
212 // ld_preloaded_lib.so. The former is DT_NEEDED and the latter is LD_PRELOADED
213 // via this execution. The main executable is linked to the LD_PRELOADED lib
214 // and the value given from the lib is returned.
215 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0, "54321");
216#endif
217}
218
219
220// ld_config_test_helper must fail because it is depending on a lib which is not
221// in the search path
222//
223// Call sequence is...
224// _helper -- (get_value_from_lib()) -->
225// _lib1.so -- (get_value_from_another_lib()) -->
226// _lib2.so (returns 12345)
227// The two libs are in ns2/ subdir.
228TEST(dl, exec_without_ld_config_file) {
229#if defined(__BIONIC__)
Colin Crossbadcb382021-09-24 17:49:58 -0700230 std::string error_message = "CANNOT LINK EXECUTABLE \"" + GetTestlibRoot() +
231 "/ld_config_test_helper\": library \"ld_config_test_helper_lib1.so\" "
232 "not found: needed by main executable\n";
233 std::string helper = GetTestlibRoot() + "/ld_config_test_helper";
Jiyong Park02586a22017-05-20 01:01:24 +0900234 chmod(helper.c_str(), 0755);
235 ExecTestHelper eth;
236 eth.SetArgs({ helper.c_str(), nullptr });
dimitry04f7a792017-09-29 11:52:17 +0200237 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, EXIT_FAILURE, error_message.c_str());
Jiyong Park02586a22017-05-20 01:01:24 +0900238#endif
239}
240
241#if defined(__BIONIC__)
dimitry1280cf52018-05-09 14:37:47 +0200242extern "C" void android_get_LD_LIBRARY_PATH(char*, size_t);
Ryan Prichard0044cd12018-04-03 20:03:12 -0700243static void create_ld_config_file(const char* config_file) {
dimitry1280cf52018-05-09 14:37:47 +0200244 char default_search_paths[PATH_MAX];
245 android_get_LD_LIBRARY_PATH(default_search_paths, sizeof(default_search_paths));
246
Ryan Prichard0044cd12018-04-03 20:03:12 -0700247 std::ofstream fout(config_file, std::ios::out);
Colin Crossbadcb382021-09-24 17:49:58 -0700248 fout << "dir.test = " << GetTestlibRoot() << "/" << std::endl
Jiyong Park02586a22017-05-20 01:01:24 +0900249 << "[test]" << std::endl
250 << "additional.namespaces = ns2" << std::endl
Christopher Ferris6d2c0bd2018-08-21 18:13:10 -0700251 << "namespace.default.search.paths = " << GetTestlibRoot() << std::endl
Jiyong Park02586a22017-05-20 01:01:24 +0900252 << "namespace.default.links = ns2" << std::endl
Colin Crossbadcb382021-09-24 17:49:58 -0700253 << "namespace.default.link.ns2.shared_libs = "
254 "libc.so:libm.so:libdl.so:ld_config_test_helper_lib1.so"
255 << std::endl
256 << "namespace.ns2.search.paths = " << default_search_paths << ":" << GetTestlibRoot()
257 << "/ns2" << std::endl;
Jiyong Park02586a22017-05-20 01:01:24 +0900258 fout.close();
259}
260#endif
261
Jiyong Park41704cd2017-09-19 09:48:07 +0900262#if defined(__BIONIC__)
Ryan Prichard546723b2021-06-04 17:27:39 -0700263// This test can't rely on ro.debuggable, because it might have been forced on
264// in a user build ("Force Debuggable"). In that configuration, ro.debuggable is
265// true, but Bionic's LD_CONFIG_FILE testing support is still disabled.
266static bool is_user_build() {
267 return android::base::GetProperty("ro.build.type", "user") == std::string("user");
Jiyong Park41704cd2017-09-19 09:48:07 +0900268}
269#endif
Jiyong Park02586a22017-05-20 01:01:24 +0900270
Ryan Prichard058eb8f2020-12-17 22:59:04 -0800271// lib1.so and lib2.so are now searchable by having another namespace 'ns2'
Jiyong Park02586a22017-05-20 01:01:24 +0900272// whose search paths include the 'ns2/' subdir.
Ryan Prichard058eb8f2020-12-17 22:59:04 -0800273//
274// lib1.so is linked with DF_1_GLOBAL, so both it and the executable are added
275// to every namespace.
276//
277// namespace configuration ('*' indicates primary ns)
278// - default: exe[*], lib1.so
279// - ns2: exe, lib1.so[*], lib2.so[*]
280//
Jiyong Park02586a22017-05-20 01:01:24 +0900281TEST(dl, exec_with_ld_config_file) {
282#if defined(__BIONIC__)
Elliott Hughesbcaa4542019-03-08 15:20:23 -0800283 SKIP_WITH_HWASAN << "libclang_rt.hwasan is not found with custom ld config";
Ryan Prichard546723b2021-06-04 17:27:39 -0700284 if (is_user_build()) {
Ryan Prichard55f9a242019-12-10 14:45:20 -0800285 GTEST_SKIP() << "LD_CONFIG_FILE is not supported on user build";
Jiyong Park41704cd2017-09-19 09:48:07 +0900286 }
Colin Crossbadcb382021-09-24 17:49:58 -0700287 std::string helper = GetTestlibRoot() + "/ld_config_test_helper";
Ryan Prichard0044cd12018-04-03 20:03:12 -0700288 TemporaryFile config_file;
Mark Salyzyn68a3bcc2018-11-13 07:35:21 -0800289 create_ld_config_file(config_file.path);
290 std::string env = std::string("LD_CONFIG_FILE=") + config_file.path;
Jiyong Park02586a22017-05-20 01:01:24 +0900291 chmod(helper.c_str(), 0755);
292 ExecTestHelper eth;
293 eth.SetArgs({ helper.c_str(), nullptr });
294 eth.SetEnv({ env.c_str(), nullptr });
Ryan Prichard058eb8f2020-12-17 22:59:04 -0800295 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0,
296 "foo lib1\n"
297 "lib1_call_funcs\n"
298 "foo lib1\n"
299 "bar lib2\n");
Jiyong Park02586a22017-05-20 01:01:24 +0900300#endif
301}
302
Ryan Prichard058eb8f2020-12-17 22:59:04 -0800303// lib3.so has same foo and bar symbols as lib2.so. lib3.so is LD_PRELOADed.
304// This test ensures that LD_PRELOADed libs are available to all namespaces.
305//
306// namespace configuration ('*' indicates primary ns)
307// - default: exe[*], lib3.so[*], lib1.so
308// - ns2: exe, lib3.so, lib1.so[*], lib2.so[*]
309//
310// Ensure that, in both namespaces, a call to foo calls the lib3.so symbol,
311// which then calls the lib1.so symbol using RTLD_NEXT. Ensure that RTLD_NEXT
312// finds nothing when called from lib1.so.
313//
314// For the bar symbol, lib3.so's primary namespace is the default namespace, but
315// lib2.so is not in the default namespace, so using RTLD_NEXT from lib3.so
316// doesn't find the symbol in lib2.so.
Jiyong Park02586a22017-05-20 01:01:24 +0900317TEST(dl, exec_with_ld_config_file_with_ld_preload) {
318#if defined(__BIONIC__)
Elliott Hughesbcaa4542019-03-08 15:20:23 -0800319 SKIP_WITH_HWASAN << "libclang_rt.hwasan is not found with custom ld config";
Ryan Prichard546723b2021-06-04 17:27:39 -0700320 if (is_user_build()) {
Ryan Prichard55f9a242019-12-10 14:45:20 -0800321 GTEST_SKIP() << "LD_CONFIG_FILE is not supported on user build";
Jiyong Park41704cd2017-09-19 09:48:07 +0900322 }
Colin Crossbadcb382021-09-24 17:49:58 -0700323 std::string helper = GetTestlibRoot() + "/ld_config_test_helper";
Ryan Prichard0044cd12018-04-03 20:03:12 -0700324 TemporaryFile config_file;
Mark Salyzyn68a3bcc2018-11-13 07:35:21 -0800325 create_ld_config_file(config_file.path);
326 std::string env = std::string("LD_CONFIG_FILE=") + config_file.path;
Christopher Ferris6d2c0bd2018-08-21 18:13:10 -0700327 std::string env2 = std::string("LD_PRELOAD=") + GetTestlibRoot() + "/ld_config_test_helper_lib3.so";
Jiyong Park02586a22017-05-20 01:01:24 +0900328 chmod(helper.c_str(), 0755);
329 ExecTestHelper eth;
330 eth.SetArgs({ helper.c_str(), nullptr });
331 eth.SetEnv({ env.c_str(), env2.c_str(), nullptr });
Ryan Prichard058eb8f2020-12-17 22:59:04 -0800332 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0,
333 "foo lib3\n"
334 "foo lib1\n"
335 "lib1_call_funcs\n"
336 "foo lib3\n"
337 "foo lib1\n"
338 "bar lib3\n"
339 "lib3_call_funcs\n"
340 "foo lib3\n"
341 "foo lib1\n"
342 "bar lib3\n");
Jiyong Park02586a22017-05-20 01:01:24 +0900343#endif
344}
345
Jiyong Park02586a22017-05-20 01:01:24 +0900346// ensures that LD_CONFIG_FILE env var does not work for production builds.
347// The test input is the same as exec_with_ld_config_file, but it must fail in
348// this case.
349TEST(dl, disable_ld_config_file) {
350#if defined(__BIONIC__)
351 if (getuid() == 0) {
352 // when executed from the shell (e.g. not as part of CTS), skip the test.
353 // This test is only for CTS.
Ryan Prichard55f9a242019-12-10 14:45:20 -0800354 GTEST_SKIP() << "test is not supported with root uid";
Jiyong Park02586a22017-05-20 01:01:24 +0900355 }
Ryan Prichard546723b2021-06-04 17:27:39 -0700356 if (!is_user_build()) {
357 GTEST_SKIP() << "test requires user build";
Jiyong Park4945d8f2017-08-30 11:30:53 +0900358 }
359
Colin Crossbadcb382021-09-24 17:49:58 -0700360 std::string error_message =
361 std::string("CANNOT LINK EXECUTABLE ") + "\"" + GetTestlibRoot() +
362 "/ld_config_test_helper\": " +
Ryan Prichard0f672142019-12-10 14:50:11 -0800363 "library \"ld_config_test_helper_lib1.so\" not found: needed by main executable\n";
Colin Crossbadcb382021-09-24 17:49:58 -0700364 std::string helper = GetTestlibRoot() + "/ld_config_test_helper";
Ryan Prichard0044cd12018-04-03 20:03:12 -0700365 TemporaryFile config_file;
Mark Salyzyn68a3bcc2018-11-13 07:35:21 -0800366 create_ld_config_file(config_file.path);
367 std::string env = std::string("LD_CONFIG_FILE=") + config_file.path;
Jiyong Park02586a22017-05-20 01:01:24 +0900368 chmod(helper.c_str(), 0755);
369 ExecTestHelper eth;
370 eth.SetArgs({ helper.c_str(), nullptr });
371 eth.SetEnv({ env.c_str(), nullptr });
Jiyong Park98283862017-11-28 13:37:03 +0900372 eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, EXIT_FAILURE, error_message.c_str());
Jiyong Park02586a22017-05-20 01:01:24 +0900373#endif
374}
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800375
376static void RelocationsTest(const char* lib, const char* expectation) {
377#if defined(__BIONIC__)
378 // Does readelf think the .so file looks right?
379 const std::string path = GetTestlibRoot() + "/" + lib;
380 ExecTestHelper eth;
381 eth.SetArgs({ "readelf", "-SW", path.c_str(), nullptr });
382 eth.Run([&]() { execvpe("readelf", eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
Elliott Hughesec580d32021-04-12 15:55:29 -0700383
384 ASSERT_TRUE(std::regex_search(eth.GetOutput(), std::regex(expectation))) << eth.GetOutput();
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800385
386 // Can we load it?
387 void* handle = dlopen(lib, RTLD_NOW);
388 ASSERT_TRUE(handle != nullptr) << dlerror();
389#else
390 UNUSED(lib);
391 UNUSED(expectation);
392 GTEST_SKIP() << "test is not supported on glibc";
393#endif
394}
395
396TEST(dl, relocations_RELR) {
Elliott Hughesec580d32021-04-12 15:55:29 -0700397 RelocationsTest("librelocations-RELR.so", "\\.relr\\.dyn * RELR");
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800398}
399
400TEST(dl, relocations_ANDROID_RELR) {
Elliott Hughesec580d32021-04-12 15:55:29 -0700401 RelocationsTest("librelocations-ANDROID_RELR.so", "\\.relr\\.dyn * ANDROID_RELR");
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800402}
403
404TEST(dl, relocations_ANDROID_REL) {
405 RelocationsTest("librelocations-ANDROID_REL.so",
406#if __LP64__
Elliott Hughesec580d32021-04-12 15:55:29 -0700407 "\\.rela\\.dyn * ANDROID_RELA"
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800408#else
Elliott Hughesec580d32021-04-12 15:55:29 -0700409 "\\.rel\\.dyn * ANDROID_REL"
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800410#endif
Elliott Hughesec580d32021-04-12 15:55:29 -0700411 );
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800412}
413
414TEST(dl, relocations_fat) {
415 RelocationsTest("librelocations-fat.so",
416#if __LP64__
Elliott Hughesec580d32021-04-12 15:55:29 -0700417 "\\.rela\\.dyn * RELA"
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800418#else
Elliott Hughesec580d32021-04-12 15:55:29 -0700419 "\\.rel\\.dyn * REL"
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800420#endif
Elliott Hughesec580d32021-04-12 15:55:29 -0700421 );
Elliott Hughes6dd1f582020-01-28 12:18:35 -0800422}