Merge "Fix test compile errors after LLVM rebase"
diff --git a/libc/include/elf.h b/libc/include/elf.h
index c36bc8d..4181006 100644
--- a/libc/include/elf.h
+++ b/libc/include/elf.h
@@ -184,6 +184,12 @@
#define PT_GNU_RELRO 0x6474e552
+#undef ELF_ST_TYPE
+#define ELF_ST_TYPE(x) ((x) & 0xf)
+#define ELF_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
+#define ELF32_ST_INFO(b,t) ELF_ST_INFO(b,t)
+#define ELF64_ST_INFO(b,t) ELF_ST_INFO(b,t)
+
#define STB_LOOS 10
#define STB_HIOS 12
#define STB_LOPROC 13
diff --git a/libdl/libdl.arm.map b/libdl/libdl.arm.map
index c0dcd5d..668f008 100644
--- a/libdl/libdl.arm.map
+++ b/libdl/libdl.arm.map
@@ -47,4 +47,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/libdl/libdl.arm64.map b/libdl/libdl.arm64.map
index 3b797f7..8270fe9 100644
--- a/libdl/libdl.arm64.map
+++ b/libdl/libdl.arm64.map
@@ -46,4 +46,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/libdl/libdl.c b/libdl/libdl.c
index f7ca3f1..1a65b67 100644
--- a/libdl/libdl.c
+++ b/libdl/libdl.c
@@ -94,6 +94,9 @@
__attribute__((__weak__, visibility("default")))
void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*));
+__attribute__((__weak__, visibility("default")))
+struct android_namespace_t* __loader_android_get_exported_namespace(const char* name);
+
// Proxy calls to bionic loader
void* dlopen(const char* filename, int flag) {
const void* caller_addr = __builtin_return_address(0);
@@ -187,3 +190,7 @@
void android_dlwarning(void* obj, void (*f)(void*, const char*)) {
__loader_android_dlwarning(obj, f);
}
+
+struct android_namespace_t* android_get_exported_namespace(const char* name) {
+ return __loader_android_get_exported_namespace(name);
+}
diff --git a/libdl/libdl.map.txt b/libdl/libdl.map.txt
index 245e016..a4c6483 100644
--- a/libdl/libdl.map.txt
+++ b/libdl/libdl.map.txt
@@ -46,4 +46,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/libdl/libdl.mips.map b/libdl/libdl.mips.map
index 3b797f7..8270fe9 100644
--- a/libdl/libdl.mips.map
+++ b/libdl/libdl.mips.map
@@ -46,4 +46,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/libdl/libdl.mips64.map b/libdl/libdl.mips64.map
index 3b797f7..8270fe9 100644
--- a/libdl/libdl.mips64.map
+++ b/libdl/libdl.mips64.map
@@ -46,4 +46,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/libdl/libdl.x86.map b/libdl/libdl.x86.map
index 3b797f7..8270fe9 100644
--- a/libdl/libdl.x86.map
+++ b/libdl/libdl.x86.map
@@ -46,4 +46,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/libdl/libdl.x86_64.map b/libdl/libdl.x86_64.map
index 3b797f7..8270fe9 100644
--- a/libdl/libdl.x86_64.map
+++ b/libdl/libdl.x86_64.map
@@ -46,4 +46,5 @@
android_init_anonymous_namespace;
android_create_namespace;
android_link_namespaces;
+ android_get_exported_namespace;
} LIBC_N;
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 0bc5a31..6195d40 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -214,6 +214,10 @@
return success;
}
+android_namespace_t* __android_get_exported_namespace(const char* name) {
+ return get_exported_namespace(name);
+}
+
void __cfi_fail(uint64_t CallSiteTypeId, void* Ptr, void *DiagData, void *CallerPc) {
CFIShadowWriter::CfiFail(CallSiteTypeId, Ptr, DiagData, CallerPc);
}
@@ -256,9 +260,13 @@
// 4*
// 0000000 000111111111122222222223333 333333444444444455 555555556666666666777777777788888 888889999999999
// 0123456 789012345678901234567890123 456789012345678901 234567890123456789012345678901234 567890123456789
- "dlvsym\0__loader_android_dlwarning\0__loader_cfi_fail\0__loader_android_link_namespaces\0"
+ "dlvsym\0__loader_android_dlwarning\0__loader_cfi_fail\0__loader_android_link_namespaces\0__loader_androi"
+ // 5*
+ // 0000000000111111111122222 22222
+ // 0123456789012345678901234 56789
+ "d_get_exported_namespace\0"
#if defined(__arm__)
- // 485
+ // 525
"__loader_dl_unwind_find_exidx\0"
#endif
;
@@ -286,8 +294,9 @@
ELFW(SYM_INITIALIZER)(407, &__android_dlwarning, 1),
ELFW(SYM_INITIALIZER)(434, &__cfi_fail, 1),
ELFW(SYM_INITIALIZER)(452, &__android_link_namespaces, 1),
+ ELFW(SYM_INITIALIZER)(485, &__android_get_exported_namespace, 1),
#if defined(__arm__)
- ELFW(SYM_INITIALIZER)(485, &__dl_unwind_find_exidx, 1),
+ ELFW(SYM_INITIALIZER)(525, &__dl_unwind_find_exidx, 1),
#endif
};
@@ -304,9 +313,9 @@
// Note that adding any new symbols here requires stubbing them out in libdl.
static unsigned g_libdl_buckets[1] = { 1 };
#if defined(__arm__)
-static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0 };
#else
-static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0 };
#endif
static uint8_t __libdl_info_buf[sizeof(soinfo)] __attribute__((aligned(8)));
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 11a00f7..afd990a 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -73,6 +73,7 @@
#define ELF_ST_TYPE(x) (static_cast<uint32_t>(x) & 0xf)
static android_namespace_t* g_anonymous_namespace = &g_default_namespace;
+static std::unordered_map<std::string, android_namespace_t*> g_exported_namespaces;
static LinkerTypeAllocator<soinfo> g_soinfo_allocator;
static LinkerTypeAllocator<LinkedListEntry<soinfo>> g_soinfo_links_allocator;
@@ -3470,6 +3471,9 @@
ns->set_permitted_paths(ns_config->permitted_paths());
namespaces[ns_config->name()] = ns;
+ if (ns_config->visible()) {
+ g_exported_namespaces[ns_config->name()] = ns;
+ }
}
// 3. Establish links between namespaces
@@ -3494,3 +3498,16 @@
set_application_target_sdk_version(config->target_sdk_version());
}
+
+// This function finds a namespace exported in ld.config.txt by its name.
+// A namespace can be exported by setting .visible property to true.
+android_namespace_t* get_exported_namespace(const char* name) {
+ if (name == nullptr) {
+ return nullptr;
+ }
+ auto it = g_exported_namespaces.find(std::string(name));
+ if (it == g_exported_namespaces.end()) {
+ return nullptr;
+ }
+ return it->second;
+}
diff --git a/linker/linker.h b/linker/linker.h
index d5d4980..53dac6c 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -173,4 +173,6 @@
android_namespace_t* namespace_to,
const char* shared_lib_sonames);
+android_namespace_t* get_exported_namespace(const char* name);
+
#endif
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index a12cfbe..f614ba0 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -456,6 +456,7 @@
}
ns_config->set_isolated(properties.get_bool(property_name_prefix + ".isolated"));
+ ns_config->set_visible(properties.get_bool(property_name_prefix + ".visible"));
// these are affected by is_asan flag
if (is_asan) {
diff --git a/linker/linker_config.h b/linker/linker_config.h
index 4ec8b26..6f8bffb 100644
--- a/linker/linker_config.h
+++ b/linker/linker_config.h
@@ -62,7 +62,7 @@
class NamespaceConfig {
public:
explicit NamespaceConfig(const std::string& name)
- : name_(name), isolated_(false)
+ : name_(name), isolated_(false), visible_(false)
{}
const char* name() const {
@@ -73,6 +73,10 @@
return isolated_;
}
+ bool visible() const {
+ return visible_;
+ }
+
const std::vector<std::string>& search_paths() const {
return search_paths_;
}
@@ -93,6 +97,10 @@
isolated_ = isolated;
}
+ void set_visible(bool visible) {
+ visible_ = visible;
+ }
+
void set_search_paths(std::vector<std::string>&& search_paths) {
search_paths_ = search_paths;
}
@@ -103,6 +111,7 @@
private:
const std::string name_;
bool isolated_;
+ bool visible_;
std::vector<std::string> search_paths_;
std::vector<std::string> permitted_paths_;
std::vector<NamespaceLinkConfig> namespace_links_;
diff --git a/linker/tests/linker_config_test.cpp b/linker/tests/linker_config_test.cpp
index 418cbda..5e51113 100644
--- a/linker/tests/linker_config_test.cpp
+++ b/linker/tests/linker_config_test.cpp
@@ -58,6 +58,7 @@
"namespace.default.links = system\n"
"namespace.default.link.system.shared_libs = libc.so:libm.so:libdl.so:libstdc++.so\n"
"namespace.system.isolated = true\n"
+ "namespace.system.visible = true\n"
"namespace.system.search.paths = /system/${LIB}\n"
"namespace.system.permitted.paths = /system/${LIB}\n"
"namespace.system.asan.search.paths = /data:/system/${LIB}\n"
@@ -137,6 +138,7 @@
ASSERT_TRUE(default_ns_config != nullptr);
ASSERT_TRUE(default_ns_config->isolated());
+ ASSERT_FALSE(default_ns_config->visible());
ASSERT_EQ(kExpectedDefaultSearchPath, default_ns_config->search_paths());
ASSERT_EQ(kExpectedDefaultPermittedPath, default_ns_config->permitted_paths());
@@ -163,6 +165,7 @@
ASSERT_TRUE(ns_system != nullptr) << "system namespace was not found";
ASSERT_TRUE(ns_system->isolated());
+ ASSERT_TRUE(ns_system->visible());
ASSERT_EQ(kExpectedSystemSearchPath, ns_system->search_paths());
ASSERT_EQ(kExpectedSystemPermittedPath, ns_system->permitted_paths());
}
diff --git a/tests/Android.bp b/tests/Android.bp
index 27cc954..d4e3800 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -58,6 +58,7 @@
"complex_test.cpp",
"ctype_test.cpp",
"dirent_test.cpp",
+ "elf_test.cpp",
"endian_test.cpp",
"error_test.cpp",
"eventfd_test.cpp",
diff --git a/tests/elf_test.cpp b/tests/elf_test.cpp
new file mode 100644
index 0000000..ad7cdfa
--- /dev/null
+++ b/tests/elf_test.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include <elf.h>
+
+#include <gtest/gtest.h>
+
+// https://github.com/android-ndk/ndk/issues/377
+TEST(elf, have_ELF_ST_INFO_macros) {
+ uint8_t info;
+
+ // 0x0f
+ info = ELF32_ST_INFO(STB_LOCAL, STT_HIPROC);
+ ASSERT_EQ(STB_LOCAL, ELF32_ST_BIND(info));
+ ASSERT_EQ(STT_HIPROC, ELF32_ST_TYPE(info));
+
+ // 0x0f
+ info = ELF64_ST_INFO(STB_LOCAL, STT_HIPROC);
+ ASSERT_EQ(STB_LOCAL, ELF64_ST_BIND(info));
+ ASSERT_EQ(STT_HIPROC, ELF64_ST_TYPE(info));
+
+ // 0xf0
+ info = ELF32_ST_INFO(STB_LOCAL, STT_HIPROC);
+ ASSERT_EQ(STB_LOCAL, ELF32_ST_BIND(info));
+ ASSERT_EQ(STT_HIPROC, ELF32_ST_TYPE(info));
+
+ // 0xf0
+ info = ELF64_ST_INFO(STB_LOCAL, STT_HIPROC);
+ ASSERT_EQ(STB_LOCAL, ELF64_ST_BIND(info));
+ ASSERT_EQ(STT_HIPROC, ELF64_ST_TYPE(info));
+}
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index 2835f1d..984a657 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -219,7 +219,6 @@
#endif // __BIONIC__
}
-// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strlcpy_fortified2) {
#if defined(__BIONIC__)
foo myfoo;
@@ -231,7 +230,6 @@
#endif // __BIONIC__
}
-// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strlcat_fortified2) {
#if defined(__BIONIC__)
foo myfoo;
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 87b4c81..fbf14c1 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1963,8 +1963,8 @@
} else {
ASSERT_EQ(0, result);
}
- arg->data->finished_mask |= (1 << arg->id);
- if (arg->data->finished_mask == ((1 << arg->data->thread_count) - 1)) {
+ int mask = arg->data->finished_mask.fetch_or(1 << arg->id);
+ if (mask == ((1 << arg->data->thread_count) - 1)) {
ASSERT_EQ(1, arg->data->serial_thread_count);
arg->data->finished_iteration_count++;
arg->data->finished_mask = 0;
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
index 59d41da..688de5b 100644
--- a/tools/versioner/src/versioner.cpp
+++ b/tools/versioner/src/versioner.cpp
@@ -445,6 +445,12 @@
}
}
+// versioner uses a prebuilt version of clang, which is not up-to-date wrt/
+// container annotations. So disable container overflow checking. b/37775238
+extern "C" const char* __asan_default_options() {
+ return "detect_container_overflow=0";
+}
+
int main(int argc, char** argv) {
std::string cwd = getWorkingDir() + "/";
bool default_args = true;