Changeset a6dffb8 in mainline


Ignore:
Timestamp:
2011-04-28T18:56:01Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b40a3b6
Parents:
b678410
Message:

Fold dynamic loading functionality into loader. This eliminates dload binary
and the extra loading stage.

Location:
uspace
Files:
11 deleted
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    rb678410 ra6dffb8  
    3535DIRS = \
    3636        app/bdsh \
    37         app/dload \
    3837        app/dltest2 \
    3938        app/edit \
  • uspace/lib/c/rtld/arch/ia32/src/reloc.c

    rb678410 ra6dffb8  
    4141#include <symbol.h>
    4242#include <rtld.h>
     43#include <rtld_debug.h>
    4344
    4445#include <rtld_arch.h>
  • uspace/lib/c/rtld/arch/mips32/src/reloc.c

    rb678410 ra6dffb8  
    4141#include <symbol.h>
    4242#include <rtld.h>
     43#include <rtld_debug.h>
    4344
    4445#include <rtld_arch.h>
  • uspace/lib/c/rtld/arch/ppc32/src/reloc.c

    rb678410 ra6dffb8  
    4141#include <symbol.h>
    4242#include <rtld.h>
     43#include <rtld_debug.h>
    4344#include <smc.h>
    4445
  • uspace/lib/c/rtld/dynamic.c

    rb678410 ra6dffb8  
    4141#include <dynamic.h>
    4242#include <rtld.h>
     43#include <rtld_debug.h>
    4344
    4445void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info)
  • uspace/lib/c/rtld/include/rtld.h

    rb678410 ra6dffb8  
    4242#include <module.h>
    4343
    44 /* Define to enable debugging mode. */
    45 #undef RTLD_DEBUG
    46 
    47 #ifdef RTLD_DEBUG
    48         #define DPRINTF(format, ...) printf(format, ##__VA_ARGS__)
    49 #else
    50         #define DPRINTF(format, ...) if (0) printf(format, ##__VA_ARGS__)
    51 #endif
    52 
    5344typedef struct {
    5445        elf_dyn_t *rtld_dynamic;
  • uspace/lib/c/rtld/include/rtld_debug.h

    rb678410 ra6dffb8  
    2727 */
    2828
    29 /** @addtogroup init
     29/** @addtogroup generic
    3030 * @{
    3131 */
    32 /**
    33  * @file
     32/** @file
    3433 */
    3534
    36 #ifndef _DLOAD_START_H
    37 #define _DLOAD_START_H
     35#ifndef RTLD_DEBUG_H_
     36#define RTLD_DEBUG_H_
    3837
    39 void program_run(void *entry, pcb_t *pcb);
     38#include <sys/types.h>
     39#include <adt/list.h>
     40
     41#include <dynamic.h>
     42#include <module.h>
     43
     44/* Define to enable debugging mode. */
     45#undef RTLD_DEBUG
     46
     47#ifdef RTLD_DEBUG
     48        #define DPRINTF(format, ...) printf(format, ##__VA_ARGS__)
     49#else
     50        #define DPRINTF(format, ...) if (0) printf(format, ##__VA_ARGS__)
     51#endif
    4052
    4153#endif
  • uspace/lib/c/rtld/module.c

    rb678410 ra6dffb8  
    4343
    4444#include <rtld.h>
     45#include <rtld_debug.h>
    4546#include <dynamic.h>
    4647#include <elf_load.h>
     
    9798        module_t *m;
    9899        const char *p, *soname;
     100
     101        DPRINTF("module_find('%s')\n", name);
    99102
    100103        /*
     
    107110
    108111        /* Traverse list of all modules. Not extremely fast, but simple */
     112        DPRINTF("head = %p\n", head);
    109113        for (cur = head->next; cur != head; cur = cur->next) {
     114                DPRINTF("cur = %p\n", cur);
    110115                m = list_get_instance(cur, module_t, modules_link);
    111116                if (str_cmp(m->dyn.soname, soname) == 0) {
     
    185190        module_t *dm;
    186191        size_t n, i;
     192
     193        DPRINTF("module_load_deps('%s')\n", m->dyn.soname);
    187194
    188195        /* Count direct dependencies */
  • uspace/lib/c/rtld/symbol.c

    rb678410 ra6dffb8  
    4040
    4141#include <rtld.h>
     42#include <rtld_debug.h>
    4243#include <symbol.h>
    4344#include <elf.h>
  • uspace/srv/loader/Makefile

    rb678410 ra6dffb8  
    4141EXTRA_CLEAN = $(LINKER_SCRIPT)
    4242
    43 EXTRA_CFLAGS = -Iinclude
     43EXTRA_CFLAGS = -Iinclude -I../../lib/c/rtld/include
    4444
    4545BINARY = loader
  • uspace/srv/loader/main.c

    rb678410 ra6dffb8  
    6363#include <elf_load.h>
    6464
     65/* From librtld */
     66#include <rtld.h>
     67#include <dynamic.h>
     68#include <elf_load.h>
     69#include <module.h>
     70
    6571#define DPRINTF(...)
    6672
    6773void program_run(void *entry, pcb_t *pcb);
     74static int ldr_load_dyn_linked(elf_info_t *p_info);
    6875
    6976/** Pathname of the file that will be loaded */
     
    9198
    9299static elf_info_t prog_info;
    93 static elf_info_t interp_info;
    94 
    95 static bool is_dyn_linked;
    96100
    97101/** Used to limit number of connections to one. */
    98102static bool connected = false;
     103
     104/** State structure of the dynamic linker. */
     105runtime_env_t dload_re;
     106static module_t prog_mod;
    99107
    100108static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    304312        if (prog_info.interp == NULL) {
    305313                /* Statically linked program */
    306                 is_dyn_linked = false;
    307314                async_answer_0(rid, EOK);
    308315                return 0;
    309316        }
    310317       
    311         printf("Load ELF interpreter '%s'\n", prog_info.interp);
    312         rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
    313         if (rc != EE_OK) {
    314                 DPRINTF("Failed to load interpreter '%s.'\n",
    315                     prog_info.interp);
    316                 async_answer_0(rid, EINVAL);
    317                 return 1;
    318         }
    319        
    320         printf("Run interpreter.\n");
    321         printf("entry point: 0x%lx\n", (unsigned long) interp_info.entry);
    322         printf("pcb address: 0x%lx\n", (unsigned long) &pcb);
    323         printf("prog dynamic: 0x%lx\n", (unsigned long) prog_info.dynamic);
    324 
    325         is_dyn_linked = true;
    326         async_answer_0(rid, EOK);
    327        
     318        DPRINTF("Binary is dynamically linked.\n");
     319        DPRINTF(" - pcb address: %p\n", &pcb);
     320        DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic);
     321
     322        rc = ldr_load_dyn_linked(&prog_info);
     323
     324        async_answer_0(rid, rc);
    328325        return 0;
    329326}
    330327
     328static int ldr_load_dyn_linked(elf_info_t *p_info)
     329{
     330        runtime_env = &dload_re;
     331
     332        DPRINTF("Load dynamically linked program.\n");
     333
     334        /*
     335         * First we need to process dynamic sections of the executable
     336         * program and insert it into the module graph.
     337         */
     338
     339        DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
     340        dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
     341        prog_mod.bias = 0;
     342        prog_mod.dyn.soname = "[program]";
     343
     344        /* Initialize list of loaded modules */
     345        list_initialize(&runtime_env->modules_head);
     346        list_append(&prog_mod.modules_link, &runtime_env->modules_head);
     347
     348        /* Pointer to program module. Used as root of the module graph. */
     349        runtime_env->program = &prog_mod;
     350
     351        /* Work around non-existent memory space allocation. */
     352        runtime_env->next_bias = 0x1000000;
     353
     354        /*
     355         * Now we can continue with loading all other modules.
     356         */
     357
     358        DPRINTF("Load all program dependencies\n");
     359        module_load_deps(&prog_mod);
     360
     361        /*
     362         * Now relocate/link all modules together.
     363         */
     364
     365        /* Process relocations in all modules */
     366        DPRINTF("Relocate all modules\n");
     367        modules_process_relocs(&prog_mod);
     368
     369        /* Pass runtime evironment pointer through PCB. */
     370        pcb.rtld_runtime = (void *) runtime_env;
     371
     372        return 0;
     373}
    331374
    332375/** Run the previously loaded program.
     
    340383        const char *cp;
    341384       
     385        DPRINTF("Set task name\n");
     386
    342387        /* Set the task name. */
    343388        cp = str_rchr(pathname, '/');
     
    345390        task_set_name(cp);
    346391       
    347         if (is_dyn_linked == true) {
    348                 /* Dynamically linked program */
    349                 DPRINTF("Run ELF interpreter.\n");
    350                 DPRINTF("Entry point: %p\n", interp_info.entry);
    351                
    352                 async_answer_0(rid, EOK);
    353                 program_run(interp_info.entry, &pcb);
    354         } else {
    355                 /* Statically linked program */
    356                 async_answer_0(rid, EOK);
    357                 program_run(prog_info.entry, &pcb);
    358         }
     392        /* Run program */
     393        DPRINTF("Reply OK\n");
     394        async_answer_0(rid, EOK);
     395        DPRINTF("Jump to entry point at %p\n", pcb.entry);
     396        program_run(prog_info.entry, &pcb);
    359397       
    360398        /* Not reached */
Note: See TracChangeset for help on using the changeset viewer.