Drop the fake exception tables entries and use weak symbols
authorDavide Libenzi <dlibenzi@google.com>
Tue, 1 Dec 2015 16:17:51 +0000 (08:17 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 16 Dec 2015 21:27:06 +0000 (16:27 -0500)
Drop the fake exception tables entries and use weak symbols.

Signed-off-by: Davide Libenzi <dlibenzi@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/riscv/uaccess.h
kern/arch/x86/uaccess.h
kern/src/ex_table.c

index 644ff24..4ed0bb7 100644 (file)
@@ -26,13 +26,6 @@ struct extable_ip_fixup {
        uint64_t fixup;
 };
 
        uint64_t fixup;
 };
 
-#define _ASM_EXTABLE_INIT()                                                                            \
-       asm volatile(                                                                                           \
-       " .pushsection \"__ex_table\",\"a\"\n"                                          \
-       " .balign 16\n"                                                                                         \
-       " .popsection\n"                                                                                        \
-       : :)
-
 #define _ASM_EXTABLE(from, to)                                                                 \
        " .pushsection \"__ex_table\",\"a\"\n"                                          \
        " .balign 16\n"                                                                                         \
 #define _ASM_EXTABLE(from, to)                                                                 \
        " .pushsection \"__ex_table\",\"a\"\n"                                          \
        " .balign 16\n"                                                                                         \
index 4d3792e..e7fe944 100644 (file)
@@ -26,13 +26,6 @@ struct extable_ip_fixup {
        uint64_t fixup;
 };
 
        uint64_t fixup;
 };
 
-#define _ASM_EXTABLE_INIT()                                                                            \
-       asm volatile(                                                                                           \
-       " .pushsection \"__ex_table\",\"a\"\n"                                          \
-       " .balign 16\n"                                                                                         \
-       " .popsection\n"                                                                                        \
-       : :)
-
 #define _ASM_EXTABLE(from, to)                                                                 \
        " .pushsection \"__ex_table\",\"a\"\n"                                          \
        " .balign 16\n"                                                                                         \
 #define _ASM_EXTABLE(from, to)                                                                 \
        " .pushsection \"__ex_table\",\"a\"\n"                                          \
        " .balign 16\n"                                                                                         \
index b8a5d2b..079f951 100644 (file)
  * ruled by the overall Linux copyright.
  */
 
  * ruled by the overall Linux copyright.
  */
 
-#include <ex_table.h>
 #include <arch/uaccess.h>
 #include <arch/uaccess.h>
+#include <compiler.h>
 #include <sort.h>
 #include <sort.h>
+#include <ex_table.h>
 
 
-extern struct extable_ip_fixup __start___ex_table;
-extern struct extable_ip_fixup __stop___ex_table;
+extern struct extable_ip_fixup __attribute__((weak)) __start___ex_table[];
+extern struct extable_ip_fixup __attribute__((weak)) __stop___ex_table[];
 
 static int fixup_cmp(const void *f1, const void *f2)
 {
 
 static int fixup_cmp(const void *f1, const void *f2)
 {
@@ -25,48 +26,48 @@ static int fixup_cmp(const void *f1, const void *f2)
 
 void exception_table_init(void)
 {
 
 void exception_table_init(void)
 {
-       struct extable_ip_fixup *first = &__start___ex_table;
-       struct extable_ip_fixup *last = &__stop___ex_table;
-       uint64_t offset = 0;
+       if (__start___ex_table) {
+               struct extable_ip_fixup *first = __start___ex_table;
+               struct extable_ip_fixup *last = __stop___ex_table;
+               uint64_t offset = 0;
 
 
-       for (struct extable_ip_fixup *fx = first; fx < last; fx++) {
-               fx->insn += offset;
-               offset += sizeof(fx->insn);
-               fx->fixup += offset;
-               offset += sizeof(fx->fixup);
-       }
+               for (struct extable_ip_fixup *fx = first; fx < last; fx++) {
+                       fx->insn += offset;
+                       offset += sizeof(fx->insn);
+                       fx->fixup += offset;
+                       offset += sizeof(fx->fixup);
+               }
 
 
-       sort(first, last - first, sizeof(*first), fixup_cmp);
+               sort(first, last - first, sizeof(*first), fixup_cmp);
 
 
-       offset = 0;
-       for (struct extable_ip_fixup *fx = first; fx < last; fx++) {
-               fx->insn -= offset;
-               offset += sizeof(fx->insn);
-               fx->fixup -= offset;
-               offset += sizeof(fx->fixup);
+               offset = 0;
+               for (struct extable_ip_fixup *fx = first; fx < last; fx++) {
+                       fx->insn -= offset;
+                       offset += sizeof(fx->insn);
+                       fx->fixup -= offset;
+                       offset += sizeof(fx->fixup);
+               }
        }
        }
-
-       /* Avoid undefined __start___ex_table and __stop___ex_table errors when
-        * no code is using the exception table facility.
-        */
-       _ASM_EXTABLE_INIT();
 }
 
 uintptr_t get_fixup_ip(uintptr_t xip)
 {
 }
 
 uintptr_t get_fixup_ip(uintptr_t xip)
 {
-       const struct extable_ip_fixup *first = &__start___ex_table;
-       const struct extable_ip_fixup *last = &__stop___ex_table;
+       const struct extable_ip_fixup *first = __start___ex_table;
+
+       if (likely(first)) {
+               const struct extable_ip_fixup *last = __stop___ex_table;
 
 
-       while (first <= last) {
-               const struct extable_ip_fixup *x = first + ((last - first) >> 1);
-               uintptr_t insn = ex_insn_addr(x);
+               while (first <= last) {
+                       const struct extable_ip_fixup *x = first + ((last - first) >> 1);
+                       uintptr_t insn = ex_insn_addr(x);
 
 
-               if (insn < xip)
-                       first = x + 1;
-               else if (insn > xip)
-                       last = x - 1;
-               else
-                       return (uintptr_t) ex_fixup_addr(x);
+                       if (insn < xip)
+                               first = x + 1;
+                       else if (insn > xip)
+                               last = x - 1;
+                       else
+                               return (uintptr_t) ex_fixup_addr(x);
+               }
        }
 
        return 0;
        }
 
        return 0;