Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTLD] Add support for PIC and being build as shared library #334

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

badochov
Copy link
Contributor

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@badochov badochov requested a review from agkaminski January 30, 2024 14:57
@badochov
Copy link
Contributor Author

FIrst 3 commits are from different PRs

Copy link

github-actions bot commented Jan 31, 2024

Unit Test Results

6 780 tests   - 920   6 154 ✅  - 831   31m 19s ⏱️ - 8m 9s
  380 suites  -  56     626 💤  -  89 
    1 files   ±  0       0 ❌ ±  0 

Results for commit 77c8fec. ± Comparison against base commit 3375557.

This pull request removes 920 tests.
flash ‑ armv7a9-zynq7000-zedboard:flash
phoenix-rtos-tests/cpp/hello-cpp ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/cpp/hello-cpp
phoenix-rtos-tests/initfini/main ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/initfini/main
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.data_in
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.data_in_big
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.data_inout
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.data_inout_big
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.data_out
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.data_out_big
phoenix-rtos-tests/ioctl/unit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/ioctl/unit.ioctl.in_val
…

♻️ This comment has been updated with latest results.

@badochov badochov force-pushed the badochov/dynamic-linker branch 3 times, most recently from c2c4a95 to cfc9a6e Compare February 2, 2024 13:23
@badochov badochov force-pushed the badochov/dynamic-linker branch from cfc9a6e to 77c8fec Compare August 5, 2024 17:06
@badochov badochov force-pushed the badochov/dynamic-linker branch from 77c8fec to ddc8fe7 Compare August 16, 2024 12:36
Comment on lines +76 to +77
__attribute__((noreturn))
extern void endthreadsvc(void);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
__attribute__((noreturn))
extern void endthreadsvc(void);
__attribute__((noreturn)) extern void endthreadsvc(void);

sys/threads.c Outdated

/* Provide stub definition of tls managing functions for statically linked programs. */

static void _libphoenix_stub(void){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
static void _libphoenix_stub(void){
static void _libphoenix_stub(void)
{

sys/threads.c Outdated
Comment on lines 29 to 30
extern void __attribute__((weak, alias("_libphoenix_stub"))) _rtld_tls_free_curr(void);
extern void __attribute__((weak, alias("_libphoenix_stub"))) _rtld_tls_allocate_curr(void);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
extern void __attribute__((weak, alias("_libphoenix_stub"))) _rtld_tls_free_curr(void);
extern void __attribute__((weak, alias("_libphoenix_stub"))) _rtld_tls_allocate_curr(void);
extern void __attribute__((weak, alias("_libphoenix_stub"))) _rtld_tls_free_curr(void);
extern void __attribute__((weak, alias("_libphoenix_stub"))) _rtld_tls_allocate_curr(void);

sys/threads.c Outdated


/* FIXME: Hack to provide tls support in dynamically loaded binaries. */
void beginthreadex_wrapper(void* arg) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
void beginthreadex_wrapper(void* arg) {
void beginthreadex_wrapper(void *arg)
{

sys/threads.c Outdated
start(startArg);
}

int beginthreadex(void (*start)(void *), unsigned int priority, void *stack, unsigned int stacksz, void *arg, handle_t *id) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
int beginthreadex(void (*start)(void *), unsigned int priority, void *stack, unsigned int stacksz, void *arg, handle_t *id) {
int beginthreadex(void (*start)(void *), unsigned int priority, void *stack, unsigned int stacksz, void *arg, handle_t *id)
{

sys/threads.c Outdated
Comment on lines 53 to 54
__attribute__((noreturn))
void endthread(void) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
__attribute__((noreturn))
void endthread(void) {
__attribute__((noreturn)) void endthread(void)
{

@badochov badochov force-pushed the badochov/dynamic-linker branch from ddc8fe7 to 9fe5f55 Compare August 16, 2024 12:56
Comment on lines +25 to +28
#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_GLOBAL 0x100
#define RTLD_LOCAL 0x200

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_GLOBAL 0x100
#define RTLD_LOCAL 0x200
#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_GLOBAL 0x100
#define RTLD_LOCAL 0x200

Comment on lines +39 to +43
int dladdr(const void *restrict, Dl_info_t *restrict);
int dlclose(void *);
char *dlerror(void);
void *dlopen(const char *, int);
void *dlsym(void *restrict, const char *restrict);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
int dladdr(const void *restrict, Dl_info_t *restrict);
int dlclose(void *);
char *dlerror(void);
void *dlopen(const char *, int);
void *dlsym(void *restrict, const char *restrict);
int dladdr(const void *restrict, Dl_info_t *restrict);
int dlclose(void *);
char *dlerror(void);
void *dlopen(const char *, int);
void *dlsym(void *restrict, const char *restrict);

@badochov badochov force-pushed the badochov/dynamic-linker branch from 2caa8d8 to b72127e Compare August 21, 2024 11:22
rtld/stubs.c Outdated


extern void *__tls_get_addr(void *) __attribute__((weak, alias("__libphoenix__tls_get_addr")));
extern void *___tls_get_addr(void *) __attribute__((weak, alias("__libphoenix___tls_get_addr"))) __attribute__((__regparm__(1))) ;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
extern void *___tls_get_addr(void *) __attribute__((weak, alias("__libphoenix___tls_get_addr"))) __attribute__((__regparm__(1))) ;
extern void *___tls_get_addr(void *) __attribute__((weak, alias("__libphoenix___tls_get_addr"))) __attribute__((__regparm__(1)));

@badochov badochov force-pushed the badochov/dynamic-linker branch 3 times, most recently from ab44ee8 to fd5b08c Compare August 27, 2024 16:02
static int _libc_initialized;


/* _libc_init is called twice once explicitely in crt0 and once during constructor handling.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[codespell] reported by reviewdog 🐶
explicitely ==> explicitly



/* _libc_init is called twice once explicitely in crt0 and once during constructor handling.
* If libc is linked statically first it is called explicitely and then during constructor handling.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[codespell] reported by reviewdog 🐶
explicitely ==> explicitly

@badochov badochov force-pushed the badochov/dynamic-linker branch 2 times, most recently from 3243e14 to 9547eeb Compare August 29, 2024 16:13
.text

.thumb_func
/* Declared as weak to be overriden by dynamic linker */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[codespell] reported by reviewdog 🐶
overriden ==> overridden

*
* void *__tls_get_addr(TLS_index *ti) */

/* Declared as weak to be overriden by dynamic linker */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[codespell] reported by reviewdog 🐶
overriden ==> overridden

@badochov badochov force-pushed the badochov/dynamic-linker branch from 9547eeb to bee4ca6 Compare September 2, 2024 16:43
rtld/stubs.c Outdated
}


__attribute__((weak)) void *__tls_get_addr(void *d) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
__attribute__((weak)) void *__tls_get_addr(void *d) {
__attribute__((weak)) void *__tls_get_addr(void *d)
{

rtld/stubs.c Outdated
}


__attribute__((weak)) void *___tls_get_addr(void *d) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
__attribute__((weak)) void *___tls_get_addr(void *d) {
__attribute__((weak)) void *___tls_get_addr(void *d)
{

@badochov badochov force-pushed the badochov/dynamic-linker branch from bee4ca6 to cae7c5e Compare September 2, 2024 17:01
rtld/stubs.c Outdated


/* As dynamic linker is not added as a NEEDED dependency in libphoenix, stub implementation are required.
* They are overriden by dynamic linkers functions in runtime. */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[codespell] reported by reviewdog 🐶
overriden ==> overridden

rtld/stubs.c Outdated


/* Stub __tls_get_addr implementations.
* They can be overriden on platforms requiring __tls_get_addr in PIC compiled platforms(eg. RISC-V, ARM).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[codespell] reported by reviewdog 🐶
overriden ==> overridden

@badochov badochov force-pushed the badochov/dynamic-linker branch 3 times, most recently from 1fbfbc1 to 531abff Compare September 5, 2024 14:21
@badochov badochov force-pushed the badochov/dynamic-linker branch 2 times, most recently from 4e2bbe9 to 0bf6d7d Compare September 6, 2024 10:37
rtld/stubs.c Outdated
}


__attribute__((weak)) void __rtld_atfork(int pre) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
__attribute__((weak)) void __rtld_atfork(int pre) {
__attribute__((weak)) void __rtld_atfork(int pre)
{

@badochov badochov force-pushed the badochov/dynamic-linker branch 2 times, most recently from 6f6f34b to ab58b63 Compare September 12, 2024 10:42
@badochov badochov force-pushed the badochov/dynamic-linker branch 4 times, most recently from d761924 to 0ba38c3 Compare September 18, 2024 07:35
@badochov badochov force-pushed the badochov/dynamic-linker branch 5 times, most recently from a561b47 to 47a6b37 Compare October 6, 2024 16:31
@badochov badochov force-pushed the badochov/dynamic-linker branch 2 times, most recently from 90eeca8 to 046a16f Compare October 25, 2024 14:32
badochov and others added 12 commits December 5, 2024 13:26
In PIE on ia32 function calls should be made using GOT.

JIRA: RTOS-664
This allows constructor handling mechanism in dynamic linker.

JIRA: RTOS-664
@badochov badochov force-pushed the badochov/dynamic-linker branch from 046a16f to 5a9ff9b Compare December 5, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant