Make __linker_error() handle the trailing newline.

Android's liblog logging automatically appends a newline, so most logging doesn't need one. __linker_error() also writes to stderr, so all callers needed to remember to supply their own newline (which liblog would then delete). One case was missed (unsurprisingly), so let's just make __linker_error() do the right thing, and simplify all the callers, and prevent future similar mistakes.

Also use %m rather than explicitly calling strerror(errno).

Change-Id: Ifcaccbb0e6760a9e04919a919f27011310c9b97f
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 2b230a8..b624c78 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -245,6 +245,7 @@
 
   va_start(ap, fmt);
   async_safe_format_fd_va_list(STDERR_FILENO, fmt, ap);
+  write(STDERR_FILENO, "\n", 1);
   va_end(ap);
 
   va_start(ap, fmt);
@@ -255,7 +256,7 @@
 }
 
 static void __linker_cannot_link(const char* argv0) {
-  __linker_error("CANNOT LINK EXECUTABLE \"%s\": %s\n",
+  __linker_error("CANNOT LINK EXECUTABLE \"%s\": %s",
                  argv0,
                  linker_get_error_buffer());
 }
@@ -267,26 +268,26 @@
   ExecutableInfo result = {};
 
   if (orig_path[0] != '/') {
-    __linker_error("error: expected absolute path: \"%s\"\n", orig_path);
+    __linker_error("error: expected absolute path: \"%s\"", orig_path);
   }
 
   off64_t file_offset;
   android::base::unique_fd fd(open_executable(orig_path, &file_offset, &result.path));
   if (fd.get() == -1) {
-    __linker_error("error: unable to open file \"%s\"\n", orig_path);
+    __linker_error("error: unable to open file \"%s\"", orig_path);
   }
 
   if (TEMP_FAILURE_RETRY(fstat(fd.get(), &result.file_stat)) == -1) {
-    __linker_error("error: unable to stat \"%s\": %s\n", result.path.c_str(), strerror(errno));
+    __linker_error("error: unable to stat \"%s\": %m", result.path.c_str());
   }
 
   ElfReader elf_reader;
   if (!elf_reader.Read(result.path.c_str(), fd.get(), file_offset, result.file_stat.st_size)) {
-    __linker_error("error: %s\n", linker_get_error_buffer());
+    __linker_error("error: %s", linker_get_error_buffer());
   }
   address_space_params address_space;
   if (!elf_reader.Load(&address_space)) {
-    __linker_error("error: %s\n", linker_get_error_buffer());
+    __linker_error("error: %s", linker_get_error_buffer());
   }
 
   result.phdr = elf_reader.loaded_phdr();
@@ -401,8 +402,7 @@
     if (note_gnu_property.IsBTICompatible() &&
         (phdr_table_protect_segments(somain->phdr, somain->phnum, somain->load_bias,
                                      somain->should_pad_segments(), &note_gnu_property) < 0)) {
-      __linker_error("error: can't protect segments for \"%s\": %s", exe_info.path.c_str(),
-                     strerror(errno));
+      __linker_error("error: can't protect segments for \"%s\": %m", exe_info.path.c_str());
     }
   }
 #endif
@@ -427,7 +427,7 @@
   // and the NDK no longer supports earlier API levels.
   if (elf_hdr->e_type != ET_DYN) {
     __linker_error("error: %s: Android only supports position-independent "
-                   "executables (-fPIE)\n", exe_info.path.c_str());
+                   "executables (-fPIE)", exe_info.path.c_str());
   }
 
   // Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
@@ -695,7 +695,7 @@
   // fallback.
   __libc_sysinfo = reinterpret_cast<void*>(__libc_int0x80);
 #endif
-  __linker_error("error: linker cannot load itself\n");
+  __linker_error("error: linker cannot load itself");
 }
 
 static ElfW(Addr) __attribute__((noinline))