The attached patch makes the ASM printer print the ".weak" directive when a weak symbol is added to a constant pool. I need something similar to it in order to bootstrap gcc on ARM. Any comments? Best Regards, Rafael -------------- next part -------------- A non-text attachment was scrubbed... Name: llvm.patch Type: text/x-patch Size: 1816 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20061207/c952d4d4/attachment.bin>
On Thu, 7 Dec 2006, [UTF-8] Rafael Esp?ndola wrote:> The attached patch makes the ASM printer print the ".weak" directive > when a weak symbol is added to a constant pool. > > I need something similar to it in order to bootstrap gcc on ARM.--- lib/CodeGen/AsmPrinter.cpp 7 Dec 2006 01:30:31 -0000 1.120 +++ lib/CodeGen/AsmPrinter.cpp 7 Dec 2006 13:00:17 -0000 @@ -640,6 +640,13 @@ printDataDirective(type); EmitConstantValueOnly(CV); O << "\n"; + if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) { + if (GV->hasWeakLinkage() || GV->hasExternalWeakLinkage()) { + O << TAI->getWeakRefDirective(); + EmitConstantValueOnly(CV); + O << "\n"; + } + } } The approach looks good, but why do you need both 'hasWeak' and 'hasExternalWeak' here? It seems that this should only check the external weak case. I think what we really want is for the asmprinter base-class to call a virtual method when it sees external weak uses. This would allow the asmprinter implementation to add it to the set of things that a .weak directive needs to be emitted for. That way we'd only get one .weak directive for a global, instead of one per use. Thoughts? -Chris -- http://nondot.org/sabre/ http://llvm.org/
> The approach looks good, but why do you need both 'hasWeak' and > 'hasExternalWeak' here? It seems that this should only check the external > weak case.Yes, we need the hasWeak also. Consider the code (from your previous email): ---------------------------- %b = global int* %a %a = weak global int 0 ---------------------------- The C backend produces a ".weak a" directive, the hasWeak call is there to make sure the AsmPrinter prints one to.> I think what we really want is for the asmprinter base-class to call a > virtual method when it sees external weak uses. This would allow the > asmprinter implementation to add it to the set of things that a .weak > directive needs to be emitted for. That way we'd only get one .weak > directive for a global, instead of one per use. > Thoughts? >Do we really need a virtual method? I think that all backends will want to print the .weak directives. If it doesn't, It can just set WeakRefDirective to NULL. I will try to implement a patch that prints only one directive per global.> -Chris >Best Regards, Rafael