[llvm] 26604d0 - [AIX] Emit AvailableExternally Linkage on AIX
Xiangling Liao via llvm-commits
llvm-commits at lists.llvm.org
Fri May 29 10:13:58 PDT 2020
Author: Xiangling Liao
Date: 2020-05-29T13:12:59-04:00
New Revision: 26604d06b6fe10bb047a3620cf306be8648dcc20
URL: https://github.com/llvm/llvm-project/commit/26604d06b6fe10bb047a3620cf306be8648dcc20
DIFF: https://github.com/llvm/llvm-project/commit/26604d06b6fe10bb047a3620cf306be8648dcc20.diff
LOG: [AIX] Emit AvailableExternally Linkage on AIX
Since on AIX, our strategy is to not use -u to suppress any undefined
symbols, we need to emit .extern for the symbols with AvailableExternally
linkage.
Differential Revision: https://reviews.llvm.org/D80642
Added:
llvm/test/CodeGen/PowerPC/aix-available-externally-linkage.ll
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/lib/Target/TargetLoweringObjectFile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3be48935f2ab..0aaf5a487c15 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -438,8 +438,13 @@ void AsmPrinter::emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
return;
}
LLVM_FALLTHROUGH;
- case GlobalValue::AppendingLinkage:
case GlobalValue::AvailableExternallyLinkage:
+ if (MAI->hasDotExternDirective()) {
+ OutStreamer->emitSymbolAttribute(GVSym, MCSA_Extern);
+ return;
+ }
+ LLVM_FALLTHROUGH;
+ case GlobalValue::AppendingLinkage:
llvm_unreachable("Should never emit this");
}
llvm_unreachable("Unknown linkage type!");
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 586de4fd97f0..68df50f1a87a 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1983,7 +1983,7 @@ TargetLoweringObjectFileXCOFF::getTargetSymbol(const GlobalValue *GV,
// function entry point. We choose to always return a function descriptor
// here.
if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
- if (GO->isDeclaration())
+ if (GO->isDeclarationForLinker())
return cast<MCSectionXCOFF>(getSectionForExternalReference(GO, TM))
->getQualNameSymbol();
@@ -2011,7 +2011,7 @@ MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal(
MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
const GlobalObject *GO, const TargetMachine &TM) const {
- assert(GO->isDeclaration() &&
+ assert(GO->isDeclarationForLinker() &&
"Tried to get ER section for a defined global.");
SmallString<128> Name;
@@ -2133,6 +2133,7 @@ XCOFF::StorageClass TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(
return XCOFF::C_HIDEXT;
case GlobalValue::ExternalLinkage:
case GlobalValue::CommonLinkage:
+ case GlobalValue::AvailableExternallyLinkage:
return XCOFF::C_EXT;
case GlobalValue::ExternalWeakLinkage:
case GlobalValue::LinkOnceAnyLinkage:
@@ -2143,9 +2144,6 @@ XCOFF::StorageClass TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(
case GlobalValue::AppendingLinkage:
report_fatal_error(
"There is no mapping that implements AppendingLinkage for XCOFF.");
- case GlobalValue::AvailableExternallyLinkage:
- report_fatal_error("unhandled AvailableExternallyLinkage when mapping "
- "linkage to StorageClass");
}
llvm_unreachable("Unknown linkage type!");
}
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 84f870f4a584..051c800600c5 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -1728,7 +1728,7 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
auto setCsectAlignment = [this](const GlobalObject *GO) {
// Declarations have 0 alignment which is set by default.
- if (GO->isDeclaration())
+ if (GO->isDeclarationForLinker())
return;
SectionKind GOKind = getObjFileLowering().getKindForGlobal(GO, TM);
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp
index bd256600c5fe..eea0aeea2c45 100644
--- a/llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -143,7 +143,7 @@ void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
/// may be overridden by the target implementation.
SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
const TargetMachine &TM){
- assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
+ assert(!GO->isDeclarationForLinker() &&
"Can only be used for global definitions");
// Functions are classified as text sections.
diff --git a/llvm/test/CodeGen/PowerPC/aix-available-externally-linkage.ll b/llvm/test/CodeGen/PowerPC/aix-available-externally-linkage.ll
new file mode 100644
index 000000000000..a0201f635150
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-available-externally-linkage.ll
@@ -0,0 +1,39 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | \
+; RUN: FileCheck %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | \
+; RUN: FileCheck %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec -filetype=obj -o %t.o < %s
+; RUN: llvm-readobj --symbols %t.o | \
+; RUN: FileCheck --check-prefix=XCOFF32 %s
+
+; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff \
+; RUN: -mcpu=pwr4 -mattr=-altivec -filetype=obj -o %t.o 2>&1 < %s | \
+; RUN: FileCheck --check-prefix=XCOFF64 %s
+; XCOFF64: LLVM ERROR: 64-bit XCOFF object files are not supported yet.
+
+ at _ZN3Foo1aE = available_externally constant i32 -1
+
+; CHECK: .extern _ZN3Foo1aE[UA]
+
+; XCOFF32: Index: [[#Index:]]{{.*}}{{[[:space:]] *}}Name: _ZN3Foo1aE
+; XCOFF32-NEXT: Value (RelocatableAddress): 0x0
+; XCOFF32-NEXT: Section: N_UNDEF
+; XCOFF32-NEXT: Type: 0x0
+; XCOFF32-NEXT: StorageClass: C_EXT (0x2)
+; XCOFF32-NEXT: NumberOfAuxEntries: 1
+; XCOFF32-NEXT: CSECT Auxiliary Entry {
+; XCOFF32-NEXT: Index: [[#Index+1]]
+; XCOFF32-NEXT: SectionLen: 0
+; XCOFF32-NEXT: ParameterHashIndex: 0x0
+; XCOFF32-NEXT: TypeChkSectNum: 0x0
+; XCOFF32-NEXT: SymbolAlignmentLog2: 0
+; XCOFF32-NEXT: SymbolType: XTY_ER (0x0)
+; XCOFF32-NEXT: StorageMappingClass: XMC_UA (0x4)
+; XCOFF32-NEXT: StabInfoIndex: 0x0
+; XCOFF32-NEXT: StabSectNum: 0x0
+; XCOFF32-NEXT: }
More information about the llvm-commits
mailing list