-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[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
Open
aabhinavg1
wants to merge
4
commits into
llvm:main
Choose a base branch
from
aabhinavg1:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.