[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] sleep patch
Here is some additional information about weak aliases, since it can be
useful to well understand them for porting existing software or
debugging the MiNTLib.
The weak behavior I described in my previous message is an extension
provided by the GNU linker (ld). It is supported the a.out object file
format, and by the GNU assembler (as) through the directive ".weak".
The documentation in the binutils is pretty poor:
http://sourceware.org/binutils/docs-2.19/as/Weak.html
The syntax ".weak alias = orignal" used by the MiNTLib doesn't seem to
be documented.
The statement "weak_alias" used by the MiNTLib is actually a convenient
macro. It is defined in mintlib/mintlib/libc-symbols.h :
http://sparemint.org/cgi-bin/cvsweb/mintlib/mintlib/libc-symbols.h?rev=1.3&content-type=text/x-cvsweb-markup
We can see it uses directly the ".weak" directive through inline assembly.
GCC can also generate a weak alias to a function by using a prototype
and the attributes "weak" and "alias"
void sleep() __attribute__((weak, alias ("__sleep")));
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Function-Attributes.html#index-g_t_0040code_007balias_007d-attribute-2116
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Function-Attributes.html#index-g_t_0040code_007bweak_007d-attribute-2187
GCC can also generate weak functions, without the need for an alias:
void __attribute__((weak)) sleep() { ... }
GCC can also achieve the same behavior by using "#pragma weak ...", but
it seems to be present only for compatibility purpose.
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Weak-Pragmas.html
--
Vincent Rivière