As described in the issue #1122, both tst-promise.so and tst-async.so
fail with null pointer execution page fault crash. Both test apps
access '__once_callable' and '__once_call' TLS variables that are part
of C++ library and given it is linked as part of the kernel we must
make sure TLS_DESC relocation logic handles this case correctly.
So this patch changes the logic to handle relocations of ARCH_TLSDESC,
so that the symbols found in the kernel are accessed using correct kernel
block offsets just like PIEs are.

On top of above, this patch also fixes the relocation logic of 
R_AARCH64_TLS_TPREL64
that happens in get_init() during early boot to make sure that the TLS
offset for relevant variables (__once_call in this case) is adjusted for
the size of thread_control_block structure. This is essential to make
sure that the __once_proxy function (see assembly below) calling __once_call 
variable
using an offset stored in GOT works correctly.

```
__once_proxy:
   0x000000004041df50 <+0>:     stp     x29, x30, [sp, #-16]!
   0x000000004041df54 <+4>:     mrs     x1, tpidr_el0
   0x000000004041df58 <+8>:     mov     x29, sp
   0x000000004041df5c <+12>:    adrp    x0, 0x40098000
   0x000000004041df60 <+16>:    ldr     x0, [x0, #2608] //Accesses
offset of __once_call in GOT which is set by arch_init_reloc_dyn()
   0x000000004041df64 <+20>:    nop
   0x000000004041df68 <+24>:    nop
   0x000000004041df6c <+28>:    ldp     x29, x30, [sp], #16
   0x000000004041df70 <+32>:    ldr     x0, [x1, x0]
   0x000000004041df74 <+36>:    mov     x16, x0
   0x000000004041df78 <+40>:    br      x16
```

Fixes #1122

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 arch/aarch64/arch-elf.cc | 4 ++--
 scripts/test.py          | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/aarch64/arch-elf.cc b/arch/aarch64/arch-elf.cc
index 39a9b6aa..091517f1 100644
--- a/arch/aarch64/arch-elf.cc
+++ b/arch/aarch64/arch-elf.cc
@@ -29,7 +29,7 @@ bool arch_init_reloc_dyn(struct init_table *t, u32 type, u32 
sym,
         *static_cast<u64*>(addr) = t->dyn_tabs.lookup(sym)->st_value + addend;
         break;
     case R_AARCH64_TLS_TPREL64:
-        *static_cast<u64*>(addr) = t->dyn_tabs.lookup(sym)->st_value + addend;
+        *static_cast<u64*>(addr) = t->dyn_tabs.lookup(sym)->st_value + addend 
+ sizeof(thread_control_block);
         break;
     default:
         return false;
@@ -116,7 +116,7 @@ void object::arch_relocate_tls_desc(u32 sym, void *addr, 
Elf64_Sxword addend)
     ulong tls_offset;
     if (sym) {
         auto sm = symbol(sym);
-        if (sm.obj->is_executable()) {
+        if (sm.obj->is_executable() || sm.obj->is_core()) {
             // If this is an executable (pie or position-dependant one)
             // then the variable is located in the reserved slot of the TLS
             // right where the kernel TLS lives
diff --git a/scripts/test.py b/scripts/test.py
index 24ae964b..f3856e4e 100755
--- a/scripts/test.py
+++ b/scripts/test.py
@@ -41,8 +41,6 @@ aarch64_disabled_list= [
     "java_no_wrapper",
     "java-perms",
     #Following tests crash with message 'Assertion failed: type == 
ARCH_JUMP_SLOT (core/elf.cc: relocate_pltgot: 789)'
-    "tst-async.so",
-    "tst-promise.so",
     "tst-sigaltstack.so",
     #Remaining tests below fail for various different reasons
     #Please see comments on the right side for more details
-- 
2.29.2

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20210226185716.268787-1-jwkozaczuk%40gmail.com.

Reply via email to