tools: record and process source/dest banks to fix data reloc bug
authorAlan Cox <alan@linux.intel.com>
Fri, 13 Jul 2018 23:07:51 +0000 (00:07 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 13 Jul 2018 23:07:51 +0000 (00:07 +0100)
Before if we had something like

extern char foo[];
char *x = foo;

and foo was banked the fixup code would try and write a code stub mashing
x in the process. Now it treats data to data references as intentional.

Kernel/tools/bankld/lkrloc3.c
Kernel/tools/binmunge.c

index c841790..eae6d85 100644 (file)
@@ -214,9 +214,9 @@ static void bankingstub(struct sym *s, struct areax *bx, int bmagic, int addr)
                 fprintf(ofp, "; Banking Stub %s:%s(%s)\n",
                         a->a_id, s->s_id, s->m_id);
                 fprintf(ofp, "; From area %s\n", bx->a_bap->a_id);
-                fprintf(ofp, "B %02X %04X %02X %s\n",
+                fprintf(ofp, "B %02X %04X %02X %s %s\n",
                         bxm, addr,
-                        bmagic, bx->a_bap->a_id);
+                        bmagic, bx->a_bap->a_id, a->a_id);
         }
         return;
 }
index b2b2646..b898eda 100644 (file)
@@ -244,13 +244,19 @@ static void process_stub(char *p)
 {
   int b1, b2, addr;
   char name[65];
+  char sname[65];
 
   if (strlen(p) > 4 && !isspace(p[8]))
     fprintf(stderr, "Overflow: %s", p);
-  if (sscanf(p, "%02x %04x %02x %64s", &b1, &addr, &b2, name) != 4) {
+  if (sscanf(p, "%02x %04x %02x %64s %64s", &b1, &addr, &b2, name, sname) != 5) {
     fprintf(stderr, "Invalid relocation link %s\n", p);
     exit(1);
   }
+  /* A data relocation into another bank of data is treated as deliberate.
+     We can't do much else. It's not code so we can't patch it, and if it's
+     a data pointer (as it should be) then a relocation is nonsense! */
+  if (!stub_code(sname) && !stub_code(name))
+    return;
   /* If we are stubbing the lot then code is handled as data is */
   if (stub_code(name) && !stub_all)
     code_reloc(b1, addr, b2);