Merge "bionic: fortify comments in _system_properties.h"
diff --git a/libc/include/uchar.h b/libc/include/uchar.h
index e1fcb5c..0ec9d2e 100644
--- a/libc/include/uchar.h
+++ b/libc/include/uchar.h
@@ -34,6 +34,11 @@
 
 __BEGIN_DECLS
 
+#if defined(__GNUC__) && __GNUC__ >= 5 && !defined(__cplusplus)
+typedef __CHAR16_TYPE__ char16_t;
+typedef __CHAR32_TYPE__ char32_t;
+#endif
+
 #define __STD_UTF_16__ 1
 #define __STD_UTF_32__ 1
 
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 2f32c0e..ceee3a5 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3022,6 +3022,8 @@
   insert_soinfo_into_debug_map(linker_soinfo_for_gdb);
 }
 
+extern "C" int __system_properties_init(void);
+
 /*
  * This code is called after the linker has linked itself and
  * fixed it's own GOT. It is safe to make references to externs
@@ -3036,6 +3038,9 @@
   // Initialize environment functions, and get to the ELF aux vectors table.
   linker_env_init(args);
 
+  // Initialize system properties
+  __system_properties_init(); // may use 'environ'
+
   // If this is a setuid/setgid program, close the security hole described in
   // ftp://ftp.freebsd.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-02:23.stdio.asc
   if (get_AT_SECURE()) {
diff --git a/linker/linker_mips.cpp b/linker/linker_mips.cpp
index 0769f82..87b811f 100644
--- a/linker/linker_mips.cpp
+++ b/linker/linker_mips.cpp
@@ -128,7 +128,7 @@
         if (s != nullptr) {
           *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr;
         } else {
-          *reinterpret_cast<ElfW(Addr)*>(reloc) += base;
+          *reinterpret_cast<ElfW(Addr)*>(reloc) += load_bias;
         }
         break;
       default:
diff --git a/tools/relocation_packer/src/elf_file.cc b/tools/relocation_packer/src/elf_file.cc
index 6ac9deb..d06bd63 100644
--- a/tools/relocation_packer/src/elf_file.cc
+++ b/tools/relocation_packer/src/elf_file.cc
@@ -472,6 +472,16 @@
               << " d_val adjusted to " << dynamic->d_un.d_val;
     }
 
+    // Special case: DT_MIPS_RLD_MAP2 stores the difference between dynamic
+    // entry address and the address of the _r_debug (used by GDB)
+    // since the dynamic section and target address are on the
+    // different sides of the hole it needs to be adjusted accordingly
+    if (tag == DT_MIPS_RLD_MAP2) {
+      dynamic->d_un.d_val += hole_size;
+      VLOG(1) << "dynamic[" << i << "] " << dynamic->d_tag
+              << " d_val adjusted to " << dynamic->d_un.d_val;
+    }
+
     // Ignore DT_RELCOUNT and DT_RELACOUNT: (1) nobody uses them and
     // technically (2) the relative relocation count is not changed.
 
diff --git a/tools/relocation_packer/src/elf_traits.h b/tools/relocation_packer/src/elf_traits.h
index 41b06c8..1c938fa 100644
--- a/tools/relocation_packer/src/elf_traits.h
+++ b/tools/relocation_packer/src/elf_traits.h
@@ -10,6 +10,10 @@
 #include "elf.h"
 #include "libelf.h"
 
+#if !defined(DT_MIPS_RLD_MAP2)
+#define DT_MIPS_RLD_MAP2 0x70000035
+#endif
+
 // ELF is a traits structure used to provide convenient aliases for
 // 32/64 bit Elf types and functions, depending on the target file.