Merge "fix half-deleted comments in tests"
diff --git a/libc/Android.bp b/libc/Android.bp
index e8175f4..590fd28 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2076,7 +2076,7 @@
}
ndk_headers {
- name: "libc_android",
+ name: "libc_kernel_android_uapi_linux",
from: "kernel/android/uapi/linux",
to: "linux",
srcs: ["kernel/android/uapi/linux/**/*.h"],
@@ -2084,6 +2084,14 @@
}
ndk_headers {
+ name: "libc_kernel_android_scsi",
+ from: "kernel/android/scsi",
+ to: "scsi",
+ srcs: ["kernel/android/scsi/**/*.h"],
+ license: "NOTICE",
+}
+
+ndk_headers {
name: "libc_asm_arm",
from: "kernel/uapi/asm-arm",
to: "arm-linux-androideabi",
diff --git a/libc/bionic/__libc_current_sigrtmax.cpp b/libc/bionic/__libc_current_sigrtmax.cpp
index 27fcb35..32179bb 100644
--- a/libc/bionic/__libc_current_sigrtmax.cpp
+++ b/libc/bionic/__libc_current_sigrtmax.cpp
@@ -29,5 +29,7 @@
#include <signal.h>
int __libc_current_sigrtmax(void) {
+ // If you change this, also change __ndk_legacy___libc_current_sigrtmax
+ // in <android/legacy_signal_inlines.h> to match.
return __SIGRTMAX;
}
diff --git a/libc/bionic/__libc_current_sigrtmin.cpp b/libc/bionic/__libc_current_sigrtmin.cpp
index 7c93267..f3b2bf6 100644
--- a/libc/bionic/__libc_current_sigrtmin.cpp
+++ b/libc/bionic/__libc_current_sigrtmin.cpp
@@ -34,5 +34,7 @@
// __SIGRTMIN + 3 is reserved for triggering native stack dumps.
int __libc_current_sigrtmin(void) {
+ // If you change this, also change __ndk_legacy___libc_current_sigrtmin
+ // in <android/legacy_signal_inlines.h> to match.
return __SIGRTMIN + 4;
}
diff --git a/libc/include/android/legacy_signal_inlines.h b/libc/include/android/legacy_signal_inlines.h
index afdaca8..a5d3a6f 100644
--- a/libc/include/android/legacy_signal_inlines.h
+++ b/libc/include/android/legacy_signal_inlines.h
@@ -41,6 +41,25 @@
#if __ANDROID_API__ < __ANDROID_API_L__
+/* These weren't introduced until L. */
+int __libc_current_sigrtmax() __attribute__((__weak__)) __VERSIONER_NO_GUARD;
+int __libc_current_sigrtmin() __attribute__((__weak__)) __VERSIONER_NO_GUARD;
+
+static __inline int __ndk_legacy___libc_current_sigrtmax() {
+ if (__libc_current_sigrtmax) return __libc_current_sigrtmax();
+ return __SIGRTMAX; /* Should match __libc_current_sigrtmax. */
+}
+
+static __inline int __ndk_legacy___libc_current_sigrtmin() {
+ if (__libc_current_sigrtmin) return __libc_current_sigrtmin();
+ return __SIGRTMIN + 4; /* Should match __libc_current_sigrtmin. */
+}
+
+#undef SIGRTMAX
+#define SIGRTMAX __ndk_legacy___libc_current_sigrtmax()
+#undef SIGRTMIN
+#define SIGRTMIN __ndk_legacy___libc_current_sigrtmin()
+
static __inline int sigismember(const sigset_t *set, int signum) {
/* Signal numbers start at 1, but bit positions start at 0. */
int bit = signum - 1;
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/libc/include/malloc.h b/libc/include/malloc.h
index 752ee72..412e3f0 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -23,13 +23,9 @@
__BEGIN_DECLS
-#if defined(__clang__)
-/* clang should support alloc_size in the nearish future. */
-#if __has_attribute(alloc_size)
-#error "We should enable alloc_size for clang."
-#else
+// Remove the workaround once b/37423073 is fixed.
+#if defined(__clang__) && !__has_attribute(alloc_size)
#define __BIONIC_ALLOC_SIZE(...)
-#endif
#else
#define __BIONIC_ALLOC_SIZE(...) __attribute__((__alloc_size__(__VA_ARGS__)))
#endif
diff --git a/libdl/libdl.c b/libdl/libdl.c
index 6a95629..f7ca3f1 100644
--- a/libdl/libdl.c
+++ b/libdl/libdl.c
@@ -128,6 +128,11 @@
}
#endif
+/*
+ * This needs to be defined as weak because it is also defined in libc.a.
+ * Without this, static executables will have a multiple definition error.
+ */
+__attribute__((__weak__))
int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
return __loader_dl_iterate_phdr(cb, data);
}
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/dlext_test.cpp b/tests/dlext_test.cpp
index 35dff2a..45a8b8b 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <android/dlext.h>
+#include <android-base/strings.h>
#include <linux/memfd.h>
#include <sys/mman.h>
@@ -464,7 +465,8 @@
EXPECT_EQ(1729U, *taxicab_number);
}
- void SpawnChildrenAndMeasurePss(const char* lib, bool share_relro, size_t* pss_out);
+ void SpawnChildrenAndMeasurePss(const char* lib, const char* relro_file, bool share_relro,
+ size_t* pss_out);
android_dlextinfo extinfo_;
};
@@ -510,19 +512,23 @@
ASSERT_NOERROR(pipe(pipefd));
size_t without_sharing, with_sharing;
- ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(kLibName, false, &without_sharing));
- ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(kLibName, true, &with_sharing));
+ ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(kLibName, tf.filename, false, &without_sharing));
+ ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(kLibName, tf.filename, true, &with_sharing));
+ ASSERT_LT(with_sharing, without_sharing);
- // We expect the sharing to save at least 10% of the total PSS. In practice
- // it saves 40%+ for this test.
- size_t expected_size = without_sharing - (without_sharing/10);
- EXPECT_LT(with_sharing, expected_size);
+ // We expect the sharing to save at least 50% of the library's total PSS.
+ // In practice it saves 80%+ for this library in the test.
+ size_t pss_saved = without_sharing - with_sharing;
+ size_t expected_min_saved = without_sharing / 2;
+
+ EXPECT_LT(expected_min_saved, pss_saved);
// Use destructor of tf to close and unlink the file.
tf.fd = extinfo_.relro_fd;
}
-void getPss(pid_t pid, size_t* pss_out) {
+void GetPss(bool shared_relro, const char* lib, const char* relro_file, pid_t pid,
+ size_t* total_pss) {
pm_kernel_t* kernel;
ASSERT_EQ(0, pm_kernel_create(&kernel));
@@ -533,21 +539,28 @@
size_t num_maps;
ASSERT_EQ(0, pm_process_maps(process, &maps, &num_maps));
- size_t total_pss = 0;
- for (size_t i = 0; i < num_maps; i++) {
- pm_memusage_t usage;
- ASSERT_EQ(0, pm_map_usage(maps[i], &usage));
- total_pss += usage.pss;
+ // Calculate total PSS of the library.
+ *total_pss = 0;
+ bool saw_relro_file = false;
+ for (size_t i = 0; i < num_maps; ++i) {
+ if (android::base::EndsWith(maps[i]->name, lib) || strcmp(maps[i]->name, relro_file) == 0) {
+ if (strcmp(maps[i]->name, relro_file) == 0) saw_relro_file = true;
+
+ pm_memusage_t usage;
+ ASSERT_EQ(0, pm_map_usage(maps[i], &usage));
+ *total_pss += usage.pss;
+ }
}
- *pss_out = total_pss;
free(maps);
pm_process_destroy(process);
pm_kernel_destroy(kernel);
+
+ if (shared_relro) ASSERT_TRUE(saw_relro_file);
}
-void DlExtRelroSharingTest::SpawnChildrenAndMeasurePss(const char* lib, bool share_relro,
- size_t* pss_out) {
+void DlExtRelroSharingTest::SpawnChildrenAndMeasurePss(const char* lib, const char* relro_file,
+ bool share_relro, size_t* pss_out) {
const int CHILDREN = 20;
// Create children
@@ -600,11 +613,11 @@
childpipe[i] = parent_done_pipe[1];
}
- // Sum the PSS of all the children
+ // Sum the PSS of tested library of all the children
size_t total_pss = 0;
for (int i=0; i<CHILDREN; ++i) {
size_t child_pss;
- ASSERT_NO_FATAL_FAILURE(getPss(child_pids[i], &child_pss));
+ ASSERT_NO_FATAL_FAILURE(GetPss(share_relro, lib, relro_file, child_pids[i], &child_pss));
total_pss += child_pss;
}
*pss_out = total_pss;
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/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
index 69638be..00322ec 100644
--- a/tests/sys_ptrace_test.cpp
+++ b/tests/sys_ptrace_test.cpp
@@ -266,7 +266,7 @@
ASSERT_EQ(0, sigaction(SIGALRM, &action, &oldaction)) << strerror(errno);
alarm(5);
- run_watchpoint_test<Uint128_t>(watchpoint_imprecise_child, 8, 8);
+ run_watchpoint_test<Uint128_t>(watchpoint_imprecise_child, 8, sizeof(void*));
ASSERT_EQ(0, sigaction(SIGALRM, &oldaction, nullptr)) << strerror(errno);
}
diff --git a/tools/versioner/src/Driver.cpp b/tools/versioner/src/Driver.cpp
index 215dc3c..1b631b6 100644
--- a/tools/versioner/src/Driver.cpp
+++ b/tools/versioner/src/Driver.cpp
@@ -42,6 +42,7 @@
#include <llvm/ADT/IntrusiveRefCntPtr.h>
#include <llvm/ADT/SmallVector.h>
#include <llvm/ADT/StringRef.h>
+#include <llvm/Config/config.h>
#include "Arch.h"
#include "DeclarationDatabase.h"
@@ -237,7 +238,14 @@
}
clang::CompilerInstance Compiler;
+
+// Remove the workaround once b/35936936 is fixed.
+#if LLVM_VERSION_MAJOR >= 5
+ Compiler.setInvocation(std::move(invocation));
+#else
Compiler.setInvocation(invocation.release());
+#endif
+
Compiler.setDiagnostics(diags.get());
Compiler.setVirtualFileSystem(vfs);