Changeset e996050 in mainline


Ignore:
Timestamp:
2025-01-30T10:41:55Z (23 hours ago)
Author:
GitHub <noreply@…>
Parents:
56210a7 (diff), bdcf71e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Matěj Volf <mat.volfik@…> (2025-01-30 10:41:55)
git-committer:
GitHub <noreply@…> (2025-01-30 10:41:55)
Message:

Merge bdcf71e7108c1065465bbc29a3666276eef4f7a4 into 56210a7aca94cc904bb253efade72fb9a4cc1a40

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/dltest/dltest.c

    r56210a7 re996050  
    944944                return 1;
    945945
    946 #ifndef STATIC_EXE
     946#ifndef STATIC_EXE // FIXME: this define is not set anywhere
    947947
    948948        if (!test_dlfcn_dl_get_private_fib_var())
  • uspace/lib/c/generic/elf/elf_load.c

    r56210a7 re996050  
    6060        rtld_t *env;
    6161#endif
    62         errno_t rc;
     62        errno_t rc = EOK;
     63        elf_finfo_t *finfo = &info->finfo;
    6364
    64         rc = elf_load_file(file, 0, &info->finfo);
     65        rc = elf_load_file(file, 0, finfo);
    6566        if (rc != EOK) {
    6667                DPRINTF("Failed to load executable '%s'.\n", file_name);
     
    7273                DPRINTF("Binary is statically linked.\n");
    7374                info->env = NULL;
     75#ifdef CONFIG_RTLD
     76                rc = rtld_init_static(finfo, &env);
     77                info->env = env;
     78#endif
    7479                return EOK;
    7580        }
     
    7782        DPRINTF("Binary is dynamically linked.\n");
    7883#ifdef CONFIG_RTLD
    79         DPRINTF("- prog dynamic: %p\n", info->finfo.dynamic);
    80 
    81         rc = rtld_prog_process(&info->finfo, &env);
     84        DPRINTF("- prog dynamic: %p\n", finfo->dynamic);
     85        rc = rtld_prog_process(finfo, &env);
    8286        info->env = env;
    8387#else
  • uspace/lib/c/generic/libc.c

    r56210a7 re996050  
    9696
    9797#ifdef CONFIG_RTLD
    98         if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
     98        if (__pcb == NULL) {
     99                /*
     100                 * A binary loaded by kernel, not the loader.
     101                 * Noop - code loaded by kernel doesn't need RTLD.
     102                 */
     103        } else {
     104                assert(__pcb->rtld_runtime != NULL);
    99105                runtime_env = (rtld_t *) __pcb->rtld_runtime;
    100         } else {
    101                 if (rtld_init_static() != EOK)
    102                         abort();
    103106        }
    104107#endif
  • uspace/lib/c/generic/rtld/module.c

    r56210a7 re996050  
    6161 * @return EOK on success, ENOMEM if out of memory
    6262 */
    63 errno_t module_create_static_exec(rtld_t *rtld, module_t **rmodule)
     63errno_t module_create_static_exec(const void *elf, rtld_t *rtld)
    6464{
    6565        module_t *module;
     
    7979
    8080        const elf_segment_header_t *tls =
    81             elf_get_phdr(__progsymbols.elfstart, PT_TLS);
     81            elf_get_phdr(elf, PT_TLS);
    8282
    8383        if (tls) {
    84                 uintptr_t bias = elf_get_bias(__progsymbols.elfstart);
     84                uintptr_t bias = elf_get_bias(elf);
    8585                module->tdata = (void *) (tls->p_vaddr + bias);
    8686                module->tdata_size = tls->p_filesz;
     
    9595
    9696        list_append(&module->modules_link, &rtld->modules);
    97 
    98         if (rmodule != NULL)
    99                 *rmodule = module;
    10097        return EOK;
    10198}
  • uspace/lib/c/generic/rtld/rtld.c

    r56210a7 re996050  
    4343
    4444rtld_t *runtime_env;
    45 static rtld_t rt_env_static;
    4645
    4746/** Initialize the runtime linker for use in a statically-linked executable. */
    48 errno_t rtld_init_static(void)
    49 {
     47errno_t rtld_init_static(elf_finfo_t *finfo, rtld_t **rre)
     48{
     49        rtld_t *env;
    5050        errno_t rc;
    5151
    52         runtime_env = &rt_env_static;
    53         list_initialize(&runtime_env->modules);
    54         list_initialize(&runtime_env->imodules);
    55         runtime_env->program = NULL;
    56         runtime_env->next_id = 1;
    57 
    58         rc = module_create_static_exec(runtime_env, NULL);
     52        env = calloc(1, sizeof(rtld_t));
     53        if (env == NULL)
     54                return ENOMEM;
     55
     56        list_initialize(&env->modules);
     57        list_initialize(&env->imodules);
     58        env->program = NULL;
     59        env->next_id = 1;
     60
     61        rc = module_create_static_exec(finfo->base, env);
    5962        if (rc != EOK)
    6063                return rc;
    6164
    62         modules_process_tls(runtime_env);
    63 
     65        modules_process_tls(env);
     66
     67        *rre = env;
    6468        return EOK;
    6569}
     
    127131        errno_t rc = module_load_deps(prog, 0);
    128132        if (rc != EOK) {
     133                free(prog);
     134                free(env);
    129135                return rc;
    130136        }
  • uspace/lib/c/generic/thread/tls.c

    r56210a7 re996050  
    7474}
    7575
    76 /** Get address of static TLS block */
     76/** Get address of static TLS block - only when RTLD is not initialized  */
    7777void *tls_get(void)
    7878{
  • uspace/lib/c/include/rtld/module.h

    r56210a7 re996050  
    4141#include <types/rtld/rtld.h>
    4242
    43 extern errno_t module_create_static_exec(rtld_t *, module_t **);
     43extern errno_t module_create_static_exec(const void *, rtld_t *);
    4444extern void module_process_relocs(module_t *);
    4545extern module_t *module_find(rtld_t *, const char *);
  • uspace/lib/c/include/rtld/rtld.h

    r56210a7 re996050  
    4545extern rtld_t *runtime_env;
    4646
    47 extern errno_t rtld_init_static(void);
     47extern errno_t rtld_init_static(elf_finfo_t *, rtld_t **);
    4848extern errno_t rtld_prog_process(elf_finfo_t *, rtld_t **);
    4949extern tcb_t *rtld_tls_make(rtld_t *);
  • uspace/srv/loader/main.c

    r56210a7 re996050  
    300300
    301301#ifdef CONFIG_RTLD
    302         if (prog_info.env) {
    303                 pcb.tcb = rtld_tls_make(prog_info.env);
    304         } else {
    305                 pcb.tcb = tls_make(prog_info.finfo.base);
    306         }
     302        assert(prog_info.env != NULL);
     303        pcb.tcb = rtld_tls_make(prog_info.env);
    307304#else
    308305        pcb.tcb = tls_make(prog_info.finfo.base);
Note: See TracChangeset for help on using the changeset viewer.