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
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:
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.
.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 = .;