[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 3/6] plat: prepare linker script for thread-local storage



Aggregate all .tdata and .tbss variables in the correct sections, and
define global variables that point at section beginning and end.

Note that because the .tbss section is zero-size in the ELF file, just
setting _tls_end to the end of it doesn't give us the the size of the
memory area once loaded, so we use SIZEOF to have it point to the end.

Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 plat/common/include/common.lds.h | 19 +++++++++++++++++++
 plat/common/include/sections.h   |  5 +++++
 plat/kvm/x86/link64.lds.S        |  2 ++
 plat/linuxu/x86/link64.lds       | 23 +++++++++++++++++++++++
 plat/xen/x86/link64.lds.S        |  2 ++
 5 files changed, 51 insertions(+)

diff --git a/plat/common/include/common.lds.h b/plat/common/include/common.lds.h
index ea030d9e..9b3cec02 100644
--- a/plat/common/include/common.lds.h
+++ b/plat/common/include/common.lds.h
@@ -93,4 +93,23 @@
        LONG(0)                                                         \
        }
 
+#define TLS_SECTIONS                                                   \
+       . = ALIGN(0x8);                                                 \
+       _tls_start = .;                                                 \
+       .tdata :                                                        \
+       {                                                               \
+               *(.tdata)                                               \
+               *(.tdata.*)                                             \
+               *(.gnu.linkonce.td.*)                                   \
+       }                                                               \
+       _etdata = .;                                                    \
+       .tbss :                                                         \
+       {                                                               \
+               *(.tbss)                                                \
+               *(.tbss.*)                                              \
+               *(.gnu.linkonce.tb.*)                                   \
+       }                                                               \
+       . = ALIGN(0x8);                                                 \
+       _tls_end = . + SIZEOF(.tbss);
+
 #endif /* __UK_COMMON_LDS_H */
diff --git a/plat/common/include/sections.h b/plat/common/include/sections.h
index 1052cfc7..a2677ce8 100644
--- a/plat/common/include/sections.h
+++ b/plat/common/include/sections.h
@@ -63,6 +63,11 @@ extern char _data[], _edata[];
 /* [_ctors, _ectors]: contains constructor tables (read-only) */
 extern char _ctors[], _ectors[];
 
+/* [_tls_start, _tls_end]: contains .tdata.* and .tbss.* sections */
+extern char _tls_start[], _tls_end[];
+/* _etdata: denotes end of .tdata (and start of .tbss */
+extern char _etdata[];
+
 /* __bss_start: start of BSS sections */
 extern char __bss_start[];
 
diff --git a/plat/kvm/x86/link64.lds.S b/plat/kvm/x86/link64.lds.S
index 011e6232..362ba3e6 100644
--- a/plat/kvm/x86/link64.lds.S
+++ b/plat/kvm/x86/link64.lds.S
@@ -76,6 +76,8 @@ SECTIONS
        }
        _ectors = .;
 
+       TLS_SECTIONS
+
        /* Read-write data (initialized) */
        . = ALIGN(__PAGE_SIZE);
        _data = .;
diff --git a/plat/linuxu/x86/link64.lds b/plat/linuxu/x86/link64.lds
index aa239a0d..e6ab00b5 100644
--- a/plat/linuxu/x86/link64.lds
+++ b/plat/linuxu/x86/link64.lds
@@ -28,3 +28,26 @@ SECTIONS
 }
 INSERT AFTER .rodata
 
+SECTIONS
+{
+       /* TODO: include these from common-lds.h */
+       . = ALIGN(0x8);
+       _tls_start = .;
+       .tdata :
+       {
+               *(.tdata)
+               *(.tdata.*)
+               *(.gnu.linkonce.td.*)
+       }
+       _etdata = .;
+       .tbss :
+       {
+               *(.tbss)
+               *(.tbss.*)
+               *(.gnu.linkonce.tb.*)
+               . = ALIGN(0x8);
+       }
+       _tls_end = . + SIZEOF(.tbss);
+}
+
+INSERT BEFORE .data
diff --git a/plat/xen/x86/link64.lds.S b/plat/xen/x86/link64.lds.S
index ff69f830..f7e53fe6 100644
--- a/plat/xen/x86/link64.lds.S
+++ b/plat/xen/x86/link64.lds.S
@@ -72,6 +72,8 @@ SECTIONS
        . = ALIGN(__PAGE_SIZE);
        _ectors = .;
 
+       TLS_SECTIONS
+
        /* Data */
        _data = .;
        .data : {
-- 
2.21.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.