Merge "Fix weak function lookups"
This commit is contained in:
commit
64dfbd242c
|
@ -118,7 +118,7 @@ void* dlsym(void* handle, const char* symbol) {
|
||||||
if (sym != NULL) {
|
if (sym != NULL) {
|
||||||
unsigned bind = ELF_ST_BIND(sym->st_info);
|
unsigned bind = ELF_ST_BIND(sym->st_info);
|
||||||
|
|
||||||
if (bind == STB_GLOBAL && sym->st_shndx != 0) {
|
if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
|
||||||
return reinterpret_cast<void*>(sym->st_value + found->load_bias);
|
return reinterpret_cast<void*>(sym->st_value + found->load_bias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,18 @@ TEST(dlfcn, rtld_next_known_symbol) {
|
||||||
ASSERT_TRUE(addr != NULL);
|
ASSERT_TRUE(addr != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(dlfcn, dlsym_weak_func) {
|
||||||
|
dlerror();
|
||||||
|
void* handle = dlopen("libtest_dlsym_weak_func.so",RTLD_NOW);
|
||||||
|
ASSERT_TRUE(handle != NULL);
|
||||||
|
|
||||||
|
int (*weak_func)();
|
||||||
|
weak_func = reinterpret_cast<int (*)()>(dlsym(handle, "weak_func"));
|
||||||
|
ASSERT_TRUE(weak_func != NULL) << "dlerror: " << dlerror();
|
||||||
|
EXPECT_EQ(42, weak_func());
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(dlfcn, dlopen_symlink) {
|
TEST(dlfcn, dlopen_symlink) {
|
||||||
void* handle1 = dlopen("libdlext_test.so", RTLD_NOW);
|
void* handle1 = dlopen("libdlext_test.so", RTLD_NOW);
|
||||||
void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW);
|
void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW);
|
||||||
|
|
|
@ -103,3 +103,15 @@ include $(TEST_PATH)/Android.build.mk
|
||||||
build_type := host
|
build_type := host
|
||||||
include $(TEST_PATH)/Android.build.mk
|
include $(TEST_PATH)/Android.build.mk
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Library with weak function
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
libtest_dlsym_weak_func_src_files := \
|
||||||
|
dlsym_weak_function.cpp
|
||||||
|
|
||||||
|
module := libtest_dlsym_weak_func
|
||||||
|
build_target := SHARED_LIBRARY
|
||||||
|
build_type := target
|
||||||
|
include $(TEST_PATH)/Android.build.mk
|
||||||
|
build_type := host
|
||||||
|
include $(TEST_PATH)/Android.build.mk
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C" int __attribute__((weak)) weak_func() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue