mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 15:43:56 +00:00
Cleanup shared-object support mechanics
The former ldso-startup static library (now called ldso_so_support) is used to spice each shared object/library with local support code for the dynamic linker (execution of static constructors and ARM-EABI). Therefore, the library must be statically linked to each dynamic library. As a result recipes for dynamic libraries must always depend on the "so" API, which makes ldso_so_support.mk and so_support.c available independent of "base". Additionally, ldso_so_support is also provided in the libc API to cut the dependency early for libc/posix libraries. Issue #3720
This commit is contained in:
committed by
Norman Feske
parent
589b416ca8
commit
42fddf8390
71
repos/base/src/lib/ldso/so_support.c
Normal file
71
repos/base/src/lib/ldso/so_support.c
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* \brief Shared-object support code
|
||||
* \author Sebastian Sumpf
|
||||
* \author Christian Helmuth
|
||||
* \date 2009-08-14
|
||||
*
|
||||
* Support code comprises hooks for execution of static constructors and
|
||||
* ARM-EABI dynamic linking.
|
||||
*
|
||||
* The ARM cross compiler uses the __gnu_Unwind_Find_exidx hook to locate a
|
||||
* 'ARM.exidx' section within a shared object. For this to work
|
||||
* 'dl_unwind_find_exidx' is excuted by 'ldso', which returns the section
|
||||
* address if it finds a shared object within the range of the provieded
|
||||
* program counter.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009-2020 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#define BEG { (ld_hook) ~1U }
|
||||
#define END { (ld_hook) 0 }
|
||||
#define SECTION(x) __attribute__((used,section( x )))
|
||||
|
||||
typedef void (*ld_hook)(void);
|
||||
static ld_hook _lctors_start[1] SECTION("_mark_ctors_start") = BEG;
|
||||
static ld_hook _lctors_end[1] SECTION("_mark_ctors_end") = END;
|
||||
|
||||
/*
|
||||
* '__dso_handle' needs to be defined in the main program and in each shared
|
||||
* object. Because ld.lib.so is both of them, '__dso_handle' is weak here.
|
||||
*/
|
||||
void *__dso_handle __attribute__((__visibility__("hidden")))
|
||||
__attribute__((weak)) = &__dso_handle;
|
||||
|
||||
/* called by dynamic linker on library startup (ld.lib.so) */
|
||||
extern void _init(void) __attribute__((used,section(".init")));
|
||||
extern void _init(void)
|
||||
{
|
||||
/* call static constructors */
|
||||
for (ld_hook *func = _lctors_end; func > _lctors_start + 1; (*--func)());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* from gcc/config/arm/unwind-arm.h
|
||||
*/
|
||||
typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
|
||||
|
||||
|
||||
/*
|
||||
* Dummy for static libs, implemented in ldso for dynamic case
|
||||
*/
|
||||
extern _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount) __attribute__((weak));
|
||||
extern _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called from libgcc_eh.a file 'gcc/config/arm/unwind-arm.c' in function
|
||||
* 'get_eit_entry'
|
||||
*/
|
||||
extern _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int *pcount)
|
||||
{
|
||||
return dl_unwind_find_exidx(pc, pcount);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* \brief Shared object startup code
|
||||
* \author Sebastian Sumpf
|
||||
* \date 2009-08-14
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2009-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#define BEG { (ld_hook) ~1U }
|
||||
#define END { (ld_hook) 0 }
|
||||
#define SECTION(x) __attribute__((used,section( x )))
|
||||
|
||||
typedef void (*ld_hook)(void);
|
||||
static ld_hook _lctors_start[1] SECTION("_mark_ctors_start") = BEG;
|
||||
static ld_hook _lctors_end[1] SECTION("_mark_ctors_end") = END;
|
||||
|
||||
/*
|
||||
* '__dso_handle' needs to be defined in the main program and in each shared
|
||||
* object. Because ld.lib.so is both of them, '__dso_handle' is weak here.
|
||||
*/
|
||||
void *__dso_handle __attribute__((__visibility__("hidden")))
|
||||
__attribute__((weak)) = &__dso_handle;
|
||||
|
||||
/* called by dynamic linker on library startup (ld-genode.so) */
|
||||
extern "C" {
|
||||
void _init(void) __attribute__((used,section(".init")));
|
||||
|
||||
void _init(void)
|
||||
{
|
||||
/* call static constructors */
|
||||
for(ld_hook *func = _lctors_end; func > _lctors_start + 1; (*--func)());
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* \brief Our implementation of __gnu_Unwind_Find_exidx
|
||||
* \author Sebastian Sumpf <Sebastian.Sumpf@genode-labs.com>
|
||||
* \date 2010-07-05
|
||||
*
|
||||
* This file is used for ARM-EABI dynamic linking, only. The ARM cross-compiler
|
||||
* uses this hook to locate a 'ARM.exidx' section within a shared object. For
|
||||
* this to work 'dl_unwind_find_exidx' is excuted by 'ldso', which returns the
|
||||
* section address if it finds a shared object within the range of the provieded
|
||||
* progam counter
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#include <base/log.h>
|
||||
|
||||
/*
|
||||
* from gcc/config/arm/unwind-arm.h
|
||||
*/
|
||||
typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
|
||||
|
||||
|
||||
/*
|
||||
* Implemented in ldso
|
||||
* */
|
||||
extern "C" _Unwind_Ptr __attribute__((weak)) dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount);
|
||||
extern "C" _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr /* pc */, int * /* pcount */)
|
||||
{
|
||||
Genode::error("dl_unwind_find_exidx called");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called from libgcc_eh.a file 'gcc/config/arm/unwind-arm.c' in function
|
||||
* 'get_eit_entry'
|
||||
*/
|
||||
extern "C" _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int *pcount)
|
||||
{
|
||||
return dl_unwind_find_exidx(pc, pcount);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user