Changeset 2eadda9 in mainline


Ignore:
Timestamp:
2018-07-11T17:45:30Z (6 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:
99d3123
Parents:
c2c4127
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-11 17:08:12)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-11 17:45:30)
Message:

Remove undefined references to main program from shared libc.

Location:
uspace
Files:
1 added
30 edited

Legend:

Unmodified
Added
Removed
  • uspace/Makefile.common

    rc2c4127 r2eadda9  
    118118LIBDLTEST_PREFIX = $(LIB_PREFIX)/dltest
    119119
    120 START_FILES = $(LIBC_PREFIX)/arch/$(UARCH)/src/entry.o
     120START_FILES = $(LIBC_PREFIX)/crt0.o $(LIBC_PREFIX)/crt1.o
    121121
    122122AFLAGS = --fatal-warnings
     
    137137endif
    138138
    139 ifeq ($(STATIC_BUILD),y)
    140         BASE_LIBS = $(LIBC_PREFIX)/libc.a
    141 else
    142         BASE_LIBS = $(LIBC_PREFIX)/libc.so.0
     139ifneq ($(STATIC_BUILD),y)
    143140        LINK_DYNAMIC = y
     141endif
     142
     143BASE_LIBS =
     144
     145ifneq ($(LIBRARY),libc)
     146        ifeq ($(STATIC_BUILD),y)
     147                BASE_LIBS += $(LIBC_PREFIX)/libc.a
     148        else
     149                BASE_LIBS += $(LIBC_PREFIX)/libc.so.0
     150        endif
    144151endif
    145152
     
    286293
    287294LIB_CFLAGS = $(CFLAGS) -fPIC
    288 LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(LSONAME)
     295LIB_LDFLAGS = $(LDFLAGS) -shared -Wl,-soname,$(LSONAME) -Wl,--no-undefined,--no-allow-shlib-undefined
    289296
    290297AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
     
    340347
    341348ifneq ($(filter %.cpp %.cc %.cxx, $(SOURCES)),)
    342 $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(CXX_BASE_LIBS)
     349$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS)
    343350        $(CXX) $(CXXFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ $(START_FILES) $(OBJECTS) $(LIBARGS) $(CXX_BASE_LIBS)
    344351else
    345 $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS) $(BASE_LIBS)
     352$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBTAGS)
    346353        $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ $(START_FILES) $(OBJECTS) $(LIBARGS) $(BASE_LIBS)
    347354endif
     
    350357
    351358ifneq ($(TEST_BINARY),)
    352 $(TEST_BINARY): $(LINKER_SCRIPT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS) $(BASE_LIBS)
     359$(TEST_BINARY): $(LINKER_SCRIPT) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBTAGS)
    353360        $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ $(START_FILES) $(TEST_OBJECTS) $(TEST_BINARY_LIBS) $(LIBARGS) $(BASE_LIBS)
    354361endif
     
    368375
    369376$(SLIBRARY): $(LIB_LINKER_SCRIPT) $(LIBRARY).la
    370         $(CC) $(CFLAGS) $(LIB_LDFLAGS) $(EXTRA_LDFLAGS) -T $(LIB_LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ -Wl,--whole-archive $(LIBRARY).la -Wl,--no-whole-archive
     377        $(CC) $(CFLAGS) $(LIB_LDFLAGS) $(EXTRA_LDFLAGS) -T $(LIB_LINKER_SCRIPT) -Wl,-Map,$@.map -o $@ -Wl,--whole-archive $(LIBRARY).la -Wl,--no-whole-archive $(LIBARGS) $(BASE_LIBS)
    371378
    372379$(LSONAME):
  • uspace/lib/c/Makefile

    rc2c4127 r2eadda9  
    207207include $(USPACE_PREFIX)/Makefile.common
    208208
     209$(LIBC_PREFIX)/crt0.o: $(LIBC_PREFIX)/arch/$(UARCH)/src/entry.o
     210        cp $< $@
     211
     212$(LIBC_PREFIX)/crt1.o: $(LIBC_PREFIX)/generic/crt/entry.o
     213        cp $< $@
     214
    209215$(LIBC_PREFIX)/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
    210216        $(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
  • uspace/lib/c/arch/abs32le/_link.ld.in

    rc2c4127 r2eadda9  
    5757
    5858        .init_array : {
     59#ifndef SHLIB
    5960                PROVIDE_HIDDEN (__init_array_start = .);
     61#endif
    6062                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    6163                KEEP (*(.init_array .ctors))
     64#ifndef SHLIB
    6265                PROVIDE_HIDDEN (__init_array_end = .);
     66#endif
    6367        }
    6468
    6569        .fini_array : {
     70#ifndef SHLIB
    6671                PROVIDE_HIDDEN (__fini_array_start = .);
     72#endif
    6773                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    6874                KEEP (*(.fini_array .dtors))
     75#ifndef SHLIB
    6976                PROVIDE_HIDDEN (__fini_array_end = .);
     77#endif
    7078        }
    7179
  • uspace/lib/c/arch/abs32le/src/entry.c

    rc2c4127 r2eadda9  
    3030 */
    3131
    32 #include "../../../generic/private/libc.h"
    3332#include <stddef.h>
    3433
    3534extern void _start(void);
     35extern void __c_start(void *);
    3636
    3737/* Normally, the entry point is defined in assembly for the architecture. */
     
    3939void _start(void)
    4040{
    41         __libc_main(NULL);
     41        __c_start(NULL);
    4242}
    4343
  • uspace/lib/c/arch/amd64/_link.ld.in

    rc2c4127 r2eadda9  
    5757
    5858        .init_array : {
     59#ifndef SHLIB
    5960                PROVIDE_HIDDEN (__init_array_start = .);
     61#endif
    6062                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    6163                KEEP (*(.init_array .ctors))
     64#ifndef SHLIB
    6265                PROVIDE_HIDDEN (__init_array_end = .);
     66#endif
    6367        }
    6468
    6569        .fini_array : {
     70#ifndef SHLIB
    6671                PROVIDE_HIDDEN (__fini_array_start = .);
     72#endif
    6773                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    6874                KEEP (*(.fini_array .dtors))
     75#ifndef SHLIB
    6976                PROVIDE_HIDDEN (__fini_array_end = .);
     77#endif
    7078        }
    7179
  • uspace/lib/c/arch/amd64/src/entry.S

    rc2c4127 r2eadda9  
    2929#include <abi/asmtool.h>
    3030
    31 .section .init, "ax"
     31.text
    3232
    3333.org 0
     
    4646
    4747        # %rdi was deliberately chosen as the first argument is also in %rdi
    48         # Pass PCB pointer to __libc_main (no operation)
    49         call __libc_main
     48        # Pass PCB pointer to __c_start (no operation)
     49        call __c_start
  • uspace/lib/c/arch/arm32/_link.ld.in

    rc2c4127 r2eadda9  
    5555
    5656        .init_array : {
     57#ifndef SHLIB
    5758                PROVIDE_HIDDEN (__init_array_start = .);
     59#endif
    5860                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    5961                KEEP (*(.init_array .ctors))
     62#ifndef SHLIB
    6063                PROVIDE_HIDDEN (__init_array_end = .);
     64#endif
    6165        }
    6266
    6367        .fini_array : {
     68#ifndef SHLIB
    6469                PROVIDE_HIDDEN (__fini_array_start = .);
     70#endif
    6571                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    6672                KEEP (*(.fini_array .dtors))
     73#ifndef SHLIB
    6774                PROVIDE_HIDDEN (__fini_array_end = .);
     75#endif
    6876        }
    6977
  • uspace/lib/c/arch/arm32/src/entry.S

    rc2c4127 r2eadda9  
    2929#include <abi/asmtool.h>
    3030
    31 .section .init, "ax"
     31.text
    3232
    3333.org 0
     
    5151        sub fp, ip, #4
    5252
    53         # Pass pcb_ptr to __libc_main as the first argument (in r0)
     53        # Pass pcb_ptr to __c_start as the first argument (in r0)
    5454        mov r0, r1
    55         bl __libc_main
     55        bl __c_start
    5656
    5757.data
  • uspace/lib/c/arch/ia32/_link.ld.in

    rc2c4127 r2eadda9  
    116116
    117117        .init_array : {
    118                 PROVIDE (__init_array_start = .);
     118#ifndef SHLIB
     119                PROVIDE_HIDDEN (__init_array_start = .);
     120#endif
    119121                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    120122                KEEP (*(.init_array .ctors))
    121                 PROVIDE (__init_array_end = .);
     123#ifndef SHLIB
     124                PROVIDE_HIDDEN (__init_array_end = .);
     125#endif
    122126        }
    123127
    124128        .fini_array : {
    125                 PROVIDE (__fini_array_start = .);
     129#ifndef SHLIB
     130                PROVIDE_HIDDEN (__fini_array_start = .);
     131#endif
    126132                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    127133                KEEP (*(.fini_array .dtors))
    128                 PROVIDE (__fini_array_end = .);
     134#ifndef SHLIB
     135                PROVIDE_HIDDEN (__fini_array_end = .);
     136#endif
    129137        }
    130138
  • uspace/lib/c/arch/ia32/src/entry.S

    rc2c4127 r2eadda9  
    3232INTEL_SEP = 11
    3333
    34 .section .init, "ax"
     34.text
    3535
    3636.org 0
     
    6565        movl %esp, %ebp
    6666
    67         # Pass the PCB pointer to __libc_main as the first argument
     67        # Pass the PCB pointer to __c_start as the first argument
    6868        pushl %edi
    69         call __libc_main
     69        call __c_start
  • uspace/lib/c/arch/ia64/_link.ld.in

    rc2c4127 r2eadda9  
    6565
    6666        .init_array : {
     67#ifndef SHLIB
    6768                PROVIDE_HIDDEN (__init_array_start = .);
     69#endif
    6870                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    6971                KEEP (*(.init_array .ctors))
     72#ifndef SHLIB
    7073                PROVIDE_HIDDEN (__init_array_end = .);
     74#endif
    7175        }
    7276
    7377        .fini_array : {
     78#ifndef SHLIB
    7479                PROVIDE_HIDDEN (__fini_array_start = .);
     80#endif
    7581                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    7682                KEEP (*(.fini_array .dtors))
     83#ifndef SHLIB
    7784                PROVIDE_HIDDEN (__fini_array_end = .);
     85#endif
    7886        }
    7987
  • uspace/lib/c/arch/ia64/src/entry.S

    rc2c4127 r2eadda9  
    2929#include <abi/asmtool.h>
    3030
    31 .section .init, "ax"
     31.text
    3232
    3333.org 0
     
    4242        movl gp = __gp
    4343
    44         # Pass PCB pointer as the first argument to __libc_main
     44        # Pass PCB pointer as the first argument to __c_start
    4545        mov out0 = r2 ;;
    46         br.call.sptk.many b0 = __libc_main
     46        br.call.sptk.many b0 = __c_start
    4747
  • uspace/lib/c/arch/mips32/_link.ld.in

    rc2c4127 r2eadda9  
    6262
    6363        .init_array : {
     64#ifndef SHLIB
    6465                PROVIDE_HIDDEN (__init_array_start = .);
     66#endif
    6567                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    6668                KEEP (*(.init_array .ctors))
     69#ifndef SHLIB
    6770                PROVIDE_HIDDEN (__init_array_end = .);
     71#endif
    6872        }
    6973
    7074        .fini_array : {
     75#ifndef SHLIB
    7176                PROVIDE_HIDDEN (__fini_array_start = .);
     77#endif
    7278                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    7379                KEEP (*(.fini_array .dtors))
     80#ifndef SHLIB
    7481                PROVIDE_HIDDEN (__fini_array_end = .);
     82#endif
    7583        }
    7684
  • uspace/lib/c/arch/mips32/src/entry.S

    rc2c4127 r2eadda9  
    3131
    3232.text
    33 .section .init, "ax"
    3433
    3534.set noreorder
     
    5150        .cprestore 16
    5251
    53         # Pass pcb_ptr to __libc_main() as the first argument. It is already
     52        # Pass pcb_ptr to __c_start() as the first argument. It is already
    5453        # in $a0. As the first argument is passed in $a0, no operation
    5554        # is needed.
    5655
    57         jal __libc_main
     56        jal __c_start
    5857        nop
    5958
  • uspace/lib/c/arch/ppc32/_link.ld.in

    rc2c4127 r2eadda9  
    5555
    5656        .init_array : {
     57#ifndef SHLIB
    5758                PROVIDE_HIDDEN (__init_array_start = .);
     59#endif
    5860                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    5961                KEEP (*(.init_array .ctors))
     62#ifndef SHLIB
    6063                PROVIDE_HIDDEN (__init_array_end = .);
     64#endif
    6165        }
    6266
    6367        .fini_array : {
     68#ifndef SHLIB
    6469                PROVIDE_HIDDEN (__fini_array_start = .);
     70#endif
    6571                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    6672                KEEP (*(.fini_array .dtors))
     73#ifndef SHLIB
    6774                PROVIDE_HIDDEN (__fini_array_end = .);
     75#endif
    6876        }
    6977
  • uspace/lib/c/arch/ppc32/src/entry.S

    rc2c4127 r2eadda9  
    2929#include <abi/asmtool.h>
    3030
    31 .section .init, "ax"
     31.text
    3232
    3333.org 0
     
    4545        stwu %r1, -16(%r1)
    4646
    47         # Pass the PCB pointer to __libc_main() as the first argument.
     47        # Pass the PCB pointer to __c_start() as the first argument.
    4848        # The first argument is passed in r3.
    4949        mr %r3, %r6
    50         bl __libc_main
     50        bl __c_start
  • uspace/lib/c/arch/riscv64/_link.ld.in

    rc2c4127 r2eadda9  
    5454
    5555        .init_array : {
     56#ifndef SHLIB
    5657                PROVIDE_HIDDEN (__init_array_start = .);
     58#endif
    5759                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    5860                KEEP (*(.init_array .ctors))
     61#ifndef SHLIB
    5962                PROVIDE_HIDDEN (__init_array_end = .);
     63#endif
    6064        }
    6165
    6266        .fini_array : {
     67#ifndef SHLIB
    6368                PROVIDE_HIDDEN (__fini_array_start = .);
     69#endif
    6470                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    6571                KEEP (*(.fini_array .dtors))
     72#ifndef SHLIB
    6673                PROVIDE_HIDDEN (__fini_array_end = .);
     74#endif
    6775        }
    6876
  • uspace/lib/c/arch/riscv64/src/entry.c

    rc2c4127 r2eadda9  
    3030 */
    3131
    32 #include "../../../generic/private/libc.h"
    33 
    3432extern void _start(void);
     33extern void __c_start(void *);
    3534
    3635// FIXME: Implement properly.
     
    3837void _start(void)
    3938{
    40         __libc_main((void *) 0);
     39        __c_start(0);
    4140}
    4241
  • uspace/lib/c/arch/sparc64/_link.ld.in

    rc2c4127 r2eadda9  
    5858
    5959        .init_array : {
     60#ifndef SHLIB
    6061                PROVIDE_HIDDEN (__init_array_start = .);
     62#endif
    6163                KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    6264                KEEP (*(.init_array .ctors))
     65#ifndef SHLIB
    6366                PROVIDE_HIDDEN (__init_array_end = .);
     67#endif
    6468        }
    6569
    6670        .fini_array : {
     71#ifndef SHLIB
    6772                PROVIDE_HIDDEN (__fini_array_start = .);
     73#endif
    6874                KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    6975                KEEP (*(.fini_array .dtors))
     76#ifndef SHLIB
    7077                PROVIDE_HIDDEN (__fini_array_end = .);
     78#endif
    7179        }
    7280
  • uspace/lib/c/arch/sparc64/src/entry.S

    rc2c4127 r2eadda9  
    2929#include <abi/asmtool.h>
    3030
    31 .section .init, "ax"
     31.text
    3232
    3333.org 0
     
    4646        add %g0, -0x7ff, %fp
    4747
    48         # Pass pcb_ptr as the first argument to __libc_main()
    49         call __libc_main
     48        # Pass pcb_ptr as the first argument to __c_start()
     49        call __c_start
    5050        mov %i1, %o0
  • uspace/lib/c/generic/as.c

    rc2c4127 r2eadda9  
    6060{
    6161        return (void *) __SYSCALL5(SYS_AS_AREA_CREATE, (sysarg_t) base,
    62             (sysarg_t) size, (sysarg_t) flags, (sysarg_t) _end,
     62            (sysarg_t) size, (sysarg_t) flags, (sysarg_t) __progsymbols.end,
    6363            (sysarg_t) pager_info);
    6464}
  • uspace/lib/c/generic/async/server.c

    rc2c4127 r2eadda9  
    13971397        // FIXME: The source has no business deciding destination address.
    13981398        return ipc_answer_3(call->cap_handle, EOK, (sysarg_t) src, (sysarg_t) flags,
    1399             (sysarg_t) _end);
     1399            (sysarg_t) __progsymbols.end);
    14001400}
    14011401
     
    14491449        assert(call);
    14501450
    1451         return ipc_answer_2(call->cap_handle, EOK, (sysarg_t) _end,
     1451        return ipc_answer_2(call->cap_handle, EOK, (sysarg_t) __progsymbols.end,
    14521452            (sysarg_t) dst);
    14531453}
  • uspace/lib/c/generic/ddi.c

    rc2c4127 r2eadda9  
    7272{
    7373        return (errno_t) __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
    74             pages, flags, (sysarg_t) virt, (sysarg_t) _end);
     74            pages, flags, (sysarg_t) virt, (sysarg_t) __progsymbols.end);
    7575}
    7676
     
    145145        return (errno_t) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
    146146            (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS,
    147             (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) _end);
     147            (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) __progsymbols.end);
    148148}
    149149
  • uspace/lib/c/generic/elf/elf_mod.c

    rc2c4127 r2eadda9  
    356356                    (void *)((uint8_t *)entry->p_vaddr + elf->bias);
    357357
     358                if (entry->p_filesz == 0) {
     359                        DPRINTF("Zero-sized ELF interp string.\n");
     360                        return EE_INVALID;
     361                }
    358362                if (elf->info->interp[entry->p_filesz - 1] != '\0') {
    359363                        DPRINTF("Unterminated ELF interp string.\n");
  • uspace/lib/c/generic/libc.c

    rc2c4127 r2eadda9  
    6161#endif
    6262
     63progsymbols_t __progsymbols;
     64
    6365static bool env_setup = false;
    6466
     
    116118         * C++ Static constructor calls.
    117119         */
    118         ptrdiff_t init_array_entries = (__init_array_end - __init_array_start);
    119120
    120         for (int i = init_array_entries - 1; i >= 0; --i)
    121                 __init_array_start[i]();
     121        if (__progsymbols.preinit_array) {
     122                for (int i = __progsymbols.preinit_array_len - 1; i >= 0; --i)
     123                        __progsymbols.preinit_array[i]();
     124        }
     125
     126        if (__progsymbols.init_array) {
     127                for (int i = __progsymbols.init_array_len - 1; i >= 0; --i)
     128                        __progsymbols.init_array[i]();
     129        }
    122130
    123131        /*
     
    125133         * according the result
    126134         */
    127         int retval = main(argc, argv);
     135        int retval = __progsymbols.main(argc, argv);
    128136        exit(retval);
    129137}
     
    136144         * when the respective constructor is called.
    137145         */
    138         ptrdiff_t fini_array_entries = (__fini_array_end - __fini_array_start);
    139146
    140         for (int i = 0; i < fini_array_entries; ++i)
    141                 __fini_array_start[i]();
     147        for (int i = 0; i < __progsymbols.fini_array_len; ++i)
     148                __progsymbols.fini_array[i]();
    142149
    143150        if (env_setup) {
     
    148155
    149156        __SYSCALL1(SYS_TASK_EXIT, false);
    150 
    151         /* Unreachable */
    152         while (true)
    153                 ;
     157        __builtin_unreachable();
    154158}
    155159
     
    157161{
    158162        __SYSCALL1(SYS_TASK_EXIT, true);
    159 
    160         /* Unreachable */
    161         while (true)
    162                 ;
     163        __builtin_unreachable();
    163164}
    164165
  • uspace/lib/c/generic/private/libc.h

    rc2c4127 r2eadda9  
    3636#define LIBC_PRIVATE_LIBC_H_
    3737
     38#include <types/common.h>
     39
     40/* Type of the main C function. */
     41typedef int (*main_fn_t)(int, char **);
     42
    3843/**
    3944 * Used for C++ constructors/destructors
     
    4348typedef void (*fini_array_entry_t)();
    4449
    45 extern init_array_entry_t __init_array_start[];
    46 extern init_array_entry_t __init_array_end[];
    47 extern fini_array_entry_t __fini_array_start[];
    48 extern fini_array_entry_t __fini_array_end[];
     50typedef struct {
     51        main_fn_t main;
     52        const void *elfstart;
     53        const void *end;
     54        init_array_entry_t *preinit_array;
     55        int preinit_array_len;
     56        init_array_entry_t *init_array;
     57        int init_array_len;
     58        fini_array_entry_t *fini_array;
     59        int fini_array_len;
     60} progsymbols_t;
    4961
    50 extern unsigned char _end[];
     62extern progsymbols_t __progsymbols;
    5163extern void __libc_main(void *) __attribute__((noreturn));
    5264extern void __libc_exit(int) __attribute__((noreturn));
    5365extern void __libc_abort(void) __attribute__((noreturn));
    54 extern int main(int, char *[]);
    5566
    5667#endif
  • uspace/lib/c/generic/rtld/module.c

    rc2c4127 r2eadda9  
    5151#include <rtld/module.h>
    5252
     53#include "../private/libc.h"
     54
    5355/** Create module for static executable.
    5456 *
     
    7375
    7476        const elf_segment_header_t *tls =
    75             elf_get_phdr(__executable_start, PT_TLS);
     77            elf_get_phdr(__progsymbols.elfstart, PT_TLS);
    7678
    7779        if (tls) {
    78                 uintptr_t bias = elf_get_bias(__executable_start);
     80                uintptr_t bias = elf_get_bias(__progsymbols.elfstart);
    7981                module->tdata = (void *) (tls->p_vaddr + bias);
    8082                module->tdata_size = tls->p_filesz;
  • uspace/lib/c/generic/tls.c

    rc2c4127 r2eadda9  
    4545#include <elf/elf.h>
    4646
     47#include "private/libc.h"
     48
    4749#ifdef CONFIG_RTLD
    4850#include <rtld/rtld.h>
     
    6163
    6264        const elf_segment_header_t *tls =
    63             elf_get_phdr(__executable_start, PT_TLS);
     65            elf_get_phdr(__progsymbols.elfstart, PT_TLS);
    6466
    6567        if (tls == NULL)
     
    8890
    8991        const elf_segment_header_t *tls =
    90             elf_get_phdr(__executable_start, PT_TLS);
     92            elf_get_phdr(__progsymbols.elfstart, PT_TLS);
    9193        if (tls == NULL)
    9294                return NULL;
    9395
    94         uintptr_t bias = elf_get_bias(__executable_start);
     96        uintptr_t bias = elf_get_bias(__progsymbols.elfstart);
    9597        size_t align = max(tls->p_align, _Alignof(tcb_t));
    9698
     
    128130#endif
    129131        const elf_segment_header_t *tls =
    130             elf_get_phdr(__executable_start, PT_TLS);
     132            elf_get_phdr(__progsymbols.elfstart, PT_TLS);
    131133
    132134        assert(tls != NULL);
  • uspace/lib/c/include/elf/elf.h

    rc2c4127 r2eadda9  
    4141#include <libarch/elf.h>
    4242
    43 extern const uint8_t __executable_start[];
    44 
    4543extern const elf_segment_header_t *elf_get_phdr(const void *, unsigned);
    4644extern uintptr_t elf_get_bias(const void *);
  • uspace/lib/posix/Makefile

    rc2c4127 r2eadda9  
    3737SPECS = gcc.specs
    3838LIBC_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
    39 LIBC_STARTUP_FILE = $(START_FILES)
    4039EXPORT_LINKER_SCRIPT = link.ld
    41 EXPORT_STARTUP_FILE = crt0.o
    4240
    4341EXPORT_FILES = \
     
    4745        $(LIBSOFTINT_PREFIX)/libsoftint.a \
    4846        $(LIBC_PREFIX)/libc.a \
     47        $(LIBC_PREFIX)/crt0.o \
     48        $(LIBC_PREFIX)/crt1.o \
    4949        $(LIBRARY).a \
    50         $(EXPORT_STARTUP_FILE) \
    5150        $(EXPORT_LINKER_SCRIPT) \
    5251        $(SPECS)
     
    9594        -L$$(HELENOS_EXPORT_ROOT)/lib \
    9695        -T link.ld \
    97         $(EXPORT_STARTUP_FILE)
     96        $$(HELENOS_EXPORT_ROOT)/lib/crt0.o \
     97        $$(HELENOS_EXPORT_ROOT)/lib/crt1.o
    9898
    9999EXPORT_LDLIBS = \
Note: See TracChangeset for help on using the changeset viewer.