From 0054bcd42260d248e391ed01d6b3da4fefdad45c Mon Sep 17 00:00:00 2001
From: Ben Gamari <bgamari.foss@gmail.com>
Date: Sun, 27 Dec 2015 23:59:59 +0100
Subject: [PATCH] rts/Linker(ARM): Ensure all code sections are flushed from
 cache

Test Plan: Validate with T12299

Reviewers: hsyl20, austin, erikd

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1708

GHC Trac Issues: #11299
---
 rts/Linker.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 2ee3cbce265d..c0ab66498725 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -2747,8 +2747,16 @@ static int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
 static void
 ocFlushInstructionCache( ObjectCode *oc )
 {
+    int i;
     // Object code
-    __clear_cache(oc->image, oc->image + oc->fileSize);
+    for (i=0; i < oc->n_sections; i++) {
+        Section *s = &oc->sections[i];
+        // This is a bit too broad but we don't have any way to determine what
+        // is certainly code
+        if (s->kind == SECTIONKIND_CODE_OR_RODATA)
+            __clear_cache(s->start, (void*) ((uintptr_t) s->start + s->size));
+    }
+
     // Jump islands
     __clear_cache(oc->symbol_extras, &oc->symbol_extras[oc->n_symbol_extras]);
 }
-- 
GitLab