Browse Source

[PAL] Rewrite the code which potentially generates incorrect assembly for assigning signal handler return address

Li Lei 5 years ago
parent
commit
6b17075687
2 changed files with 12 additions and 6 deletions
  1. 6 3
      Pal/src/host/Linux-SGX/sgx_exception.c
  2. 6 3
      Pal/src/host/Linux/db_exception.c

+ 6 - 3
Pal/src/host/Linux-SGX/sgx_exception.c

@@ -57,8 +57,6 @@
  *     }
  */
 
-void restore_rt (void) __asm__ ("__restore_rt");
-
 #ifndef SA_RESTORER
 #define SA_RESTORER  0x04000000
 #endif
@@ -75,6 +73,11 @@ void restore_rt (void) __asm__ ("__restore_rt");
          "    syscall\n");
 
 DEFINE_RESTORE_RT(__NR_rt_sigreturn)
+
+/* Workaround for fixing an old GAS (2.27) bug that incorrectly
+ * omits relocations when referencing this symbol */
+__attribute__((visibility("hidden"))) void __restore_rt(void);
+
 #endif
 
 int set_sighandler (int * sigs, int nsig, void * handler)
@@ -85,7 +88,7 @@ int set_sighandler (int * sigs, int nsig, void * handler)
 
 #if !defined(__i386__)
     action.sa_flags |= SA_RESTORER;
-    action.sa_restorer = restore_rt;
+    action.sa_restorer = __restore_rt;
 #endif
 
     __sigemptyset((__sigset_t *) &action.sa_mask);

+ 6 - 3
Pal/src/host/Linux/db_exception.c

@@ -54,8 +54,6 @@
  *     }
  */
 
-void restore_rt (void) __asm__ ("__restore_rt");
-
 #ifndef SA_RESTORER
 #define SA_RESTORER  0x04000000
 #endif
@@ -72,6 +70,11 @@ void restore_rt (void) __asm__ ("__restore_rt");
          "    syscall\n");
 
 DEFINE_RESTORE_RT(__NR_rt_sigreturn)
+
+/* Workaround for an old GAS (2.27) bug that incorrectly
+ * omits relocations when referencing this symbol */
+__attribute__((visibility("hidden"))) void __restore_rt(void);
+
 #endif
 
 int set_sighandler (int * sigs, int nsig, void * handler)
@@ -83,7 +86,7 @@ int set_sighandler (int * sigs, int nsig, void * handler)
         action.sa_flags = SA_SIGINFO;
 #if !defined(__i386__)
         action.sa_flags |= SA_RESTORER;
-        action.sa_restorer = restore_rt;
+        action.sa_restorer = __restore_rt;
 #endif
     } else {
         action.sa_flags = 0x0u;