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

Some shared object constructors are not called #139

Open
capehill opened this issue Jan 2, 2023 · 7 comments
Open

Some shared object constructors are not called #139

capehill opened this issue Jan 2, 2023 · 7 comments

Comments

@capehill
Copy link

capehill commented Jan 2, 2023

Problem: only 1 of 2 constructors in shared object are called. Both constructors are called when library is linked statically. (Both destructors are called in all cases). Not sure if this problem is related to GCC or elf.library or something else.

Using GCC 11.2. Here is a small example:

-- lib.c

#include <stdio.h>

void __attribute__((constructor(101))) ctor()
{
    printf("%s\n", __func__);
}

void  __attribute__((destructor(101))) dtor()
{
    printf("%s\n", __func__);
}

void __attribute__((constructor(102))) ctor2()
{
    printf("%s\n", __func__);
}

void  __attribute__((destructor(102))) dtor2()
{
    printf("%s\n", __func__);
}

int function(int x)
{
    printf("%s %d\n", __func__, x);

    return x;
}

-- main.c

#include <stdio.h>

int function(int);

int main()
{
    int result = function(123);

    printf("%s result %d\n", __func__, result);

    return 0;
}

-- makefile

CC=gcc

all:
	$(CC) -o lib.o -c lib.c -fPIC
	$(CC) -o libf.so lib.o -shared
	ar cruv  libf.a lib.o
	ranlib libf.a
	$(CC) -o test_dyn main.c -use-dynld -L. -lf -athread=native
	$(CC) -o test_static main.c -L. -lf -athread=native

-- output

ctor2 call is missing here:

constructor> test_dyn
ctor
function 123
main result 123
dtor2
dtor
constructor> test_static
ctor
ctor2
function 123
main result 123
dtor2
dtor
@afxgroup
Copy link

afxgroup commented Jan 3, 2023

I think that AmigaLabs/clib4#57 could be related to this

@afxgroup
Copy link

afxgroup commented Mar 6, 2023

New beta elf.library should fix this problem

@raziel-
Copy link

raziel- commented Mar 6, 2023

Hopefully this cures the random crashes i get with ScummVM on start.

otoh the timeframe for releasing the updated lib isn't encouraging

@afxgroup
Copy link

afxgroup commented Mar 6, 2023

That's the main problem.. However I don't know. What you have in the crashlog? Because with actual elf.library the problem happens always and not sometimes

@raziel-
Copy link

raziel- commented Mar 6, 2023

As I said, it's random.
Sometimes ISI, sometimes DSI, coming from everywhere in the code, all of the time on first start, most of the time after some other big programs ran beforehand, e.g. odyssey

Lately not so much, but every fix to the shared objects handling helps:-)

Great work

@khval
Copy link

khval commented Mar 6, 2023 via email

@khval
Copy link

khval commented Mar 6, 2023 via email

3246251196 added a commit to 3246251196/adtools_testing that referenced this issue Mar 31, 2023
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

No branches or pull requests

4 participants