Skip to content

Commit 43fbfa2

Browse files
committed
[PowerPC][AIX] Emit weak_definition symbols as weak externals
- On AIX, the assembler does not recognize '.weak_definition'. - Emit MCSA_WeakDefinition symbols using the standard weak directive (.weak) and set storage class to C_WEAKEXT in XCOFF. - Added test llvm/test/MC/PowerPC/aix-weak-definition.s
1 parent f65f60e commit 43fbfa2

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,18 @@ bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol,
764764
OS << "\t.extern\t";
765765
break;
766766
case MCSA_Weak: OS << MAI->getWeakDirective(); break;
767-
case MCSA_WeakDefinition:
768-
OS << "\t.weak_definition\t";
767+
case MCSA_WeakDefinition: {
768+
// AIX, use the standard weak directive (.weak) instead of
769+
//'.weak_definition' because the AIX assembler does not
770+
// recognize the '.weak_definition' directive.
771+
const llvm::Triple &TT = getContext().getTargetTriple();
772+
if (TT.isOSAIX())
773+
OS << MAI->getWeakDirective();
774+
else
775+
OS << "\t.weak_definition\t";
769776
break;
770-
// .weak_reference
777+
}
778+
// .weak_reference
771779
case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
772780
case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
773781
case MCSA_Cold:

llvm/lib/MC/MCXCOFFStreamer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
7272
Symbol->setStorageClass(XCOFF::C_WEAKEXT);
7373
Symbol->setExternal(true);
7474
break;
75+
case llvm::MCSA_WeakDefinition:
76+
// On AIX/XCOFF, a weak definition symbol should be emitted
77+
// as an external weak symbol (C_WEAKEXT), since the assembler
78+
// does not support '.weak_definition' directly.
79+
Symbol->setStorageClass(XCOFF::C_WEAKEXT);
80+
Symbol->setExternal(true);
81+
break;
7582
case llvm::MCSA_Hidden:
7683
Symbol->setVisibilityType(XCOFF::SYM_V_HIDDEN);
7784
break;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Check that weak_definition symbols are emitted as weak externals.
2+
# Note: On AIX, .weak_definition is mapped to .weak by LLVM's backend.
3+
# RUN: llvm-mc -triple powerpc-ibm-aix-xcoff %s -filetype=obj -o - | \
4+
# RUN: llvm-objdump --syms - | FileCheck %s
5+
6+
.weak_definition foo # LLVM IR WeakDefinition → .weak on AIX
7+
foo:
8+
blr
9+
10+
# CHECK: SYMBOL TABLE:
11+
# CHECK-NEXT: 00000000 df *DEBUG* 00000000 .file
12+
# CHECK-NEXT: 00000000 l .text 00000004
13+
# CHECK-NEXT: 00000000 w F .text (csect: ) 00000000 foo

0 commit comments

Comments
 (0)