This attribute is ignored, unless base-relative data (see -fbaserel) is compiled.
To improve speed, programs compiled with the AmigaOS port of ‘GCC’ set the ‘a4’ register to the appropriate value only once, in the startup code. Code generated with the standard ‘GCC’ option ‘-fpic’, in contrast, sets the ‘a4’ register in every function which references global data.
This is only safe as long as all function calls are performed from within your own code. Things become “tricky” if callback functions, like the AmigaOS hooks, interrupt handlers etc. are used. If global data is referenced in such functions, ‘a4’ has to be set properly.
This is exactly what the ‘saveds’ attribute does: it initializes ‘a4’ in the function prologue, and restores it to its original value in the function epilogue.
Note: For compatibility with other AmigaOS ‘C’ compilers, a preprocessor symbol ‘__saveds’ is available, which expands to
__attribute__((saveds))(see Keyword macros).
Please do not use this attribute in pure executables (see -resident, see -resident32). This is because several invocations of pure executables can run concurrently, each one having its own data section, and there is no way to find out to which of these sections should ‘a4’ be set.
The ‘saveds’ attribute is not necessary in function declarations (prototypes).
This attribute was first made available in the ‘GCC’ 18.104.22.168, ‘Geek Gadgets’ snapshot ‘961012’.