aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2014-12-13 03:53:49 -0800
committerAndrew Waterman <waterman@cs.berkeley.edu>2014-12-13 03:54:07 -0800
commit74c924f975b966f4c7b67bae135548dc837ae299 (patch)
treef3681ef6eba0e1d6bab12d004fbe81b6b61b1901
parent984abbe6e67503c93dbb13d9a305960f11c4ba7b (diff)
downloadriscv-tests-74c924f975b966f4c7b67bae135548dc837ae299.zip
riscv-tests-74c924f975b966f4c7b67bae135548dc837ae299.tar.gz
riscv-tests-74c924f975b966f4c7b67bae135548dc837ae299.tar.bz2
Initialize static TLS for the benchmarks
-rw-r--r--benchmarks/common/crt.S20
-rw-r--r--benchmarks/common/syscalls.c12
-rw-r--r--benchmarks/common/test.ld13
3 files changed, 33 insertions, 12 deletions
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 = .;