Changeset 2c4e1cc in mainline for uspace/lib/c/generic/tls.c


Ignore:
Timestamp:
2018-04-04T17:01:18Z (7 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5754c31e
Parents:
1433ecda
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-04-03 16:54:34)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-04-04 17:01:18)
Message:

Define TLS consistently in linker scripts, and remove nonstandard symbols.

Read the program header to find TLS instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/tls.c

    r1433ecda r2c4e1cc  
    4141#include <stdlib.h>
    4242#include <str.h>
     43#include <elf/elf.h>
    4344
    4445#ifdef CONFIG_RTLD
     
    5253                return runtime_env->tls_size;
    5354#endif
    54         return &_tbss_end - &_tdata_start;
     55
     56        const elf_segment_header_t *tls =
     57            elf_get_phdr(__executable_start, PT_TLS);
     58        return tls->p_memsz;
    5559}
    5660
     
    7377        void *data;
    7478        tcb_t *tcb;
    75         size_t tls_size = &_tbss_end - &_tdata_start;
    7679
    7780#ifdef CONFIG_RTLD
     
    8083#endif
    8184
    82         tcb = tls_alloc_arch(&data, tls_size);
    83         if (!tcb)
     85        const elf_segment_header_t *tls =
     86            elf_get_phdr(__executable_start, PT_TLS);
     87        if (tls == NULL)
    8488                return NULL;
     89
     90        uintptr_t bias = elf_get_bias(__executable_start);
     91
     92        tcb = tls_alloc_arch(&data, tls->p_memsz);
    8593
    8694        /*
    8795         * Copy thread local data from the initialization image.
    8896         */
    89         memcpy(data, &_tdata_start, &_tdata_end - &_tdata_start);
     97        memcpy(data, (void *)(tls->p_vaddr + bias), tls->p_filesz);
    9098        /*
    9199         * Zero out the thread local uninitialized data.
    92100         */
    93         memset(data + (&_tbss_start - &_tdata_start), 0,
    94             &_tbss_end - &_tbss_start);
     101        memset(data + tls->p_filesz, 0, tls->p_memsz - tls->p_filesz);
    95102
    96103        return tcb;
     
    151158        tcb_t *tcb;
    152159
    153         size = ALIGN_UP(size, &_tls_alignment);
    154         *data = memalign((uintptr_t) &_tls_alignment, sizeof(tcb_t) + size);
     160        uintptr_t align = elf_get_phdr(__executable_start, PT_TLS)->p_align;
     161
     162        size = ALIGN_UP(size, align);
     163        *data = memalign(align, sizeof(tcb_t) + size);
    155164        if (*data == NULL)
    156165                return NULL;
     
    171180void tls_free_variant_2(tcb_t *tcb, size_t size)
    172181{
    173         size = ALIGN_UP(size, &_tls_alignment);
     182        uintptr_t align = elf_get_phdr(__executable_start, PT_TLS)->p_align;
     183        size = ALIGN_UP(size, align);
    174184        void *start = ((void *) tcb) - size;
    175185        free(start);
Note: See TracChangeset for help on using the changeset viewer.