linker: simplify how warnings turn into errors past a certain api level.

This was motivated by the fact that most of the _anchors_ on the doc page were outdated. I've taken the simple expedient of removing those. I was then struck by the amount of copy & paste involved in showing both warning and error, so the new function takes care of that.

Change-Id: I82d3e6a6d8235a78f7cfe427b1209a1f9c83f682
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index c52952f..e695efd 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -308,26 +308,17 @@
   }
 
   if (header_.e_shentsize != sizeof(ElfW(Shdr))) {
-    if (get_application_target_sdk_version() >= 26) {
-      DL_ERR_AND_LOG("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)",
-                     name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)));
+    if (DL_ERROR_AFTER(26, "\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)",
+                       name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)))) {
       return false;
     }
-    DL_WARN_documented_change(26,
-                              "invalid-elf-header_section-headers-enforced-for-api-level-26",
-                              "\"%s\" has unsupported e_shentsize 0x%x (expected 0x%zx)",
-                              name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)));
     add_dlwarning(name_.c_str(), "has invalid ELF header");
   }
 
   if (header_.e_shstrndx == 0) {
-    if (get_application_target_sdk_version() >= 26) {
-      DL_ERR_AND_LOG("\"%s\" has invalid e_shstrndx", name_.c_str());
+    if (DL_ERROR_AFTER(26, "\"%s\" has invalid e_shstrndx", name_.c_str())) {
       return false;
     }
-    DL_WARN_documented_change(26,
-                              "invalid-elf-header_section-headers-enforced-for-api-level-26",
-                              "\"%s\" has invalid e_shstrndx", name_.c_str());
     add_dlwarning(name_.c_str(), "has invalid ELF header");
   }
 
@@ -434,40 +425,24 @@
   }
 
   if (pt_dynamic_offset != dynamic_shdr->sh_offset) {
-    if (get_application_target_sdk_version() >= 26) {
-      DL_ERR_AND_LOG("\"%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);
+    if (DL_ERROR_AFTER(26, "\"%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;
     }
-    DL_WARN_documented_change(26,
-                              "invalid-elf-header_section-headers-enforced-for-api-level-26",
-                              "\"%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);
     add_dlwarning(name_.c_str(), "invalid .dynamic section");
   }
 
   if (pt_dynamic_filesz != dynamic_shdr->sh_size) {
-    if (get_application_target_sdk_version() >= 26) {
-      DL_ERR_AND_LOG("\"%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);
+    if (DL_ERROR_AFTER(26, "\"%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;
     }
-    DL_WARN_documented_change(26,
-                              "invalid-elf-header_section-headers-enforced-for-api-level-26",
-                              "\"%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);
     add_dlwarning(name_.c_str(), "invalid .dynamic section");
   }
 
@@ -1058,15 +1033,10 @@
     if (file_length != 0) {
       int prot = PFLAGS_TO_PROT(phdr->p_flags);
       if ((prot & (PROT_EXEC | PROT_WRITE)) == (PROT_EXEC | PROT_WRITE)) {
-        // W + E PT_LOAD segments are not allowed in O.
-        if (get_application_target_sdk_version() >= 26) {
-          DL_ERR_AND_LOG("\"%s\": W+E load segments are not allowed", name_.c_str());
+        if (DL_ERROR_AFTER(26, "\"%s\" has load segments that are both writable and executable",
+                           name_.c_str())) {
           return false;
         }
-        DL_WARN_documented_change(26,
-                                  "writable-and-executable-segments-enforced-for-api-level-26",
-                                  "\"%s\" has load segments that are both writable and executable",
-                                  name_.c_str());
         add_dlwarning(name_.c_str(), "W+E load segments");
       }