I am implementing weak linkage support on the ARM backend and I noticed this code on the X86 and PPC backends: ------------------------------------------------ // If the initializer is a extern weak symbol, remember to emit the weak // reference! if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) if (GV->hasExternalWeakLinkage()) ExtWeakSymbols.insert(Mang->getValueName(GV)); ------------------------------------------------ Can a initializer be a weak reference? For example, ------------------------ int a __attribute__ ((weak)); int b = a; ------------------------ fails to compile with the error: test.c:2: error: initializer element is not constant Best Regards, Rafael
On Wed, 6 Dec 2006, [UTF-8] Rafael Esp?ndola wrote:> I am implementing weak linkage support on the ARM backend and I > noticed this code on the X86 and PPC backends: > ------------------------------------------------ > // If the initializer is a extern weak symbol, remember to emit the weak > // reference! > if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) > if (GV->hasExternalWeakLinkage()) > ExtWeakSymbols.insert(Mang->getValueName(GV)); > ------------------------------------------------ > > Can a initializer be a weak reference? For example, > ------------------------ > int a __attribute__ ((weak)); > int b = a;Try: int *B = &a; -Chris -- http://nondot.org/sabre/ http://llvm.org/
> Try: int *B = &a;In LLVM IL this is ------------------------------- %b = global int* %a %a = weak global int 0 ------------------------------- compiling with llc -march=x86-64 produces ----------------------------- .globl b .data .align 8 b: # b .size b, 8 .quad a .comm a,4,4 # a ----------------------------- Note that no ".weak" directive is printed. gcc prints a ".weak a" after the ".quad a". I believe that this is a similar (but more uncommon) problem to one I am having in ARM when a weak symbol is placed is a global table. I will send my current hack to the ML in a minute.> -ChrisThanks, Rafael