Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d3e938c in mainline


Ignore:
Timestamp:
2019-01-08T13:27:05Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
05cb995, 1567471, 1aa9eff, cdec2a1
Parents:
9c4df21
git-author:
Jiri Svoboda <jiri@…> (2018-01-07 22:27:02)
git-committer:
Jiri Svoboda <jiri@…> (2019-01-08 13:27:05)
Message:

Dynamic linking on amd64 (WIP)

After modifying HelenOS.config, it is possible to build with dynamic
linking support, but an attempt to load a shared library will fail.

Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • abi/include/abi/asmtool.h

    r9c4df21 rd3e938c  
    5656        SYMBOL_END(func)
    5757
     58#ifdef __PIC__
     59#define FUNCTION_REF(func) func@PLT
     60#else
     61#define FUNCTION_REF(func) func
     62#endif
     63
    5864#endif
    5965
  • uspace/lib/c/arch/amd64/Makefile.inc

    r9c4df21 rd3e938c  
    3434        arch/$(UARCH)/src/tls.c \
    3535        arch/$(UARCH)/src/stacktrace.c \
    36         arch/$(UARCH)/src/stacktrace_asm.S
     36        arch/$(UARCH)/src/stacktrace_asm.S \
     37        arch/$(UARCH)/src/rtld/dynamic.c \
     38        arch/$(UARCH)/src/rtld/reloc.c
    3739
    3840ARCH_AUTOCHECK_HEADERS = \
  • uspace/lib/c/arch/amd64/include/libarch/tls.h

    r9c4df21 rd3e938c  
    4545        void *self;
    4646        void *fibril_data;
     47        void **dtv;
     48        void *pad;
    4749} tcb_t;
    4850
  • uspace/lib/c/arch/amd64/src/entry.S

    r9c4df21 rd3e938c  
    4747        # %rdi was deliberately chosen as the first argument is also in %rdi
    4848        # Pass PCB pointer to __c_start (no operation)
    49         call __c_start
     49        call FUNCTION_REF(__c_start)
  • uspace/lib/c/arch/amd64/src/thread_entry.S

    r9c4df21 rd3e938c  
    4646        #
    4747        movq %rax, %rdi
    48         call __thread_main
     48        call FUNCTION_REF(__thread_main)
    4949SYMBOL_END(__thread_entry)
  • uspace/lib/c/arch/amd64/src/tls.c

    r9c4df21 rd3e938c  
    3838#include <stddef.h>
    3939
     40#ifdef CONFIG_RTLD
     41#include <rtld/rtld.h>
     42#endif
     43
    4044tcb_t *tls_alloc_arch(size_t size, size_t align)
    4145{
     
    4852}
    4953
     54/*
     55 * Rtld TLS support
     56 */
     57
     58typedef struct {
     59        unsigned long int ti_module;
     60        unsigned long int ti_offset;
     61} tls_index;
     62
     63void __attribute__((__regparm__(1)))
     64    *__tls_get_addr(tls_index *ti);
     65
     66void __attribute__((__regparm__(1)))
     67    *__tls_get_addr(tls_index *ti)
     68{
     69        uint8_t *tls;
     70
     71#ifdef CONFIG_RTLD
     72        if (runtime_env != NULL) {
     73                return rtld_tls_get_addr(runtime_env, __tcb_get(),
     74                    ti->ti_module, ti->ti_offset);
     75        }
     76#endif
     77        /* Get address of static TLS block */
     78        tls = tls_get();
     79        return tls + ti->ti_offset;
     80}
     81
    5082/** @}
    5183 */
  • uspace/lib/c/generic/rtld/dynamic.c

    r9c4df21 rd3e938c  
    6464                d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
    6565                d_val = dp->d_un.d_val;
    66                 DPRINTF("tag=%u ptr=0x%x val=%u\n", (unsigned)dp->d_tag,
    67                     (unsigned)d_ptr, (unsigned)d_val);
     66                DPRINTF("tag=%u ptr=0x%zx val=%zu\n", (unsigned)dp->d_tag,
     67                    (uintptr_t)d_ptr, (uintptr_t)d_val);
    6868
    6969                switch (dp->d_tag) {
  • uspace/lib/c/include/rtld/elf_dyn.h

    r9c4df21 rd3e938c  
    3939#include <libarch/rtld/elf_dyn.h>
    4040
    41 #define ELF32_R_SYM(i) ((i)>>8)
     41#define ELF32_R_SYM(i) ((i) >> 8)
    4242#define ELF32_R_TYPE(i) ((unsigned char)(i))
     43
     44#define ELF64_R_SYM(i) ((i) >> 32)
     45#define ELF64_R_TYPE(i) ((i) & 0xffffffffL)
    4346
    4447struct elf32_dyn {
     
    4750                elf_word d_val;
    4851                elf32_addr d_ptr;
     52        } d_un;
     53};
     54
     55struct elf64_dyn {
     56        elf_sxword d_tag;
     57        union {
     58                elf_xword d_val;
     59                elf64_addr d_ptr;
    4960        } d_un;
    5061};
     
    6172};
    6273
     74struct elf64_rel {
     75        elf64_addr r_offset;
     76        elf_xword r_info;
     77};
     78
     79struct elf64_rela {
     80        elf64_addr r_offset;
     81        elf_xword r_info;
     82        elf_sxword r_addend;
     83};
     84
    6385#ifdef __32_BITS__
    6486typedef struct elf32_dyn elf_dyn_t;
    6587typedef struct elf32_rel elf_rel_t;
    6688typedef struct elf32_rela elf_rela_t;
     89#endif
     90
     91#ifdef __64_BITS__
     92typedef struct elf64_dyn elf_dyn_t;
     93typedef struct elf64_rel elf_rel_t;
     94typedef struct elf64_rela elf_rela_t;
    6795#endif
    6896
Note: See TracChangeset for help on using the changeset viewer.