Changeset e175d69 in mainline


Ignore:
Timestamp:
2011-05-01T13:08:18Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
042fbe0
Parents:
a41577e (diff), e515a827 (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.
Message:

Merge dynamic linking support (ia32-only, off by default). Very limited TLS
support. Executables which use TLS should set STATIC_ONLY = y in Makefile.

Files:
18 added
27 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    ra41577e re175d69  
    528528! [PLATFORM=sparc64&MACHINE=generic] CONFIG_AOUT_ISOFS_B (y)
    529529
     530% Dynamic linking support
     531! [PLATFORM=ia32] CONFIG_RTLD (n/y)
     532! [PLATFORM=abs32le|PLATFORM=amd64|PLATFORM=arm32|PLATFORM=ia64|PLATFORM=mips32|PLATFORM=ppc32|PLATFORM=sparc64] CONFIG_RTLD (n)
     533
     534% Build shared libraries
     535! [CONFIG_RTLD=y] CONFIG_BUILD_SHARED_LIBS (n/y)
     536! [CONFIG_RTLD=n] CONFIG_BUILD_SHARED_LIBS (n)
     537
     538% Link against shared libraries
     539! [CONFIG_BUILD_SHARED_LIBS=y] CONFIG_USE_SHARED_LIBS (n/y)
     540! [CONFIG_BUILD_SHARED_LIBS=n] CONFIG_USE_SHARED_LIBS (n)
     541
    530542% Run devman on startup
    531543! CONFIG_START_DEVMAN (y/n)
  • boot/Makefile

    ra41577e re175d69  
    5555                cp "$$file" "$(DIST_PATH)/srv/" ; \
    5656        done
     57        for file in $(RD_LIBS) ; do \
     58                cp "$$file" "$(DIST_PATH)/lib/" ; \
     59        done
    5760        for file in $(RD_APPS) ; do \
    5861                cp "$$file" "$(DIST_PATH)/app/" ; \
     
    8386        rm -f $(USPACE_PATH)/dist/srv/*
    8487        rm -rf $(USPACE_PATH)/dist/drv/*
     88        rm -f $(USPACE_PATH)/dist/lib/*
    8589        rm -f $(USPACE_PATH)/dist/app/*
    8690        rm -f $(USPACE_PATH)/dist/cfg/net/*
  • boot/Makefile.common

    ra41577e re175d69  
    118118RD_DRV_CFG =
    119119
     120RD_LIBS =
     121
     122ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
     123        RD_LIBS += \
     124                $(USPACE_PATH)/lib/test/libtest.so.0 \
     125                $(USPACE_PATH)/lib/c/libc.so.0 \
     126                $(USPACE_PATH)/lib/softint/libsoftint.so.0
     127        RD_APPS += \
     128                $(USPACE_PATH)/app/dltest/dltest
     129endif
     130
    120131RD_APPS_ESSENTIAL = \
    121132        $(USPACE_PATH)/app/bdsh/bdsh \
     
    124135
    125136RD_APPS_NON_ESSENTIAL = \
     137        $(USPACE_PATH)/app/dltest/dltest \
     138        $(USPACE_PATH)/app/dltest2/dltest2 \
     139        $(USPACE_PATH)/app/dload/dload \
    126140        $(USPACE_PATH)/app/edit/edit \
    127141        $(USPACE_PATH)/app/kill/kill \
  • kernel/arch/ia32/include/barrier.h

    ra41577e re175d69  
    5454NO_TRACE static inline void cpuid_serialization(void)
    5555{
     56#ifndef __IN_SHARED_LIBC__
    5657        asm volatile (
    5758                "xorl %%eax, %%eax\n"
     
    5960                ::: "eax", "ebx", "ecx", "edx", "memory"
    6061        );
     62#else
     63        /* Must not clobber PIC register ebx */
     64        asm volatile (
     65                "movl %%ebx, %%esi\n"
     66                "xorl %%eax, %%eax\n"
     67                "cpuid\n"
     68                "movl %%esi, %%ebx\n"
     69                ::: "eax", "ecx", "edx", "esi", "memory"
     70        );
     71#endif
    6172}
    6273
  • uspace/Makefile.common

    ra41577e re175d69  
    4040#   BINARY         (/) binary output name (like appname)
    4141#   LIBRARY        (/) library output name (like libname)
     42#
    4243#   EXTRA_OUTPUT       additional output targets
    4344#   EXTRA_CLEAN        additional cleanup targets
     45#
     46# Optionally, for a binary:
     47#   STATIC_NEEDED      set to 'y' for init binaries, will build statically
     48#                      linked version
     49#   STATIC_ONLY        set to 'y' if binary cannot be linked dynamically
     50#                      (e.g. uses thread-local variables)
     51#
     52# Optionally, for a libary:
     53#   SLIBRARY           Name with full version, e.g. libfoo.so.0.0
     54#   LSONAME            Soname / name with short version, e.g. libfoo.so.0
    4455#
    4556# (x) required variables
     
    7384endif
    7485
     86ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
     87        ifneq ($(SLIBRARY),)
     88                LARCHIVE = $(LIBRARY).la
     89                LOUTPUT = $(SLIBRARY)
     90                EXTRA_OUTPUT += $(LOUTPUT).disasm $(LIBRARY).so $(LSONAME)
     91                EXTRA_CLEAN += $(LOUTPUT).map $(LOUTPUT).ldisasm \
     92                    $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld \
     93                    $(LIBRARY).so $(LSONAME)
     94        endif
     95endif
     96
    7597DEPEND = Makefile.depend
    7698DEPEND_PREV = $(DEPEND).prev
     
    90112LIBNET_PREFIX = $(LIB_PREFIX)/net
    91113
     114ifeq ($(STATIC_NEEDED),y)
     115        STATIC_BUILD = y
     116else
     117        ifeq ($(STATIC_ONLY),y)
     118                STATIC_BUILD = y
     119        else
     120                ifeq ($(CONFIG_USE_SHARED_LIBS), y)
     121                        STATIC_BUILD = n
     122                else
     123                        STATIC_BUILD = y
     124                endif
     125        endif
     126endif
     127
     128ifeq ($(STATIC_BUILD), y)
    92129BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
    93 
    94130LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
     131else
     132BASE_LIBS = $(LIBC_PREFIX)/libc.so.0 $(LIBSOFTINT_PREFIX)/libsoftint.so.0
     133LFLAGS = -Bdynamic
     134LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
     135endif
    95136
    96137ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
     
    102143.PHONY: all clean
    103144
    104 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
     145all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
    105146        -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
    106147
    107148clean:
    108         rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
     149        rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
    109150        find . -name '*.o' -follow -exec rm \{\} \;
     151        find . -name '*.lo' -follow -exec rm \{\} \;
    110152
    111153GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
     
    130172        -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
    131173
     174LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
     175LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
     176
    132177ifeq ($(CONFIG_DEBUG),y)
    133178        GCC_CFLAGS += -Werror
     
    175220
    176221OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
     222LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
    177223
    178224ifneq ($(BINARY),)
     
    191237endif
    192238
     239ifneq ($(SLIBRARY),)
     240%.disasm: $(LOUTPUT)
     241ifeq ($(CONFIG_LINE_DEBUG),y)
     242        $(OBJDUMP) -d -S $< > $@
     243else
     244        $(OBJDUMP) -d $< > $@
     245endif
     246
     247$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld
     248        $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
     249
     250$(LIBRARY).so:
     251        ln -s $(SLIBRARY) $@
     252
     253$(LSONAME):
     254        ln -s $(SLIBRARY) $@
     255endif
     256
    193257ifneq ($(LIBRARY),)
    194258%.a: $(OBJECTS)
     
    196260endif
    197261
     262ifneq ($(SLIBRARY),)
     263%.la: $(LOBJECTS)
     264        $(AR) rc $@ $(LOBJECTS)
     265endif
     266
    198267%.o: %.S $(DEPEND)
    199268        $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
     
    210279%.o: %.c $(DEPEND)
    211280        $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     281ifeq ($(PRECHECK),y)
     282        $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
     283endif
     284
     285%.lo: %.S $(DEPEND)
     286        $(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
     287ifeq ($(PRECHECK),y)
     288        $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
     289endif
     290
     291%.lo: %.s $(DEPEND)
     292        $(AS) $(AFLAGS) -o $@ $<
     293ifeq ($(PRECHECK),y)
     294        $(JOBFILE) $(JOB) $< $@ as asm
     295endif
     296
     297%.lo: %.c $(DEPEND)
     298        $(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
    212299ifeq ($(PRECHECK),y)
    213300        $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
     
    223310$(OUTPUT): $(OBJECTS)
    224311
     312$(LARCHIVE): $(LOBJECTS)
  • uspace/app/init/Makefile

    ra41577e re175d69  
    3030USPACE_PREFIX = ../..
    3131BINARY = init
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/lib/c/Makefile

    ra41577e re175d69  
    4343LINKER_SCRIPTS = \
    4444        $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld \
    45         $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld
     45        $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld \
     46        $(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld \
     47        $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
    4648
    4749PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH)
     
    4951EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPTS)
    5052LIBRARY = libc
     53SLIBRARY = libc.so.0.0
     54LSONAME = libc.so.0
     55
    5156
    5257-include $(COMMON_MAKEFILE)
    5358-include $(CONFIG_MAKEFILE)
    5459-include arch/$(UARCH)/Makefile.inc
     60
     61EXTRA_CFLAGS += -I../../srv/loader/include
    5562
    5663GENERIC_SOURCES = \
     
    118125        generic/sort.c \
    119126        generic/stats.c \
    120         generic/assert.c \
     127        generic/assert.c
     128
     129ifeq ($(CONFIG_RTLD), y)
     130        GENERIC_SOURCES += \
     131                generic/dlfcn.c \
     132                generic/rtld/rtld.c \
     133                generic/rtld/elf_load.c \
     134                generic/rtld/dynamic.c \
     135                generic/rtld/module.c \
     136                generic/rtld/symbol.c
     137endif
    121138
    122139SOURCES = \
     
    143160        $(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DLOADER -E -x c $< | grep -v "^\#" > $@
    144161
     162$(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
     163        $(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DSHLIB -E -x c $< | grep -v "^\#" > $@
     164
     165$(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
     166        $(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DDLEXE -E -x c $< | grep -v "^\#" > $@
     167
    145168$(COMMON_HEADER_ARCH): $(COMMON_HEADER)
    146169        ln -sfn ../../../$< $@
  • uspace/lib/c/arch/ia32/Makefile.inc

    ra41577e re175d69  
    3636        arch/$(UARCH)/src/setjmp.S \
    3737        arch/$(UARCH)/src/stacktrace.c \
    38         arch/$(UARCH)/src/stacktrace_asm.S
     38        arch/$(UARCH)/src/stacktrace_asm.S \
     39        arch/$(UARCH)/src/rtld/dynamic.c \
     40        arch/$(UARCH)/src/rtld/reloc.c
    3941
    4042.PRECIOUS: arch/$(UARCH)/src/entry.o
  • uspace/lib/c/arch/ia32/_link.ld.in

    ra41577e re175d69  
     1#ifndef SHLIB
    12STARTUP(LIBC_PATH/arch/UARCH/src/entry.o)
    23ENTRY(__entry)
     4#endif
    35
    46PHDRS {
    5 #ifdef LOADER
     7#if defined(LOADER) || defined(DLEXE)
    68        interp PT_INTERP;
    79        text PT_LOAD FILEHDR PHDRS FLAGS(5);
     
    1012#endif
    1113        data PT_LOAD FLAGS(6);
     14#if defined(SHLIB) || defined(DLEXE)
     15        dynamic PT_DYNAMIC;
     16#endif
    1217        debug PT_NOTE;
    1318}
    1419
    1520SECTIONS {
    16 #ifdef LOADER
     21#if defined(LOADER) || defined(DLEXE)
    1722        .interp : {
    1823                *(.interp);
    1924        } :interp
    20 
     25#endif
     26#ifdef LOADER
    2127        . = 0x70001000 + SIZEOF_HEADERS;
    2228#else
     
    3137                *(.rodata .rodata.*);
    3238        } :text
     39
     40#if defined(SHLIB) || defined(DLEXE)
     41        .rel.plt : {
     42                *(.rel.plt);
     43        }
     44        /*
     45         *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt
     46         * without alignment gap or DT_REL will be broken
     47         */
     48        .rel.dyn : {
     49                *(.rel.*);
     50        } :text
    3351       
     52        .plt : {
     53                *(.plt);
     54        } :text
     55       
     56        .dynsym : {
     57                *(.dynsym);
     58        } :text
     59       
     60        .dynstr : {
     61                *(.dynstr);
     62        } :text
     63       
     64        .hash : {
     65                *(.hash);
     66        } :text
     67#endif
    3468        . = . + 0x1000;
     69       
     70#if defined(SHLIB) || defined(DLEXE)
     71        .dynamic : {
     72                *(.dynamic);
     73        } :data :dynamic
     74#endif
    3575       
    3676        .data : {
     
    3878        } :data
    3979       
     80#if defined(SHLIB) || defined(DLEXE)
     81        .data.rel : {
     82                *(.data.rel .data.rel.*);
     83        } :data
     84
     85        .got : {
     86                *(.got);
     87        } :data
     88        .got.plt : {
     89                *(.got.plt);
     90        } :data
     91#endif
     92       
     93#ifndef DLEXE
    4094        .tdata : {
    4195                _tdata_start = .;
     
    49103       
    50104        _tls_alignment = ALIGNOF(.tdata);
     105#endif
    51106       
    52107        .bss : {
     108                *(.dynbss);
    53109                *(COMMON);
    54110                *(.bss);
  • uspace/lib/c/arch/ia32/src/syscall.S

    ra41577e re175d69  
    3232__syscall_fast_func:
    3333        .long __syscall_slow
     34        .size __syscall_fast_func, . - __syscall_fast_func
    3435
    3536.text
     
    7172 */
    7273.global __syscall_fast
     74        .type __syscall_fast, @function
     75
    7376__syscall_fast:
    7477        pushl %ebx
     
    9598        popl %ebx
    9699        ret
     100
     101        .size __syscall_fast, . - __syscall_fast
  • uspace/lib/c/arch/ia32/src/tls.c

    ra41577e re175d69  
    3737#include <tls.h>
    3838#include <sys/types.h>
     39#include <align.h>
    3940
    4041tcb_t * __alloc_tls(void **data, size_t size)
     
    4849}
    4950
     51/*
     52 * Rtld TLS support
     53 */
     54
     55typedef struct {
     56        unsigned long int ti_module;
     57        unsigned long int ti_offset;
     58} tls_index;
     59
     60void __attribute__ ((__regparm__ (1)))
     61    *___tls_get_addr(tls_index *ti);
     62
     63void __attribute__ ((__regparm__ (1)))
     64    *___tls_get_addr(tls_index *ti)
     65{
     66        size_t tls_size;
     67        uint8_t *tls;
     68
     69        /* Calculate size of TLS block */
     70        tls_size = ALIGN_UP(&_tbss_end - &_tdata_start, &_tls_alignment);
     71
     72        /* The TLS block is just before TCB */
     73        tls = (uint8_t *)__tcb_get() - tls_size;
     74
     75        return tls + ti->ti_offset;
     76}
     77
    5078/** @}
    5179 */
  • uspace/lib/c/generic/libc.c

    ra41577e re175d69  
    5353#include "private/io.h"
    5454
     55#ifdef CONFIG_RTLD
     56#include <rtld/rtld.h>
     57#endif
     58
    5559static bool env_setup = false;
    5660
     
    7781        char **argv;
    7882       
     83#ifdef __IN_SHARED_LIBC__
     84        if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
     85                runtime_env = (runtime_env_t *) __pcb->rtld_runtime;
     86        }
     87#endif
    7988        /*
    8089         * Get command line arguments and initialize
  • uspace/lib/c/include/loader/pcb.h

    ra41577e re175d69  
    7272        /** Pointer to ELF dynamic section of the program. */
    7373        void *dynamic;
     74        /** Pointer to dynamic linker state structure (runtime_env_t). */
     75        void *rtld_runtime;
    7476} pcb_t;
    7577
  • uspace/lib/softint/Makefile

    ra41577e re175d69  
    3131EXTRA_CFLAGS = -Iinclude
    3232LIBRARY = libsoftint
     33SLIBRARY = libsoftint.so.0.0
     34LSONAME = libsoftint.so.0
    3335
    3436SOURCES = \
  • uspace/srv/bd/rd/Makefile

    ra41577e re175d69  
    3030USPACE_PREFIX = ../../..
    3131BINARY = rd
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/srv/devman/Makefile

    ra41577e re175d69  
    3030USPACE_PREFIX = ../..
    3131BINARY = devman
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/srv/devmap/Makefile

    ra41577e re175d69  
    3030USPACE_PREFIX = ../..
    3131BINARY = devmap
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/srv/fs/devfs/Makefile

    ra41577e re175d69  
    3232EXTRA_CFLAGS += -I$(LIBFS_PREFIX)
    3333BINARY = devfs
     34STATIC_NEEDED = y
    3435
    3536SOURCES = \
  • uspace/srv/fs/fat/Makefile

    ra41577e re175d69  
    3232EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX)
    3333BINARY = fat
     34STATIC_NEEDED = y
    3435
    3536SOURCES = \
  • uspace/srv/fs/tmpfs/Makefile

    ra41577e re175d69  
    3232EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX)
    3333BINARY = tmpfs
     34STATIC_NEEDED = y
    3435
    3536SOURCES = \
  • uspace/srv/loader/Makefile

    ra41577e re175d69  
    4242
    4343BINARY = loader
     44STATIC_ONLY = y
    4445
    4546GENERIC_SOURCES = \
  • uspace/srv/loader/elf_load.c

    ra41577e re175d69  
    103103 *
    104104 */
    105 int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info)
     105int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags,
     106    elf_info_t *info)
    106107{
    107108        elf_ld_t elf;
     
    118119        elf.fd = fd;
    119120        elf.info = info;
     121        elf.flags = flags;
    120122
    121123        rc = elf_load(&elf, so_bias);
     
    124126
    125127        return rc;
    126 }
    127 
    128 /** Run an ELF executable.
    129  *
    130  * Transfers control to the entry point of an ELF executable loaded
    131  * earlier with elf_load_file(). This function does not return.
    132  *
    133  * @param info Info structure filled earlier by elf_load_file()
    134  *
    135  */
    136 void elf_run(elf_info_t *info, pcb_t *pcb)
    137 {
    138         entry_point_jmp(info->entry, pcb);
    139 
    140         /* not reached */
    141128}
    142129
     
    153140        pcb->entry = info->entry;
    154141        pcb->dynamic = info->dynamic;
     142        pcb->rtld_runtime = NULL;
    155143}
    156144
     
    306294                break;
    307295        case PT_INTERP:
    308                 /* Assume silently interp == "/rtld.so" */
    309                 elf->info->interp = "/rtld.so";
     296                /* Assume silently interp == "/app/dload" */
     297                elf->info->interp = "/app/dload";
    310298                break;
    311299        case PT_DYNAMIC:
     300                /* Record pointer to dynamic section into info structure */
     301                elf->info->dynamic =
     302                    (void *)((uint8_t *)entry->p_vaddr + elf->bias);
     303                DPRINTF("dynamic section found at 0x%x\n",
     304                        (uintptr_t)elf->info->dynamic);
     305                break;
     306        case 0x70000000:
     307                /* FIXME: MIPS reginfo */
     308                break;
    312309        case PT_SHLIB:
    313         case PT_LOPROC:
    314         case PT_HIPROC:
     310//      case PT_LOPROC:
     311//      case PT_HIPROC:
    315312        default:
    316313                DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
     
    383380            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    384381        if (a == (void *)(-1)) {
    385                 DPRINTF("Memory mapping failed.\n");
     382                DPRINTF("memory mapping failed (0x%x, %d)\n",
     383                        base+bias, mem_sz);
    386384                return EE_MEMORY;
    387385        }
     
    425423        }
    426424
     425        /*
     426         * The caller wants to modify the segments first. He will then
     427         * need to set the right access mode and ensure SMC coherence.
     428         */
     429        if ((elf->flags & ELDF_RW) != 0) return EE_OK;
     430
     431//      printf("set area flags to %d\n", flags);
    427432        rc = as_area_change_flags(seg_ptr, flags);
    428433        if (rc != 0) {
  • uspace/srv/loader/include/elf_load.h

    ra41577e re175d69  
    4343#include "elf.h"
    4444
     45typedef enum {
     46        /** Leave all segments in RW access mode. */
     47        ELDF_RW = 1
     48} eld_flags_t;
     49
    4550/**
    4651 * Some data extracted from the headers are stored here
     
    6772        uintptr_t bias;
    6873
     74        /** Flags passed to the ELF loader. */
     75        eld_flags_t flags;
     76
    6977        /** A copy of the ELF file header */
    7078        elf_header_t *header;
     
    7482} elf_ld_t;
    7583
    76 int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info);
    77 void elf_run(elf_info_t *info, pcb_t *pcb);
     84int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags,
     85    elf_info_t *info);
    7886void elf_create_pcb(elf_info_t *info, pcb_t *pcb);
    7987
  • uspace/srv/loader/main.c

    ra41577e re175d69  
    5555#include <macros.h>
    5656#include <loader/pcb.h>
     57#include <entry_point.h>
    5758#include <errno.h>
    5859#include <async.h>
     
    6263#include <elf.h>
    6364#include <elf_load.h>
     65
     66#ifdef CONFIG_RTLD
     67#include <rtld/rtld.h>
     68#include <rtld/dynamic.h>
     69#include <rtld/module.h>
     70
     71static int ldr_load_dyn_linked(elf_info_t *p_info);
     72#endif
    6473
    6574#define DPRINTF(...)
     
    8998
    9099static elf_info_t prog_info;
    91 static elf_info_t interp_info;
    92 
    93 static bool is_dyn_linked;
    94100
    95101/** Used to limit number of connections to one. */
    96102static bool connected = false;
     103
     104#ifdef CONFIG_RTLD
     105/** State structure of the dynamic linker. */
     106runtime_env_t dload_re;
     107static module_t prog_mod;
     108#endif
    97109
    98110static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    283295        int rc;
    284296       
    285         rc = elf_load_file(pathname, 0, &prog_info);
     297        rc = elf_load_file(pathname, 0, 0, &prog_info);
    286298        if (rc != EE_OK) {
    287299                DPRINTF("Failed to load executable '%s'.\n", pathname);
     
    302314        if (prog_info.interp == NULL) {
    303315                /* Statically linked program */
    304                 is_dyn_linked = false;
    305316                async_answer_0(rid, EOK);
    306317                return 0;
    307318        }
    308319       
    309         rc = elf_load_file(prog_info.interp, 0, &interp_info);
    310         if (rc != EE_OK) {
    311                 DPRINTF("Failed to load interpreter '%s.'\n",
    312                     prog_info.interp);
    313                 async_answer_0(rid, EINVAL);
    314                 return 1;
    315         }
    316        
    317         is_dyn_linked = true;
    318         async_answer_0(rid, EOK);
    319        
     320        DPRINTF("Binary is dynamically linked.\n");
     321#ifdef CONFIG_RTLD
     322        DPRINTF(" - pcb address: %p\n", &pcb);
     323        DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic);
     324
     325        rc = ldr_load_dyn_linked(&prog_info);
     326#else
     327        rc = ENOTSUP;
     328#endif
     329        async_answer_0(rid, rc);
    320330        return 0;
    321331}
    322332
     333#ifdef CONFIG_RTLD
     334
     335static int ldr_load_dyn_linked(elf_info_t *p_info)
     336{
     337        runtime_env = &dload_re;
     338
     339        DPRINTF("Load dynamically linked program.\n");
     340
     341        /*
     342         * First we need to process dynamic sections of the executable
     343         * program and insert it into the module graph.
     344         */
     345
     346        DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
     347        dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
     348        prog_mod.bias = 0;
     349        prog_mod.dyn.soname = "[program]";
     350
     351        /* Initialize list of loaded modules */
     352        list_initialize(&runtime_env->modules_head);
     353        list_append(&prog_mod.modules_link, &runtime_env->modules_head);
     354
     355        /* Pointer to program module. Used as root of the module graph. */
     356        runtime_env->program = &prog_mod;
     357
     358        /* Work around non-existent memory space allocation. */
     359        runtime_env->next_bias = 0x1000000;
     360
     361        /*
     362         * Now we can continue with loading all other modules.
     363         */
     364
     365        DPRINTF("Load all program dependencies\n");
     366        module_load_deps(&prog_mod);
     367
     368        /*
     369         * Now relocate/link all modules together.
     370         */
     371
     372        /* Process relocations in all modules */
     373        DPRINTF("Relocate all modules\n");
     374        modules_process_relocs(&prog_mod);
     375
     376        /* Pass runtime evironment pointer through PCB. */
     377        pcb.rtld_runtime = (void *) runtime_env;
     378
     379        return 0;
     380}
     381#endif
    323382
    324383/** Run the previously loaded program.
     
    332391        const char *cp;
    333392       
     393        DPRINTF("Set task name\n");
     394
    334395        /* Set the task name. */
    335396        cp = str_rchr(pathname, '/');
     
    337398        task_set_name(cp);
    338399       
    339         if (is_dyn_linked == true) {
    340                 /* Dynamically linked program */
    341                 DPRINTF("Run ELF interpreter.\n");
    342                 DPRINTF("Entry point: %p\n", interp_info.entry);
    343                
    344                 async_answer_0(rid, EOK);
    345                 elf_run(&interp_info, &pcb);
    346         } else {
    347                 /* Statically linked program */
    348                 async_answer_0(rid, EOK);
    349                 elf_run(&prog_info, &pcb);
    350         }
     400        /* Run program */
     401        DPRINTF("Reply OK\n");
     402        async_answer_0(rid, EOK);
     403        DPRINTF("Jump to entry point at %p\n", pcb.entry);
     404        entry_point_jmp(prog_info.entry, &pcb);
    351405       
    352406        /* Not reached */
  • uspace/srv/net/tl/icmp/Makefile

    ra41577e re175d69  
    3232EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
    3333BINARY = icmp
     34STATIC_ONLY = y
    3435
    3536SOURCES = \
  • uspace/srv/ns/Makefile

    ra41577e re175d69  
    3030USPACE_PREFIX = ../..
    3131BINARY = ns
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/srv/vfs/Makefile

    ra41577e re175d69  
    3030USPACE_PREFIX = ../..
    3131BINARY = vfs
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
Note: See TracChangeset for help on using the changeset viewer.