Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,18 @@ bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol,
OS << "\t.extern\t";
break;
case MCSA_Weak: OS << MAI->getWeakDirective(); break;
case MCSA_WeakDefinition:
OS << "\t.weak_definition\t";
case MCSA_WeakDefinition: {
// AIX, use the standard weak directive (.weak) instead of
//'.weak_definition' because the AIX assembler does not
// recognize the '.weak_definition' directive.
const llvm::Triple &TT = getContext().getTargetTriple();
if (TT.isOSAIX())
OS << MAI->getWeakDirective();
else
OS << "\t.weak_definition\t";
break;
// .weak_reference
}
// .weak_reference
case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
case MCSA_Cold:
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/MC/MCXCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
Symbol->setStorageClass(XCOFF::C_WEAKEXT);
Symbol->setExternal(true);
break;
case llvm::MCSA_WeakDefinition:
// On AIX/XCOFF, a weak definition symbol should be emitted
// as an external weak symbol (C_WEAKEXT), since the assembler
// does not support '.weak_definition' directly.
Symbol->setStorageClass(XCOFF::C_WEAKEXT);
Symbol->setExternal(true);
break;
case llvm::MCSA_Hidden:
Symbol->setVisibilityType(XCOFF::SYM_V_HIDDEN);
break;
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/MC/PowerPC/aix-weak-definition.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Check that weak_definition symbols are emitted as weak externals.
# Note: On AIX, .weak_definition is mapped to .weak by LLVM's backend.
# RUN: llvm-mc -triple powerpc-ibm-aix-xcoff %s -filetype=obj -o - | \
# RUN: llvm-objdump --syms - | FileCheck %s

.weak_definition foo # LLVM IR WeakDefinition → .weak on AIX
foo:
blr

# CHECK: SYMBOL TABLE:
# CHECK-NEXT: 00000000 df *DEBUG* 00000000 .file
# CHECK-NEXT: 00000000 l .text 00000004
# CHECK-NEXT: 00000000 w F .text (csect: ) 00000000 foo