Merge "Convert malloc_debug from Android.mk to Android.bp"
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 0c59c92..5188b6d 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -350,7 +350,7 @@
int __set_thread_area:set_thread_area(void*) x86
# vdso stuff.
-int clock_gettime(clockid_t, timespec*) arm,mips,mips64
-int __clock_gettime:clock_gettime(clockid_t, timespec*) arm64,x86,x86_64
-int gettimeofday(timeval*, timezone*) arm,mips,mips64
-int __gettimeofday:gettimeofday(timeval*, timezone*) arm64,x86,x86_64
+int clock_gettime(clockid_t, timespec*) mips,mips64
+int __clock_gettime:clock_gettime(clockid_t, timespec*) arm,arm64,x86,x86_64
+int gettimeofday(timeval*, timezone*) mips,mips64
+int __gettimeofday:gettimeofday(timeval*, timezone*) arm,arm64,x86,x86_64
diff --git a/libc/arch-arm/syscalls/clock_gettime.S b/libc/arch-arm/syscalls/__clock_gettime.S
similarity index 87%
rename from libc/arch-arm/syscalls/clock_gettime.S
rename to libc/arch-arm/syscalls/__clock_gettime.S
index 61a95dd..30eff03 100644
--- a/libc/arch-arm/syscalls/clock_gettime.S
+++ b/libc/arch-arm/syscalls/__clock_gettime.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(clock_gettime)
+ENTRY(__clock_gettime)
mov ip, r7
.cfi_register r7, ip
ldr r7, =__NR_clock_gettime
@@ -13,4 +13,4 @@
bxls lr
neg r0, r0
b __set_errno_internal
-END(clock_gettime)
+END(__clock_gettime)
diff --git a/libc/arch-arm/syscalls/gettimeofday.S b/libc/arch-arm/syscalls/__gettimeofday.S
similarity index 88%
rename from libc/arch-arm/syscalls/gettimeofday.S
rename to libc/arch-arm/syscalls/__gettimeofday.S
index f5ed674..de0eca5 100644
--- a/libc/arch-arm/syscalls/gettimeofday.S
+++ b/libc/arch-arm/syscalls/__gettimeofday.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(gettimeofday)
+ENTRY(__gettimeofday)
mov ip, r7
.cfi_register r7, ip
ldr r7, =__NR_gettimeofday
@@ -13,4 +13,4 @@
bxls lr
neg r0, r0
b __set_errno_internal
-END(gettimeofday)
+END(__gettimeofday)
diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp
index 029c148..f3d95ca 100644
--- a/libc/bionic/vdso.cpp
+++ b/libc/bionic/vdso.cpp
@@ -17,7 +17,7 @@
#include "private/bionic_globals.h"
#include "private/bionic_vdso.h"
-#if defined(__aarch64__) || defined(__x86_64__) || defined (__i386__)
+#if defined(__aarch64__) || defined(__arm__) || defined(__i386__) || defined(__x86_64__)
#include <limits.h>
#include <link.h>
@@ -28,6 +28,8 @@
#include <unistd.h>
#include "private/KernelArgumentBlock.h"
+#define AT_SYSINFO_EHDR 33 /* until we have new enough uapi headers... */
+
int clock_gettime(int clock_id, timespec* tp) {
auto vdso_clock_gettime = reinterpret_cast<decltype(&clock_gettime)>(
__libc_globals->vdso[VDSO_CLOCK_GETTIME].fn);
diff --git a/libc/private/bionic_vdso.h b/libc/private/bionic_vdso.h
index 5400de5..8fd0743 100644
--- a/libc/private/bionic_vdso.h
+++ b/libc/private/bionic_vdso.h
@@ -25,6 +25,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#ifndef _PRIVATE_BIONIC_VDSO_H
#define _PRIVATE_BIONIC_VDSO_H
@@ -33,7 +34,7 @@
#if defined(__aarch64__)
#define VDSO_CLOCK_GETTIME_SYMBOL "__kernel_clock_gettime"
#define VDSO_GETTIMEOFDAY_SYMBOL "__kernel_gettimeofday"
-#elif defined(__x86_64__) || defined(__i386__)
+#elif defined(__arm__) || defined(__i386__) || defined(__x86_64__)
#define VDSO_CLOCK_GETTIME_SYMBOL "__vdso_clock_gettime"
#define VDSO_GETTIMEOFDAY_SYMBOL "__vdso_gettimeofday"
#endif
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 136e432..4eff46d 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -252,7 +252,12 @@
off64_t range_start;
off64_t range_end;
- return safe_add(&range_start, file_offset_, offset) &&
+ // Only header can be located at the 0 offset... This function called to
+ // check DYNSYM and DYNAMIC sections and phdr/shdr - none of them can be
+ // and 0 offset.
+
+ return offset > 0 &&
+ safe_add(&range_start, file_offset_, offset) &&
safe_add(&range_end, range_start, size) &&
range_start < file_size_ &&
range_end <= file_size_;
@@ -324,6 +329,35 @@
return false;
}
+ // Make sure dynamic_shdr offset and size matches PT_DYNAMIC phdr
+ size_t pt_dynamic_offset = 0;
+ size_t pt_dynamic_filesz = 0;
+ for (size_t i = 0; i < phdr_num_; ++i) {
+ const ElfW(Phdr)* phdr = &phdr_table_[i];
+ if (phdr->p_type == PT_DYNAMIC) {
+ pt_dynamic_offset = phdr->p_offset;
+ pt_dynamic_filesz = phdr->p_filesz;
+ }
+ }
+
+ if (pt_dynamic_offset != dynamic_shdr->sh_offset) {
+ DL_ERR("\"%s\" .dynamic section has invalid offset: 0x%zx, "
+ "expected to match PT_DYNAMIC offset: 0x%zx",
+ name_.c_str(),
+ static_cast<size_t>(dynamic_shdr->sh_offset),
+ pt_dynamic_offset);
+ return false;
+ }
+
+ if (pt_dynamic_filesz != dynamic_shdr->sh_size) {
+ DL_ERR("\"%s\" .dynamic section has invalid size: 0x%zx, "
+ "expected to match PT_DYNAMIC filesz: 0x%zx",
+ name_.c_str(),
+ static_cast<size_t>(dynamic_shdr->sh_size),
+ pt_dynamic_filesz);
+ return false;
+ }
+
if (dynamic_shdr->sh_link >= shdr_num_) {
DL_ERR("\"%s\" .dynamic section has invalid sh_link: %d", name_.c_str(), dynamic_shdr->sh_link);
return false;
diff --git a/tools/Android.bp b/tools/Android.bp
new file mode 100644
index 0000000..b44c296
--- /dev/null
+++ b/tools/Android.bp
@@ -0,0 +1 @@
+subdirs = ["*"]
diff --git a/tools/relocation_packer/Android.bp b/tools/relocation_packer/Android.bp
new file mode 100644
index 0000000..2907b31
--- /dev/null
+++ b/tools/relocation_packer/Android.bp
@@ -0,0 +1,84 @@
+//
+// Copyright (C) 2015 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.
+//
+
+cc_defaults {
+ name: "relocation_packer_flags",
+ cppflags: [
+ "-Wall",
+ "-Wextra",
+ "-Wunused",
+ "-Werror",
+ "-Wold-style-cast",
+ ],
+
+ target: {
+ darwin: {
+ enabled: false,
+ },
+ },
+}
+
+cc_library_host_static {
+ name: "lib_relocation_packer",
+ defaults: ["relocation_packer_flags"],
+ srcs: [
+ "src/debug.cc",
+ "src/delta_encoder.cc",
+ "src/elf_file.cc",
+ "src/packer.cc",
+ "src/sleb128.cc",
+ ],
+
+ static_libs: [
+ "libelf",
+ "libz",
+ ],
+}
+
+cc_binary_host {
+ name: "relocation_packer",
+ defaults: ["relocation_packer_flags"],
+
+ srcs: ["src/main.cc"],
+ static_libs: [
+ "lib_relocation_packer",
+ "libelf",
+ "libz",
+ "libbase",
+ ],
+
+ // Statically linking libc++ to make it work from prebuilts
+ stl: "libc++_static",
+}
+
+cc_test_host {
+ name: "relocation_packer_unit_tests",
+ defaults: ["relocation_packer_flags"],
+
+ srcs: [
+ "src/debug_unittest.cc",
+ "src/delta_encoder_unittest.cc",
+ "src/elf_file_unittest.cc",
+ "src/sleb128_unittest.cc",
+ "src/packer_unittest.cc",
+ ],
+
+ static_libs: [
+ "lib_relocation_packer",
+ "libelf",
+ "libz",
+ ],
+}
diff --git a/tools/relocation_packer/Android.mk b/tools/relocation_packer/Android.mk
index bdb54b7..80208ec 100644
--- a/tools/relocation_packer/Android.mk
+++ b/tools/relocation_packer/Android.mk
@@ -15,63 +15,6 @@
#
ifeq ($(HOST_OS),linux)
-common_cppflags := -Wall -Wextra -Wunused -Werror -Wold-style-cast
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION := .cc
-
-LOCAL_SRC_FILES := \
- src/debug.cc \
- src/delta_encoder.cc \
- src/elf_file.cc \
- src/packer.cc \
- src/sleb128.cc \
-
-LOCAL_STATIC_LIBRARIES := libelf libz
-LOCAL_MODULE := lib_relocation_packer
-
-LOCAL_CPPFLAGS := $(common_cppflags)
-
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION := .cc
-
-LOCAL_SRC_FILES := src/main.cc
-LOCAL_STATIC_LIBRARIES := lib_relocation_packer libelf libz libbase
-
-# Statically linking libc++ to make it work from prebuilts
-LOCAL_CXX_STL := libc++_static
-
-LOCAL_MODULE := relocation_packer
-
-LOCAL_CPPFLAGS := $(common_cppflags)
-
-include $(BUILD_HOST_EXECUTABLE)
-
-include $(CLEAR_VARS)
-
-LOCAL_CPP_EXTENSION := .cc
-
-LOCAL_SRC_FILES := \
- src/debug_unittest.cc \
- src/delta_encoder_unittest.cc \
- src/elf_file_unittest.cc \
- src/sleb128_unittest.cc \
- src/packer_unittest.cc \
-
-LOCAL_STATIC_LIBRARIES := lib_relocation_packer libelf libz
-
-LOCAL_CPPFLAGS := $(common_cppflags)
-
-LOCAL_MODULE := relocation_packer_unit_tests
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_HOST_NATIVE_TEST)
# $(1) library name
define copy-test-library