-
Notifications
You must be signed in to change notification settings - Fork 65
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
Problems handling weak and external symbols #289
Comments
the reason is: the constructor attribute no longer works. Constructors still do work, since gcc emits code not using this attribute You have to use
the lower the number the early it gets invoked. Stdio is initialized with -30. The constructors are called at -5. And you could simply use the libnix library which already provides what you are doing:
|
Thanks for getting back to me. I was just wondering what the reason was that this feature was removed? It was quite useful. I can add the stabs.h code myself, but other people might also have a problem. I tried your solution of using libnix and it works, although LayoutBase is missing so I had to manually add it to my code. I could probably submit a PR to add that to libnix. Normally I am using clib2. Is there any documentation about the -noixemul flag? I am wondering about the following: m68k-amigaos-gcc -noixemul => Using libnix Is this correct? Perhaps I have accidentally been linking with both ixemul and clib2 in my code. Sorry for all of the questions and thanks for the help! |
Please have a look into the wiki here. |
Thanks for the information! |
I'm a bit confused. I've updated my code and it is working for simple examples but not for something more complex. I suspect something is getting executed before my startup code. You said:
When you say the constructors are called at -5, do you mean the ADD2INIT and ADD2EXIT macros? |
I also have another problem. I switched to using -noixemul but my Reaction based .image and .gadget libraries do not load. For each one, I get the following error:
It seems that the library is trying to open them as "normal" libraries. In this case, the library should be loaded as bitmap.image (from the Sys:Classes/Images directory). The strange thing is that I tried your suggestion a couple of weeks ago and it worked. Has something changed since then? |
It simply did not work in all cases. Feel free to fix the Amiga linker code to get it working the old way. |
It seems that you are using new stuff with a name conflict to old stuff:
means that there existed (was planned?) a You can initialize your library yourself by providing an instantiated variable. A declaration or a definition is not enough:
No auto-open will occur for this
How would I know what you tried and how long a couple of weeks is? /shrug |
I think that would take me about a year to figure out. :-) I am sure that it is quite difficult for you to make this and I appreciate it! I found another problem related to this - not only are the functions marked as attribute((constructor)) not being called, but global C++ constructors are not called either. It took some debugging to track this down because my Amiga just hangs. It's easy to reproduce and I've attached a test case. Just compile it with "m68k-amigaos-g++ Constructor.cpp". If you use an older release of amiga-gcc then it works and prints out "In MyClass constructor" when you run the executable. Compile it with a new release and it doesn't print anything. Thanks and let me know if you need any more information! |
It works as expected:
|
Hello Bebbo. I did a git pull and fresh recompile to make sure I've got the latest source and have some more results: It is the clib2 build the constructor does not work with:
Of course, clib2 is the build I have been using! I also found another curiosity. This also does not work:
But what library is this using by default? All other libraries work but not clib2 and not the default. But the default one creates a binary of a different size to all of the others, so I am wondering what library it is using.
Thanks as always for the help. |
Try passing -v to the compiler to see the detailed invocation parameters |
I had a look and there are a bunch of clib2 related defines and a library path added, but I didn't see anything to explain what is getting built when no -m parameter is passed. I would expect the size to be identical to one of the other builds when no -m parameter is passed (i.e. The build defaults to clib2, nix20 etc. 🧐 |
I adapted the clib2 here to use the section based INIT stuff. Constructors do work again. |
Hello again @bebbo. I took some time to rebuild the latest Amiga GCC on MacOS and Linux can can confirm that it is able to successfully build my software again, and the software works! Many thanks for your work in making this happen - I know some of these GCC issues you have to solve are pretty tough, so it's really appreciated! 😎😁🤩 |
you are welcome |
I have a system for automatically opening libraries that depends on external symbols. One uses it like this:
File.c:
Then at link time, you link with a library that defines IntuitionBase as a weak symbol. Some linker magic then happens which includes this symbol and its module in the executable, thus causing the library to be opened. For libraries that don't have anything referencing their base, their modules don't get included and so the library does not get opened.
It's probably easiest to show with an example. I simplified the bug to two files in the attached WeakSymbols.zip file. TestIntuition.c, which declares and uses IntuitionBase like above, and AutoIntuition.c, which contains the declaration of the IntuitionBase symbol.
Just compile it like this:
If you compile it with last year's 210321150254 GCC release and run the executable on AmigaOS, you output something like this:
But if you compile it with the latest snapshot, you get this:
So it seems that the IntuitionBase symbol is being imported from AutoIntuition.c (because there is no linker error about an undefined symbol) but the OpenIntuitionBase() function, which has the constructor attribute assigned to it, is not getting called, so intuition.library does not get opened.
One interesting (but possibly irrelevant) thing is that the old 210321150254 release gives a warning when compiling the AutoIntuition.c file:
But then it works anyway (it also works if the weak attribute is removed). The warning does not appear when compiling with the latest snapshot.
I tried compiling Amiga GCC using an older snapshot of the amiga-gcc tree but the problem is still happening. So it seems that it is being caused by a newer version of some subproject that is getting pulled in in the projects subdirectory, rather than a change made to code in the amiga-gcc tree itself.
WeakSymbols.zip
The text was updated successfully, but these errors were encountered: