[llvm] 282da83 - [XCOFF][AIX] Issue an error when specifying an alias for a common symbol
Stephen Peckham via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 31 08:44:21 PDT 2023
Author: Stephen Peckham
Date: 2023-08-31T11:43:47-04:00
New Revision: 282da837565fcf8598a81b5f3b34bc25705917d3
URL: https://github.com/llvm/llvm-project/commit/282da837565fcf8598a81b5f3b34bc25705917d3
DIFF: https://github.com/llvm/llvm-project/commit/282da837565fcf8598a81b5f3b34bc25705917d3.diff
LOG: [XCOFF][AIX] Issue an error when specifying an alias for a common symbol
Summary:
There is no support in XCOFF for labels on common symbols. Therefore, an alias for a common symbol is not supported. Issue an error in the front end when an aliasee is a common symbol. Issue a similar error in the back end in case an IR specifies an alias for a common symbol.
Reviewed by: hubert.reinterpretcast, DiggerLin
Differential Revision: https://reviews.llvm.org/D158739
Added:
clang/test/CodeGen/aix-common.c
llvm/test/CodeGen/PowerPC/aix-common.ll
Modified:
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/CodeGen/CodeGenModule.cpp
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 9ed9a88fa3d62d..c950a2d95f641d 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -283,6 +283,8 @@ def err_avx_calling_convention : Error<warn_avx_calling_convention.Summary>;
def err_alias_to_undefined : Error<
"%select{alias|ifunc}0 must point to a defined "
"%select{variable or |}1function">;
+def err_alias_to_common : Error<
+ "alias to a variable in a common section is not allowed">;
def note_alias_requires_mangled_name : Note<
"the %select{function or variable|function}0 specified in an %select{alias|ifunc}1 must refer to its mangled name">;
def note_alias_mangled_name_alternative: Note<
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f27fc019ccc53e..07bce12d7e6689 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -563,8 +563,8 @@ static const llvm::GlobalValue *getAliasedGlobal(const llvm::GlobalValue *GV) {
}
static bool checkAliasedGlobal(
- DiagnosticsEngine &Diags, SourceLocation Location, bool IsIFunc,
- const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
+ const ASTContext &Context, DiagnosticsEngine &Diags, SourceLocation Location,
+ bool IsIFunc, const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames,
SourceRange AliasRange) {
GV = getAliasedGlobal(Alias);
@@ -573,6 +573,14 @@ static bool checkAliasedGlobal(
return false;
}
+ if (GV->hasCommonLinkage()) {
+ const llvm::Triple &Triple = Context.getTargetInfo().getTriple();
+ if (Triple.getObjectFormat() == llvm::Triple::XCOFF) {
+ Diags.Report(Location, diag::err_alias_to_common);
+ return false;
+ }
+ }
+
if (GV->isDeclaration()) {
Diags.Report(Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
Diags.Report(Location, diag::note_alias_requires_mangled_name)
@@ -633,7 +641,7 @@ void CodeGenModule::checkAliases() {
StringRef MangledName = getMangledName(GD);
llvm::GlobalValue *Alias = GetGlobalValue(MangledName);
const llvm::GlobalValue *GV = nullptr;
- if (!checkAliasedGlobal(Diags, Location, IsIFunc, Alias, GV,
+ if (!checkAliasedGlobal(getContext(), Diags, Location, IsIFunc, Alias, GV,
MangledDeclNames, Range)) {
Error = true;
continue;
diff --git a/clang/test/CodeGen/aix-common.c b/clang/test/CodeGen/aix-common.c
new file mode 100644
index 00000000000000..c18eb8f30623f5
--- /dev/null
+++ b/clang/test/CodeGen/aix-common.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -S -fcommon %s -verify -o -
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -S -fcommon %s -verify -o -
+int xxxxxx;
+extern int yyyyyy __attribute__((__alias__("xxxxxx") )); //expected-error {{alias to a variable in a common section is not allowed}}
+
+void *gggggg() { return &yyyyyy; }
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 377bd7af9f191e..1ecccdebe036f0 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2762,11 +2762,21 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
// Construct an aliasing list for each GlobalObject.
for (const auto &Alias : M.aliases()) {
- const GlobalObject *Base = Alias.getAliaseeObject();
- if (!Base)
+ const GlobalObject *Aliasee = Alias.getAliaseeObject();
+ if (!Aliasee)
report_fatal_error(
"alias without a base object is not yet supported on AIX");
- GOAliasMap[Base].push_back(&Alias);
+
+ if (Aliasee->hasCommonLinkage()) {
+ report_fatal_error("Aliases to common variables are not allowed on AIX:"
+ "\n\tAlias attribute for " +
+ Alias.getGlobalIdentifier() +
+ " is invalid because " + Aliasee->getName() +
+ " is common.",
+ false);
+ }
+
+ GOAliasMap[Aliasee].push_back(&Alias);
}
return Result;
diff --git a/llvm/test/CodeGen/PowerPC/aix-common.ll b/llvm/test/CodeGen/PowerPC/aix-common.ll
new file mode 100644
index 00000000000000..f02c68607f5b0d
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-common.ll
@@ -0,0 +1,15 @@
+; RUN: not llc -filetype=obj -mtriple powerpc-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+; RUN: not llc -filetype=asm -mtriple powerpc-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+; RUN: not llc -filetype=obj -mtriple powerpc64-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+; RUN: not llc -filetype=asm -mtriple powerpc64-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+ at x= common global i32 0, align 4
+
+ at y= alias i32, ptr @x
+
+; Function Attrs: noinline nounwind optnone
+define ptr @g() #0 {
+entry:
+ ret ptr @y
+}
+; CHECK: LLVM ERROR: Aliases to common variables are not allowed on AIX:
+; CHECK-NEXT: Alias attribute for y is invalid because x is common.
More information about the llvm-commits
mailing list