amiga-gcc icon indicating copy to clipboard operation
amiga-gcc copied to clipboard

Creating self-relocating .library with EH is no longer possible

Open Midar opened this issue 3 years ago • 2 comments

Creating a self-relocating .library with EH used to be possible with amiga-gcc, however, these days, it results in the following linker warning:

.text reloc for __EH_FRAME_BEGINS__ is out of range: 00000000

That doesn't seem right. Interestingly, there is no such warning for EH_FRAME_OBJECTS? So whatever was changed only broke EH_FRAME_BEGINS. I haven't managed to track down which change broke this.

Midar avatar Aug 14 '22 13:08 Midar

so to say: it's more OS4/amiga-ppc compatible atm ;-)

bebbo avatar Aug 14 '22 14:08 bebbo

Hah, good one! ;) But still a regression unfortunately :(

Midar avatar Aug 14 '22 14:08 Midar

So what changed here? Is there any way to work around it?

Midar avatar Oct 14 '22 17:10 Midar

... to keep data segments minimal, all const stuff ends up in the .text segment. no idea without looking at the code...

does your code try to load that via a4? then it will fail.

bebbo avatar Oct 14 '22 17:10 bebbo

change

extern const void * _EH_FRAME_BEGINS__;

into

extern const void * const _EH_FRAME_BEGINS__;

bebbo avatar Oct 14 '22 18:10 bebbo

Hmm, that seems to make the warning go away again, but it still fails at

        if ((size_t)_EH_FRAME_BEGINS__ != (size_t)_EH_FRAME_OBJECTS__)
                return false;

The first one used to be the count, is that no longer the case?

Midar avatar Oct 14 '22 18:10 Midar

comparing pointers without de-referencing? the pointers are different.

And the counters are gone, since the constructors are a relict from the past. Well, you can create counters using the linker scripts but that raises different problems,

current lib code is:

void __init_eh() {
    void ** frame = _EH_FRAME_BEGINS__;
    void ** object = _EH_FRAME_OBJECTS__;
    
    while (*frame) {
      __register_frame_info(*frame++, *object++);
    }
}

bebbo avatar Oct 14 '22 18:10 bebbo

That seems to have worked, thanks. However, I need to change it back to non-const and get a warning, because otherwise I get an immediate crash.

Midar avatar Oct 14 '22 19:10 Midar

Unrelated: Why are there .a files checked into the repository under lib?

Midar avatar Oct 14 '22 19:10 Midar

Unrelated: Why are there .a files checked into the repository under lib?

because these aren't build?

bebbo avatar Oct 14 '22 19:10 bebbo

It seems that there's even more broken in amiga-gcc. It now opens the library but then just hangs. When compiling it without library support, it just says "Program aborted" - that is even if I #define abort to something that prints an error, and it never gets printed. The same code worked with older amiga-gcc and works perfectly fine when compiled for MorphOS using the MorphOS SDK. Is there any way to figure out where this abort call is coming from if not from my code?

Midar avatar Oct 16 '22 17:10 Midar

you need something like:

amiga-library.m

#ifdef OF_AMIGAOS_M68K
__attribute__((section(".list___CTOR_LIST__")))
const uintptr_t __CTOR_LIST__ = 0;
__attribute__((section(".list___EH_FRAME_BEGINS__")))
const uintptr_t _EH_FRAME_BEGINS__ = 0;
__attribute__((section(".list___EH_FRAME_OBJECTS__")))
uintptr_t _EH_FRAME_OBJECTS__ = 0;
#endif

and use it like

			for (const uintptr_t *frame = 1 + &_EH_FRAME_BEGINS__;
			    *frame != 0;)
				libc.__deregister_frame_info((const void *)*frame++);

plus an end file: amiga-end.m

#ifdef OF_AMIGAOS_M68K
__attribute__((section(".list___CTOR_LIST__")))
long a_random_name1 = 0;
__attribute__((section(".list___EH_FRAME_BEGINS__")))
long a_random_name2 = 0;
__attribute__((section(".list___EH_FRAME_OBJECTS__")))
long a_random_name3 = 0;
#endif

bebbo avatar Oct 17 '22 19:10 bebbo

I could remove the requirement of an end file. Read here: https://github.com/bebbo/amiga-gcc/wiki/Constructors,-Destructors,-Managed-Lists

bebbo avatar Nov 01 '22 08:11 bebbo