This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Changing __weak_reference


Hi guys,


I have a question about the __weak_reference definition in
libc/include/sys/cdefs.h.  Our definition in cdefs.h is 11 years old,
added when the linux code has been added to newlib.

However, the definition in cdefs.h is not state of the art and even
wrong in parts.  The current BSD definition only has one argument,
while the newlib definition has two.  On non-ELF targets the newlib
implementation assumes .stabs, whether the target uses it or not.

For that reason, I'd like to change __weak_reference in a backward
incompatible way to the latest definition used on the BSDs, along 
these lines:

--- SNIP --- #ifdef __GNUC__
#if __STDC__
#define __strong_alias(alias,sym)                                       \
    __asm(".global " __ASMNAME(#alias) "\n"                       \
            __ASMNAME(#alias) " = " __ASMNAME(#sym));

#define __weak_alias(alias,sym)                                         \
    __asm(".weak " __ASMNAME(#alias) "\n"                 \
            __ASMNAME(#alias) " = " __ASMNAME(#sym));

/* Do not use __weak_extern, use __weak_reference instead */
#define __weak_extern(sym)                                              \
    __asm(".weak " __ASMNAME(#sym));

#if __GNUC_PREREQ__(4, 0)
#define __weak_reference(sym)   __attribute__((__weakref__(#sym)))
#else
#define __weak_reference(sym)   ; __asm(".weak " __ASMNAME(#sym))
#endif

#if __GNUC_PREREQ__(4, 2)
#define __weakref_visible       static
#else
#define __weakref_visible       extern
#endif

#ifdef __LEADING_UNDERSCORE
#define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
#define ___weak_alias(alias,sym)                                        \
    __asm(".weak alias\nalias = sym");
#else
#define __weak_alias(alias,sym)                                         \
    __asm(".weak alias\nalias = sym");
#endif
#ifdef __LEADING_UNDERSCORE
#define __weak_extern(sym) ___weak_extern(_/**/sym)
#define ___weak_extern(sym)                                             \
    __asm(".weak sym");
#else
#define __weak_extern(sym)                                              \
    __asm(".weak sym");
#endif
#define __warn_references(sym,msg)                                      \
    __asm(".pushsection .gnu.warning.sym\n"                             \
          ".ascii \"" msg "\"\n"                                        \
          ".popsection");

#endif /* !__STDC__ */
#endif /* !__GNUC__ */
--- SNAP ---

Does anybody see a problem with that?  Within newlib, __weak_reference
is only used inside of the Linux code.  That's easily fixable.  Do
you know any external projects which rely on the current newlib
definition of __weak_reference?

Alternatively, shall we keep the old definition, and provide a macro
to switch to the old definition?


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]