diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -800,11 +800,6 @@ void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility( MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) { - // Print symbol's rename (original name contains invalid character(s)) if - // there is one. - if (cast(Symbol)->hasRename()) - emitXCOFFRenameDirective(Symbol, - cast(Symbol)->getSymbolTableName()); switch (Linkage) { case MCSA_Global: @@ -839,6 +834,12 @@ report_fatal_error("unexpected value for Visibility type"); } EmitEOL(); + + // Print symbol's rename (original name contains invalid character(s)) if + // there is one. + if (cast(Symbol)->hasRename()) + emitXCOFFRenameDirective(Symbol, + cast(Symbol)->getSymbolTableName()); } void MCAsmStreamer::emitXCOFFRenameDirective(const MCSymbol *Name, @@ -868,12 +869,6 @@ void MCAsmStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { - // Print symbol's rename (original name contains invalid character(s)) if - // there is one. - MCSymbolXCOFF *XSym = dyn_cast(Symbol); - if (XSym && XSym->hasRename()) - emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName()); - OS << "\t.comm\t"; Symbol->print(OS, MAI); OS << ',' << Size; @@ -885,6 +880,13 @@ OS << ',' << Log2_32(ByteAlignment); } EmitEOL(); + + // Print symbol's rename (original name contains invalid character(s)) if + // there is one. + MCSymbolXCOFF *XSym = dyn_cast(Symbol); + if (XSym && XSym->hasRename()) + emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName()); + } void MCAsmStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -124,9 +124,10 @@ MCSymbolXCOFF *TCSym = cast(Streamer.getContext().getOrCreateSymbol( XSym->getSymbolTableName() + "[TC]")); + OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << '\n'; + if (TCSym->hasRename()) Streamer.emitXCOFFRenameDirective(TCSym, TCSym->getSymbolTableName()); - OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << '\n'; return; } diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll --- a/llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll @@ -40,10 +40,10 @@ ; This is f@o declare i32 @"f\40o"(...) -; ASM: .rename _Renamed..24f_o[DS],"f$o" # -- Begin function f$o -; ASM-NEXT: .lglobl _Renamed..24f_o[DS] -; ASM-NEXT: .rename ._Renamed..24f_o,".f$o" +; ASM: .lglobl _Renamed..24f_o[DS] # -- Begin function f$o +; ASM-NEXT: .rename _Renamed..24f_o[DS],"f$o" ; ASM-NEXT: .lglobl ._Renamed..24f_o +; ASM-NEXT: .rename ._Renamed..24f_o,".f$o" ; ASM-NEXT: .align 4 ; ASM-NEXT: .csect _Renamed..24f_o[DS],2 ; ASM-NEXT: .vbyte 4, ._Renamed..24f_o # @"f$o" @@ -53,10 +53,10 @@ ; ASM-NEXT: ._Renamed..24f_o: ; ASM: bl ._Renamed..40f_o ; ASM-NEXT: nop -; ASM: .rename _Renamed..26f_o[DS],"f&o" # -- Begin function f&o -; ASM-NEXT: .globl _Renamed..26f_o[DS] -; ASM-NEXT: .rename ._Renamed..26f_o,".f&o" +; ASM: .globl _Renamed..26f_o[DS] # -- Begin function f&o +; ASM-NEXT: .rename _Renamed..26f_o[DS],"f&o" ; ASM-NEXT: .globl ._Renamed..26f_o +; ASM-NEXT: .rename ._Renamed..26f_o,".f&o" ; ASM-NEXT: .align 4 ; ASM-NEXT: .csect _Renamed..26f_o[DS],2 ; ASM-NEXT: .vbyte 4, ._Renamed..26f_o # @"f&o" @@ -65,10 +65,10 @@ ; ASM-NEXT: .csect .text[PR],2 ; ASM-NEXT: ._Renamed..26f_o: ; ASM: bl ._Renamed..24f_o -; ASM: .rename _Renamed..265ff__o[DS],"f&_o" # -- Begin function f&_o -; ASM-NEXT: .globl _Renamed..265ff__o[DS] -; ASM-NEXT: .rename ._Renamed..265ff__o,".f&_o" +; ASM: .globl _Renamed..265ff__o[DS] # -- Begin function f&_o +; ASM-NEXT: .rename _Renamed..265ff__o[DS],"f&_o" ; ASM-NEXT: .globl ._Renamed..265ff__o +; ASM-NEXT: .rename ._Renamed..265ff__o,".f&_o" ; ASM-NEXT: .align 4 ; ASM-NEXT: .csect _Renamed..265ff__o[DS],2 ; ASM-NEXT: .vbyte 4, ._Renamed..265ff__o # @"f&_o" @@ -77,21 +77,21 @@ ; ASM-NEXT: .csect .text[PR],2 ; ASM-NEXT: ._Renamed..265ff__o: ; ASM: .csect .data[RW],2 -; ASM-NEXT: .rename _Renamed..60f_o,"f`o" ; ASM-NEXT: .globl _Renamed..60f_o +; ASM-NEXT: .rename _Renamed..60f_o,"f`o" ; ASM-NEXT: .align 2 ; ASM-NEXT: _Renamed..60f_o: ; ASM-NEXT: .vbyte 4, 10 # 0xa -; ASM-NEXT: .rename _Renamed..2222f_o_[RW],"f""o""" ; ASM-NEXT: .comm _Renamed..2222f_o_[RW],4,2 -; ASM-NEXT: .rename ._Renamed..40f_o,".f@o" +; ASM-NEXT: .rename _Renamed..2222f_o_[RW],"f""o""" ; ASM-NEXT: .extern ._Renamed..40f_o -; ASM-NEXT: .rename _Renamed..40f_o[DS],"f@o" +; ASM-NEXT: .rename ._Renamed..40f_o,".f@o" ; ASM-NEXT: .extern _Renamed..40f_o[DS] +; ASM-NEXT: .rename _Renamed..40f_o[DS],"f@o" ; ASM-NEXT: .toc ; ASM-NEXT: L..C0: -; ASM-NEXT: .rename _Renamed..40f_o[TC],"f@o" ; ASM-NEXT: .tc _Renamed..40f_o[TC],_Renamed..40f_o[DS] +; ASM-NEXT: .rename _Renamed..40f_o[TC],"f@o" ; OBJ: Disassembly of section .text: ; OBJ-EMPTY: