01 March 2023, 22:22 | #1 |
Hardware Designer
Join Date: Aug 2018
Location: Bialystok/Poland
Age: 50
Posts: 178
|
Implementation details of taglist variadic functions
I have looked into implementation of functions like OpenWindowTags(). We know that only OpenWindowTagList() is really in intuition.library, variadic version is created by include files. I use native GCC 2.95.3 and it implements variadic taglist functions as variadic macros, where named version of __VA_ARGS__ is used as content of local array initializer.
Code:
ULONG _tags = {tags}; Compiled code looks weird. Compiler allocates space on stack using LINK instruction, twice the size of the taglist. It fills the taglist with tags and values in the first half on the space, then calls bcopy() to copy the taglist to the second half of the space. Finally it passes address of the copy to OpenWindowTagList(). What is the point of this copy? It also creates a minor problem when linking with -nostdlib, as bcopy() has to be delivered somehow. I have to admit that using variadic function (instead of macro) and just passing address of the first tag argument creates smaller, cleaner and faster code. For example: Code:
struct Window* OpenWindowTags(struct NewWindow *nwin, ULONG tag, ...) { struct TagItem *tags = (struct TagItem*)&tag; return OpenWindowTagList(nwin, tags); } |
02 March 2023, 11:33 | #2 | ||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
amiga.lib. An optional version using compiler-specific pragmas or inlines may be in some compiler-specific header file, when including <proto/intuition.h>. If you include <clib/intuition_protos.h>instead, you can be sure that the version from amiga.libis used. Quote:
__VA_ARGS__is C99, but a named version with {tags}is gcc-specific. Quote:
amiga.liblooks the same as your example. Just link with it. Maybe later gcc code generators create better code, but using macros might not be the best approach here. Quote:
At least it would be more portable than your macro using gcc-specific extensions. When linking with amiga.libyou also eliminate any "dirty hacks", as you only call OpenWindowTags()following the default ABI, the rest is handled there, as your compiler's amiga.libknows the ABI. Maybe it is possible to exclude only the macros for variadic OS-calls from your includes? Don't know about gcc, but at least with vbcc can define -DNO_INLINE_STDARGfor that. |
||||
02 March 2023, 14:53 | #3 | |
Hardware Designer
Join Date: Aug 2018
Location: Bialystok/Poland
Age: 50
Posts: 178
|
Quote:
fd2pragmatool and resides in <inline/intuition.h>, which is included from <proto/intuition.h> Anyway I have defined NO_INLINE_STDARG, downloaded latest NDK, extracted amiga.lib, changed name to libamiga.a, so the linker recognizes it, all fine but... Code:
hunk_drelx not supported yet hunk_drelx not supported yet main.o(.text_0x102): undefined reference to `OpenWindowTags' |
|
02 March 2023, 17:04 | #4 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
That's interesting! My first thought was: ok, your GNU-ld does not support small-data references. But on the other hand the official NDK 3.2
amiga.libshould not contain any small data code at all. So I scanned it for any HUNK_DREL32, HUNK_DREL16or HUNK_DREL8hunks. And I found one HUNK_DREL32in the last unit of the library: "Acrypt.c". HUNK_DREL32is very strange, as there are usually only 16-bit small-data references generated by most Amiga compilers. Don't know if Olaf reads this, otherwise I have to contact him. I don't think this is intended. Quote:
In other words: the library defines _OpenWindowTags. Quote:
|
||
02 March 2023, 19:45 | #5 | |
Hardware Designer
Join Date: Aug 2018
Location: Bialystok/Poland
Age: 50
Posts: 178
|
No, because
nmchokes on this unknown hunk and reports no symbols found. I've also noticed that IRA refuses to disassemble the library for the very same reason. Quote:
gcc -dumpmachineshows "m68k-amigaos". I guess I can write a Python script (to be run on PC) which will parse FD files and generate variadic stubs code. Then I can compile it and have not complete, but working libamiga.a. |
|
04 March 2023, 14:44 | #6 | ||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Or remove the Acrypt.c unit from the 3.2 amiga.lib. In my version it is the last unit (HUNK_UNIT $000003e7, named "ACrypt.c") starting at offset $36534. The last 320 bytes of amiga.lib. Who needs Acrypt anyway... Quote:
Quote:
undefined reference to `OpenWindowTags'. Does the linker automatically translate the symbol names? Does your gcc generate hunk-format, a.out or ELF object files? Quote:
I would use fd2pragma to generate the assembler source for all the stubs (including variadic ones). Code:
fd2pragma -s 90 -t /tmp/ -n .text -i /path/to/NDK_3.2/SFD/intuition_lib.sfd ar q libamiga.a *.o |
||||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
non-constant TagList values and SASC6.58 | alancfrancis | Coders. C/C++ | 5 | 31 May 2021 17:59 |
Calling assembler functions from C | Nosferax | Coders. C/C++ | 41 | 25 March 2020 12:55 |
Calling OS Functions? | nocash | Coders. System | 5 | 03 February 2016 09:27 |
functions benchmark | wawa | Coders. System | 2 | 15 April 2013 18:55 |
How do the non-i/o functions work? | mikro | project.WHDLoad | 3 | 03 November 2011 14:33 |
|
|