- Notifications
You must be signed in to change notification settings - Fork 14.9k
[PowerPC][AIX] Emit weak_definition symbols as weak externals #156072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
@llvm/pr-subscribers-backend-powerpc Author: None (aabhinavg1) Changes
Fixes #130269 Testing:
ninja check-llvm-codegen-powerpc ===== Before Patch ===== [779/780] Running lit suite /llvm/test/CodeGen/PowerPC Testing Time: 44.38s Total Discovered Tests: 1952 Unsupported : 38 (1.95%) Passed : 1907 (97.69%) Expectedly Failed: 7 (0.36%) ===== After Patch ===== [779/780] Running lit suite /llvm/test/CodeGen/PowerPC Testing Time: 120.31s Total Discovered Tests: 1952 Unsupported : 3 (0.15%) Passed : 1941 (99.44%) Expectedly Failed: 8 (0.41%) Verification: $ ../bin/clang -target powerpc64-ibm-aix -S test.c -o test.s $ cat test.s .file "test.c",,"LLVM version 22.0.0git ..." .csect ..text..[PR],5 .rename ..text..[PR],"" # Start of file scope inline assembly .weak foo foo: blr # End of file scope inline assembly .machine "PWR7" Input C code: __asm__(".weak_definition foo\n" "foo:\n" "blr"); Outcome:
Full diff: https://github.com/llvm/llvm-project/pull/156072.diff 3 Files Affected:
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index be8c022f39ad1..7b1a1878915bc 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -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: diff --git a/llvm/lib/MC/MCXCOFFStreamer.cpp b/llvm/lib/MC/MCXCOFFStreamer.cpp index 4bf14c11068cb..cd5398dc7bc3b 100644 --- a/llvm/lib/MC/MCXCOFFStreamer.cpp +++ b/llvm/lib/MC/MCXCOFFStreamer.cpp @@ -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; diff --git a/llvm/test/MC/PowerPC/aix-weak-definition.s b/llvm/test/MC/PowerPC/aix-weak-definition.s new file mode 100644 index 0000000000000..6bab51b91c63d --- /dev/null +++ b/llvm/test/MC/PowerPC/aix-weak-definition.s @@ -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 |
Adding @hubert-reinterpretcast & @daltenty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need .weak_definition? ELF doesn't support .weak_definition and we don't use MCSA_WeakDefinition for ELF. You can use MCSA_Weak for XCOFF
Fixes powerpc64-ibm-aix: the
.weak
assembler directive is not supported #130269Fixes #130269
Testing:
Verification:
Input C code:
Outcome:
.weak_definition
in the source is correctly mapped to.weak
in the assembly on AIX.