cosmopolitan/libc/intrin/weaken.h

29 lines
1.1 KiB
C
Raw Normal View History

2022-08-11 19:13:18 +00:00
#ifndef COSMOPOLITAN_LIBC_BITS_WEAKEN_H_
#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_
#include "libc/intrin/ezlea.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifndef __STRICT_ANSI__
#define _weaken(symbol) ((const typeof(&(symbol)))_weakaddr(#symbol))
2022-08-11 19:13:18 +00:00
#define _strongaddr(symbolstr) \
({ \
intptr_t waddr; \
asm(_ezlea(symbolstr) "0" : "=r"(waddr)); \
waddr; \
2022-08-11 19:13:18 +00:00
})
#define _weakaddr(symbolstr) \
({ \
intptr_t waddr; \
asm(".weak\t" symbolstr "\n\t" _ezlea(symbolstr) "0" : "=r"(waddr)); \
waddr; \
2022-08-11 19:13:18 +00:00
})
#else
#define _weaken(symbol) symbol
#define _weakaddr(symbolstr) &(symbolstr)
2022-08-11 19:13:18 +00:00
#endif /* __STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_WEAKEN_H_ */