linker: use %m in error messages.

Change-Id: Ib799abdd2628fa1c54a2e479c6455b44d40deae1
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 2eb3cae..4365ea5 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -387,7 +387,7 @@
   auto length = readlink(proc_self_fd, buf, sizeof(buf));
   if (length == -1) {
     if (!is_first_stage_init()) {
-      PRINT("readlink(\"%s\") failed: %s [fd=%d]", proc_self_fd, strerror(errno), fd);
+      PRINT("readlink(\"%s\" [fd=%d]) failed: %m", proc_self_fd, fd);
     }
     return false;
   }
@@ -1185,7 +1185,7 @@
 
   struct stat file_stat;
   if (TEMP_FAILURE_RETRY(fstat(task->get_fd(), &file_stat)) != 0) {
-    DL_OPEN_ERR("unable to stat file for the library \"%s\": %s", name, strerror(errno));
+    DL_OPEN_ERR("unable to stat file for the library \"%s\": %m", name);
     return false;
   }
   if (file_offset >= file_stat.st_size) {
@@ -1215,7 +1215,7 @@
 
   struct statfs fs_stat;
   if (TEMP_FAILURE_RETRY(fstatfs(task->get_fd(), &fs_stat)) != 0) {
-    DL_OPEN_ERR("unable to fstatfs file for the library \"%s\": %s", name, strerror(errno));
+    DL_OPEN_ERR("unable to fstatfs file for the library \"%s\": %m", name);
     return false;
   }
 
@@ -3364,7 +3364,7 @@
                               get_realpath());
     add_dlwarning(get_realpath(), "text relocations");
     if (phdr_table_unprotect_segments(phdr, phnum, load_bias, should_pad_segments_) < 0) {
-      DL_ERR("can't unprotect loadable segments for \"%s\": %s", get_realpath(), strerror(errno));
+      DL_ERR("can't unprotect loadable segments for \"%s\": %m", get_realpath());
       return false;
     }
   }
@@ -3380,8 +3380,7 @@
   if (has_text_relocations) {
     // All relocations are done, we can protect our segments back to read-only.
     if (phdr_table_protect_segments(phdr, phnum, load_bias, should_pad_segments_) < 0) {
-      DL_ERR("can't protect segments for \"%s\": %s",
-             get_realpath(), strerror(errno));
+      DL_ERR("can't protect segments for \"%s\": %m", get_realpath());
       return false;
     }
   }
@@ -3397,15 +3396,13 @@
   if (extinfo && (extinfo->flags & ANDROID_DLEXT_WRITE_RELRO)) {
     if (phdr_table_serialize_gnu_relro(phdr, phnum, load_bias,
                                        extinfo->relro_fd, relro_fd_offset) < 0) {
-      DL_ERR("failed serializing GNU RELRO section for \"%s\": %s",
-             get_realpath(), strerror(errno));
+      DL_ERR("failed serializing GNU RELRO section for \"%s\": %m", get_realpath());
       return false;
     }
   } else if (extinfo && (extinfo->flags & ANDROID_DLEXT_USE_RELRO)) {
     if (phdr_table_map_gnu_relro(phdr, phnum, load_bias,
                                  extinfo->relro_fd, relro_fd_offset) < 0) {
-      DL_ERR("failed mapping GNU RELRO section for \"%s\": %s",
-             get_realpath(), strerror(errno));
+      DL_ERR("failed mapping GNU RELRO section for \"%s\": %m", get_realpath());
       return false;
     }
   }
@@ -3418,8 +3415,7 @@
 
 bool soinfo::protect_relro() {
   if (phdr_table_protect_gnu_relro(phdr, phnum, load_bias, should_pad_segments_) < 0) {
-    DL_ERR("can't enable GNU RELRO protection for \"%s\": %s",
-           get_realpath(), strerror(errno));
+    DL_ERR("can't enable GNU RELRO protection for \"%s\": %m", get_realpath());
     return false;
   }
   return true;
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index 70430b8..613c781 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -254,11 +254,10 @@
         // the failure with INFO rather than DL_WARN. e.g. A binary in
         // /data/local/tmp may attempt to stat /postinstall. See
         // http://b/120996057.
-        INFO("%s:%zd: warning: path \"%s\" couldn't be resolved: %s",
+        INFO("%s:%zd: warning: path \"%s\" couldn't be resolved: %m",
              ld_config_file_path,
              cp.lineno(),
-             value.c_str(),
-             strerror(errno));
+             value.c_str());
         resolved_path = value;
       }
 
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index cdc4b86..0e5fb96 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -234,8 +234,7 @@
   if (TEMP_FAILURE_RETRY(stat(exe_path, &result.file_stat) == -1)) {
     // Fallback to argv[0] for the case where /proc isn't available
     if (TEMP_FAILURE_RETRY(stat(arg_path, &result.file_stat) == -1)) {
-      async_safe_fatal("unable to stat either \"/proc/self/exe\" or \"%s\": %s",
-          arg_path, strerror(errno));
+      async_safe_fatal("unable to stat either \"/proc/self/exe\" or \"%s\": %m", arg_path);
     }
     exe_path = arg_path;
   }
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index a629ee6..1b51fcd 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -234,7 +234,7 @@
 #endif
 
   if (!file_fragment_.Map(fd_, file_offset_, 0, map_size)) {
-    DL_ERR("\"%s\" header mmap failed: %s", name_.c_str(), strerror(errno));
+    DL_ERR("\"%s\" header mmap failed: %m", name_.c_str());
     return false;
   }
 
@@ -389,7 +389,7 @@
 
   void* phdr_data = MapData(&phdr_fragment_, header_.e_phoff, size);
   if (phdr_data == nullptr) {
-    DL_ERR("\"%s\" phdr mmap failed: %s", name_.c_str(), strerror(errno));
+    DL_ERR("\"%s\" phdr mmap failed: %m", name_.c_str());
     return false;
   }
 
@@ -416,7 +416,7 @@
 
   void* shdr_data = MapData(&shdr_fragment_, header_.e_shoff, size);
   if (shdr_data == nullptr) {
-    DL_ERR("\"%s\" shdr mmap failed: %s", name_.c_str(), strerror(errno));
+    DL_ERR("\"%s\" shdr mmap failed: %m", name_.c_str());
     return false;
   }
 
@@ -510,7 +510,7 @@
 
   void* dynamic_data = MapData(&dynamic_fragment_, dynamic_shdr->sh_offset, dynamic_shdr->sh_size);
   if (dynamic_data == nullptr) {
-    DL_ERR("\"%s\" dynamic section mmap failed: %s", name_.c_str(), strerror(errno));
+    DL_ERR("\"%s\" dynamic section mmap failed: %m", name_.c_str());
     return false;
   }
 
@@ -524,7 +524,7 @@
 
   void* strtab_data = MapData(&strtab_fragment_, strtab_shdr->sh_offset, strtab_shdr->sh_size);
   if (strtab_data == nullptr) {
-    DL_ERR("\"%s\" strtab section mmap failed: %s", name_.c_str(), strerror(errno));
+    DL_ERR("\"%s\" strtab section mmap failed: %m", name_.c_str());
     return false;
   }
 
@@ -923,7 +923,7 @@
                             fd_,
                             file_offset_ + file_page_start);
       if (seg_addr == MAP_FAILED) {
-        DL_ERR("couldn't map \"%s\" segment %zd: %s", name_.c_str(), i, strerror(errno));
+        DL_ERR("couldn't map \"%s\" segment %zd: %m", name_.c_str(), i);
         return false;
       }
 
@@ -984,7 +984,7 @@
                            -1,
                            0);
       if (zeromap == MAP_FAILED) {
-        DL_ERR("couldn't zero fill \"%s\" gap: %s", name_.c_str(), strerror(errno));
+        DL_ERR("couldn't zero fill \"%s\" gap: %m", name_.c_str());
         return false;
       }
 
diff --git a/linker/linker_relocate.cpp b/linker/linker_relocate.cpp
index 5f993ba..8f85871 100644
--- a/linker/linker_relocate.cpp
+++ b/linker/linker_relocate.cpp
@@ -189,8 +189,7 @@
     if (phdr_table_protect_segments(relocator.si->phdr, relocator.si->phnum,
                                     relocator.si->load_bias,
                                     relocator.si->should_pad_segments()) < 0) {
-      DL_ERR("can't protect segments for \"%s\": %s",
-             relocator.si->get_realpath(), strerror(errno));
+      DL_ERR("can't protect segments for \"%s\": %m", relocator.si->get_realpath());
       return false;
     }
     return true;
@@ -200,8 +199,8 @@
     if (phdr_table_unprotect_segments(relocator.si->phdr, relocator.si->phnum,
                                       relocator.si->load_bias,
                                       relocator.si->should_pad_segments()) < 0) {
-      DL_ERR("can't unprotect loadable segments for \"%s\": %s",
-             relocator.si->get_realpath(), strerror(errno));
+      DL_ERR("can't unprotect loadable segments for \"%s\": %m",
+             relocator.si->get_realpath());
       return false;
     }
     return true;
diff --git a/linker/linker_utils.cpp b/linker/linker_utils.cpp
index cd03eed..9abe542 100644
--- a/linker/linker_utils.cpp
+++ b/linker/linker_utils.cpp
@@ -207,7 +207,7 @@
   if (realpath(original_path, resolved_path) != nullptr) {
     struct stat s;
     if (stat(resolved_path, &s) == -1) {
-      DL_WARN("Warning: cannot stat file \"%s\": %s (ignoring)", resolved_path, strerror(errno));
+      DL_WARN("Warning: cannot stat file \"%s\": %m (ignoring)", resolved_path);
       return "";
     }
     if (!S_ISDIR(s.st_mode)) {
@@ -226,8 +226,7 @@
     std::string entry_path;
     if (parse_zip_path(normalized_path.c_str(), &zip_path, &entry_path)) {
       if (realpath(zip_path.c_str(), resolved_path) == nullptr) {
-        DL_WARN("Warning: unable to resolve \"%s\": %s (ignoring)",
-                zip_path.c_str(), strerror(errno));
+        DL_WARN("Warning: unable to resolve \"%s\": %m (ignoring)", zip_path.c_str());
         return "";
       }