implements proper linker script to support TLS
This change updates the linker script and dependend wile so that thread local storage sections are properly supported and initailaized
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <picotls.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN_C extern "C"
|
||||
@@ -24,6 +25,12 @@ EXTERN_C uint8_t __bss_end;
|
||||
EXTERN_C const uint8_t __data_source;
|
||||
EXTERN_C uint8_t __data_start;
|
||||
EXTERN_C uint8_t __data_end;
|
||||
EXTERN_C const uint8_t __data_source;
|
||||
EXTERN_C uint8_t __tbss_start;
|
||||
EXTERN_C uintptr_t __tbss_size;
|
||||
EXTERN_C const uint8_t __tdata_source;
|
||||
EXTERN_C uint8_t __tls_base;
|
||||
EXTERN_C uintptr_t __tdata_size;
|
||||
|
||||
EXTERN_C function_t __init_array_start;
|
||||
EXTERN_C function_t __init_array_end;
|
||||
@@ -32,10 +39,10 @@ EXTERN_C function_t __fini_array_end;
|
||||
|
||||
// This function will be placed by the linker script according to the section
|
||||
// Raw function 'called' by the CPU with no runtime.
|
||||
EXTERN_C void _start(void) __attribute__ ((naked,section(".text.init")));
|
||||
EXTERN_C void _start(void) __attribute__ ((naked,section(".text.boot")));
|
||||
|
||||
// Entry and exit points as C functions.
|
||||
EXTERN_C void _initialize(void) __attribute__ ((noreturn,section(".init")));
|
||||
EXTERN_C void _initialize(void) __attribute__ ((noreturn,section(".text.boot")));
|
||||
EXTERN_C void _exit(int exit_code) __attribute__ ((noreturn,noinline,weak));
|
||||
|
||||
// Standard entry point, no arguments.
|
||||
@@ -68,19 +75,22 @@ void _start(void) {
|
||||
void _initialize(void) {
|
||||
// Init memory regions
|
||||
// Clear the .bss section (global variables with no initial values)
|
||||
memset((void*) &__bss_start,
|
||||
0,
|
||||
(&__bss_end - &__bss_start));
|
||||
memset((void*) &__bss_start, 0, (&__bss_end - &__bss_start));
|
||||
// Initialize the .data section (global variables with initial values)
|
||||
memcpy((void*)&__data_start,
|
||||
(const void*)&__data_source,
|
||||
(&__data_end - &__data_end));
|
||||
memcpy((void*)&__data_start, (const void*)&__data_source, (&__data_end - &__data_start));
|
||||
// Clear the .tbss section (thread local variables with no initial values)
|
||||
memset((void*) &__tbss_start, 0, __tbss_size);
|
||||
// Initialize the .tls section (thread local variables with initial values)
|
||||
memcpy((void*) &__tls_base, (const void*)&__tdata_source, __tdata_size);
|
||||
// Call constructors
|
||||
for (const function_t* entry=&__init_array_start;
|
||||
entry < &__init_array_end;
|
||||
++entry) {
|
||||
(*entry)();
|
||||
}
|
||||
#ifdef __THREAD_LOCAL_STORAGE
|
||||
_set_tls(__tls_base)
|
||||
#endif
|
||||
int rc = main();
|
||||
// Call destructors
|
||||
for (const function_t* entry=&__fini_array_start;
|
||||
|
||||
Reference in New Issue
Block a user