From: Andrew Waterman Date: Sat, 13 Dec 2014 11:53:49 +0000 (-0800) Subject: Initialize static TLS for the benchmarks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=74c924f975b966f4c7b67bae135548dc837ae299;p=riscv-tests.git Initialize static TLS for the benchmarks --- diff --git a/benchmarks/common/crt.S b/benchmarks/common/crt.S index 2c004d1..cce3140 100644 --- a/benchmarks/common/crt.S +++ b/benchmarks/common/crt.S @@ -114,13 +114,6 @@ _start: sll sp, sp, STKSHIFT add sp, sp, tp - # offset thread pointer by thread pointer bias - lui t0, %tprel_hi(tls_start) - add t0, t0, tp, %tprel_add(tls_start) - add t0, t0, %tprel_lo(tls_start) - sub t0, t0, tp - sub tp, tp, t0 - la t0, _init csrw epc, t0 sret @@ -211,5 +204,14 @@ trap_entry: addi sp, sp, 272 sret -.section .tbss -tls_start: +.section ".tdata.begin" +.globl _tdata_begin +_tdata_begin: + +.section ".tdata.end" +.globl _tdata_end +_tdata_end: + +.section ".tbss.end" +.globl _tbss_end +_tbss_end: diff --git a/benchmarks/common/syscalls.c b/benchmarks/common/syscalls.c index ddbb795..1e4efab 100644 --- a/benchmarks/common/syscalls.c +++ b/benchmarks/common/syscalls.c @@ -125,8 +125,20 @@ int __attribute__((weak)) main(int argc, char** argv) return -1; } +static void init_tls() +{ + register void* thread_pointer asm("tp"); + extern char _tls_data; + extern __thread char _tdata_begin, _tdata_end, _tbss_end; + size_t tdata_size = &_tdata_end - &_tdata_begin; + memcpy(thread_pointer, &_tls_data, tdata_size); + size_t tbss_size = &_tbss_end - &_tdata_end; + memset(thread_pointer + tdata_size, 0, tbss_size); +} + void _init(int cid, int nc) { + init_tls(); thread_entry(cid, nc); // only single-threaded programs should ever get here. diff --git a/benchmarks/common/test.ld b/benchmarks/common/test.ld index dda2a7f..438581c 100644 --- a/benchmarks/common/test.ld +++ b/benchmarks/common/test.ld @@ -38,11 +38,18 @@ SECTIONS .bss : { *(.bss) } /* thread-local data segment */ - .tbss : { - crt.o(.tbss) /* Make sure tls_start is the first TLS symbol */ + .tdata : + { + _tls_data = .; + crt.o(.tdata.begin) + *(.tdata) + crt.o(.tdata.end) + } + .tbss : + { *(.tbss) + crt.o(.tbss.end) } - .tdata : { *(.tdata) } /* End of uninitalized data segement */ _end = .;