amiga-gcc
amiga-gcc copied to clipboard
Crashes on 68000 CPU when exceptions are enabled
I've just found out that some code does crash on a 68000 CPU when exceptions are used:
#include <dos/dos.h>
#include <stdio.h>
class A
{
public:
A()
: m_pText("Hey\n")
{
}
void Run()
{
printf("%s", m_pText);
}
private:
const char* m_pText;
};
int main(void)
{
try
{
A a;
a.Run();
return RETURN_OK;
}
catch(const char* pMsg)
{
printf("%s\n", pMsg);
return RETURN_FAIL;
}
}
$ m68k-amigaos-g++ exc_test.cpp -o exc_test -noixemul
The binary crashes on a WinUAE config with CPU set to 68000. With 68020 it works.
Maybe there's some CPU-dependent code generated when using exceptions?
Guess this one is not fixable: the exception info may lead to a word read from an odd address, which raises an address error trap on the 68000
but the above code is working here in WinUAE without problems.
Note that binaries created with -noixemul
do not work on kickstart 1.3
You have to use -mcrt=nix13
I've run the code in WinUAE on a A600 config but using 3.1 ROMs 40.63 (A500, A600, A2000) and a Workbench 3.1, 1MB ChipRAM, most compatible settings.
But I understand that the odd addresses can be a problem on the non-32-bit 68000.
Thanks for explaining.
please test
Thanks for reopening this.
But I did a quick test and recompiled the above example with m68k-amigaos-gcc (GCC) 6.5.0b 211205132514 and it still did crash.
But as I've no real hardware 68000 Amiga, I used a WinUAE config. Maybe I choose some problematic settings in WinUAE, I'll check it soon.
here are some tests (including your file) exception.zip
addresserror crashes on A500 and both others do work now.
All these binaries crash on my config, an emulated A600 with 3.1 ROM and plain Workbench 3.1 install on DH0, mapped to an Windows-Folder (no HDF).
Here some pictures of the config:
And the crash:
Is something obviously wrong?
duh - my more compatible
is not checked here - now the guru is visiting me too...
They also work on my config. Great!
the fix is live, you need
make update
make clean-libgcc
make libgcc
Great, now the example above now works on my 68000 config, and so does also my own program ADiffView.
So I can release a new version with 68000 compatibility soon:-)
Thank you for fixing this:thumbsup:
nice app. and thanks for reporting/testing!
I have a strange problem here about exceptions. But it has nothing to do with 68000/68020+.
When I do a throw in the constructor of a certain class, the program crashes. However, it works for other classes/constructors. It also works without crashing if I compile with -O0 instead of -O2.
I pushed the example with the crash to a different branch
For example the linked file DiffDocument.h. There in line 98 the DiffEngine is instantiated. Although this is empty in this example and only throws an exception in the constructor, it crashes at this point.
But if I activate DiffEngineFake, which is implemented directly on top in DiffDocument.h, it works. The DiffEngineFake exception is thrown, no crash.
If I move the instantiation of DiffEngineFake below that of DiffEngine, it now also works: Now the exception of DiffEngine is thrown, no crash.
If I now comment out DiffEngineFake, it crashes again.
I don't want to waste your time with my issues, but could it be somehow related to the gcc 6.5 and the exception implementation?
I'm only asking this because I'm a little stumped on this behavior.
please provide a more simple test case. cmake ..
only builds it for Linux.
Yeah that's right, I'm using WSL2 with Debian installed.
In the next few days I will try to find a simpler example that also crashes. But somehow I already fear that it is due to the context of my project and only reproducible there:D
how do you build that for the Amiga?
In Windows I have WinUAE installed, and in its config I add a harddrive DH1 as directory with the directory path set to
\\wsl$\Debian\home\username\amiga-share\
And in Linux the whole repository is cloned into that
/home/username/amiga-share
directory. All the cmake/make/gcc tools work from there and the binaries are created directly in the repository directory.
In Windows I have some WinUAE configs, e.g. a basic A1200 one which also use the amiga-share as DH1 and from their startup-sequence directly start the given binary (e.g. ADiffView_gcc). So, for example on my Windows desktop I have an icon / link ADiffView which on double click starts its WinUAE config with the current binarie I compiled seconds ago from Linux.
For coding in Windows I use VSCode. When I there open the folder
\\wsl$\Debian\home\username\amiga-share\ADiffView\
it automatically switches to WSL/Linux mode with the Linux console integrated at the bottom. <Ctrl+Shift+b> builds directly from VSCode.
I've attached a minimal example that crashes when loaded from the startup-sequence of a basic an A1200 config.
The crash is coming from the instantiation of DiffEngine in DiffDocument.h, line 87. When this line is commented out it doesn't crash after rebuild.
The latter example is not related to odd addresses, it's an unwinding issue.
with amiga13.1 this prints Exception