فهرست منبع

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)) {