Преглед на файлове

Avoid writing relocations if there's no change.

If performing a relocation ends up being a no-op, don't actually perform
the write. This would save a bunch of copy-on-writes for images with text
relocations. I don't believe this has much actual impact on our images,
since all relocations are in the data section, which probably gets
modified soon after anyway, but it's good hygiene.
Evan Green преди 8 години
родител
ревизия
5cb675e82d
променени са 1 файла, в които са добавени 15 реда и са изтрити 3 реда
  1. 15 3
      lib/im/elf.c

+ 15 - 3
lib/im/elf.c

@@ -3485,12 +3485,24 @@ Return Value:
                             Symbols[SymbolIndex].Size;
 
         } else {
-            *RelocationPlace = Address;
-            RelocationEnd = RelocationPlace + 1;
+
+            //
+            // Avoid the write unless it's necessary, as unnecessary write
+            // faults are expensive.
+            //
+
+            if (*RelocationPlace != Address) {
+                *RelocationPlace = Address;
+                RelocationEnd = RelocationPlace + 1;
+
+            } else {
+                RelocationEnd = NULL;
+            }
         }
 
         if ((LoadingImage != NULL) &&
-            ((Image->Flags & IMAGE_FLAG_TEXT_RELOCATIONS) != 0)) {
+            ((Image->Flags & IMAGE_FLAG_TEXT_RELOCATIONS) != 0) &&
+            (RelocationEnd != NULL)) {
 
             if ((LoadingImage->RelocationStart == ELF_INVALID_RELOCATION) ||
                 (LoadingImage->RelocationStart > (PVOID)RelocationPlace)) {