rts/Linker.c (ocFlushInstructionCache):
authorpho@cielonegro.org <unknown>
Tue, 30 Nov 2010 12:14:25 +0000 (12:14 +0000)
committerpho@cielonegro.org <unknown>
Tue, 30 Nov 2010 12:14:25 +0000 (12:14 +0000)
I found this function causes a segfault when ocAllocateSymbolExtras() has allocated a separate memory region for jump islands.

rts/Linker.c

index c92ede5..5f8ce13 100644 (file)
@@ -2393,13 +2393,12 @@ static SymbolExtra* makeSymbolExtra( ObjectCode* oc,
    Because the PPC has split data/instruction caches, we have to
    do that whenever we modify code at runtime.
  */
-
-static void ocFlushInstructionCache( ObjectCode *oc )
+static void ocFlushInstructionCacheFrom(void* begin, size_t length)
 {
-    int n = (oc->fileSize + sizeof( SymbolExtra ) * oc->n_symbol_extras + 3) / 4;
-    unsigned long *p = (unsigned long *) oc->image;
+    size_t         n = (length + 3) / 4;
+    unsigned long* p = begin;
 
-    while( n-- )
+    while (n--)
     {
         __asm__ volatile ( "dcbf 0,%0\n\t"
                            "sync\n\t"
@@ -2413,6 +2412,14 @@ static void ocFlushInstructionCache( ObjectCode *oc )
                        "isync"
                      );
 }
+static void ocFlushInstructionCache( ObjectCode *oc )
+{
+    /* The main object code */
+    ocFlushInstructionCacheFrom(oc->image + oc->misalignment, oc->fileSize);
+
+    /* Jump Islands */
+    ocFlushInstructionCacheFrom(oc->symbol_extras, sizeof(SymbolExtra) * oc->n_symbol_extras);
+}
 #endif
 
 /* --------------------------------------------------------------------------