Always log errno when aborting.

(Where errno is relevant.)

Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter,
but it's more common, and potentially more intention-revealing.)

Bug: http://b/65608572
Test: ran tests
Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 58a52d0..a843b7b 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -286,8 +286,7 @@
                      struct stat* file_stat, off64_t file_offset,
                      uint32_t rtld_flags) {
   if (strlen(name) >= PATH_MAX) {
-    DL_ERR("library name \"%s\" too long", name);
-    return nullptr;
+    async_safe_fatal("library name \"%s\" too long", name);
   }
 
   TRACE("name %s: allocating soinfo for ns=%p", name, ns);
diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp
index fd6f496..a37e910 100644
--- a/linker/linker_allocator.cpp
+++ b/linker/linker_allocator.cpp
@@ -200,12 +200,10 @@
 }
 
 void LinkerSmallObjectAllocator::alloc_page() {
-  static_assert(sizeof(page_info) % 16 == 0,
-                "sizeof(page_info) is not multiple of 16");
-  void* map_ptr = mmap(nullptr, PAGE_SIZE,
-      PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+  static_assert(sizeof(page_info) % 16 == 0, "sizeof(page_info) is not multiple of 16");
+  void* map_ptr = mmap(nullptr, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   if (map_ptr == MAP_FAILED) {
-    async_safe_fatal("mmap failed");
+    async_safe_fatal("mmap failed: %s", strerror(errno));
   }
 
   prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map_ptr, PAGE_SIZE, "linker_alloc_small_objects");
@@ -246,11 +244,11 @@
 
 void* LinkerMemoryAllocator::alloc_mmap(size_t size) {
   size_t allocated_size = PAGE_END(size + sizeof(page_info));
-  void* map_ptr = mmap(nullptr, allocated_size,
-      PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+  void* map_ptr = mmap(nullptr, allocated_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
+                       -1, 0);
 
   if (map_ptr == MAP_FAILED) {
-    async_safe_fatal("mmap failed");
+    async_safe_fatal("mmap failed: %s", strerror(errno));
   }
 
   prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, map_ptr, allocated_size, "linker_alloc_lob");
diff --git a/linker/linker_allocator.h b/linker/linker_allocator.h
index 80ae508..9c16828 100644
--- a/linker/linker_allocator.h
+++ b/linker/linker_allocator.h
@@ -88,12 +88,12 @@
 
   T* allocate(size_t n, const T* hint = nullptr) {
     size_t size = n * sizeof(T);
-    void* ptr = mmap(const_cast<T*>(hint), size,
-        PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+    void* ptr = mmap(const_cast<T*>(hint), size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
+                     -1, 0);
     if (ptr == MAP_FAILED) {
       // Spec says we need to throw std::bad_alloc here but because our
       // code does not support exception handling anyways - we are going to abort.
-      async_safe_fatal("mmap failed");
+      async_safe_fatal("mmap failed: %s", strerror(errno));
     }
 
     prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, size, "linker_alloc_vector");
diff --git a/linker/linker_block_allocator.cpp b/linker/linker_block_allocator.cpp
index 605e185..abb1ebd 100644
--- a/linker/linker_block_allocator.cpp
+++ b/linker/linker_block_allocator.cpp
@@ -117,7 +117,7 @@
                 "Invalid sizeof(LinkerBlockAllocatorPage)");
 
   LinkerBlockAllocatorPage* page = reinterpret_cast<LinkerBlockAllocatorPage*>(
-      mmap(nullptr, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0));
+      mmap(nullptr, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0));
 
   if (page == MAP_FAILED) {
     abort(); // oom
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index e8b02d6..3862d8c 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -276,11 +276,8 @@
 
   const char* executable_path = get_executable_path();
   soinfo* si = soinfo_alloc(&g_default_namespace, executable_path, &file_stat, 0, RTLD_GLOBAL);
-  if (si == nullptr) {
-    async_safe_fatal("Couldn't allocate soinfo: out of memory?");
-  }
 
-  /* bootstrap the link map, the main exe always needs to be first */
+  // Bootstrap the link map, the main exe always needs to be first.
   si->set_main_executable();
   link_map* map = &(si->link_map_head);