Skip to content

Commit c6fb2a4

Browse files
committed
[AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections
This patch disallows the use of the -maix-small-local-exec-tls and -fno-data-sections options within clang, and also disallows the use of the aix-small-local-exec-tls attribute with the -data-sections=false option in llc. This is because having data sections off when using the aix-small-local-exec-tls feature is not ideal for performance. As the small-local-exec-tls region is a limited resource, this space should not used for variables that may be replaced. Note, that on AIX, data sections is turned on by default, so this patch makes it so that a diagnostic is emitted when users explicitly turn off data sections while using the aix-small-local-exec-tls feature.
1 parent 33d804c commit c6fb2a4

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,6 @@ bool PPCTargetInfo::initFeatureMap(
646646
return false;
647647
}
648648

649-
if (llvm::is_contained(FeaturesVec, "+aix-small-local-exec-tls")) {
650-
if (!getTriple().isOSAIX() || !getTriple().isArch64Bit()) {
651-
Diags.Report(diag::err_opt_not_valid_on_target)
652-
<< "-maix-small-local-exec-tls";
653-
return false;
654-
}
655-
}
656-
657649
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
658650
}
659651

clang/lib/Driver/ToolChains/Arch/PPC.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
122122
ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
123123
if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
124124
Features.push_back("+secure-plt");
125+
126+
bool UseSeparateSections = isUseSeparateSections(Triple);
127+
bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
128+
if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
129+
if (!Triple.isOSAIX() || !Triple.isArch64Bit())
130+
D.Diag(diag::err_opt_not_valid_on_target) << "-maix-small-local-exec-tls";
131+
132+
// The -maix-small-local-exec-tls option should only be used with
133+
// -fdata-sections, as having data sections turned off with this option
134+
// is not ideal for performance. Moreover, the small-local-exec-tls region
135+
// is a limited resource, and should not be used for variables that may
136+
// be replaced.
137+
if (!Args.hasFlag(options::OPT_fdata_sections,
138+
options::OPT_fno_data_sections,
139+
UseSeparateSections || HasDefaultDataSections))
140+
D.Diag(diag::err_drv_argument_only_allowed_with)
141+
<< "-maix-small-local-exec-tls"
142+
<< "-fdata-sections";
143+
}
125144
}
126145

127146
ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,

clang/test/Driver/aix-small-local-exec-tls.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
1313
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-exec-tls \
1414
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
15+
// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
16+
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
17+
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
18+
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-exec-tls \
19+
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
20+
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
1521

1622
int test(void) {
1723
return 0;
@@ -23,6 +29,7 @@ int test(void) {
2329

2430
// CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-exec-tls' cannot be specified on this target
2531
// CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-exec-tls' cannot be specified on this target
32+
// CHECK-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' only allowed with '-fdata-sections'
2633

2734
// CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
2835
// CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {

llvm/lib/Target/PowerPC/PPCSubtarget.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,23 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
124124
// Determine endianness.
125125
IsLittleEndian = TM.isLittleEndian();
126126

127-
if (HasAIXSmallLocalExecTLS && (!TargetTriple.isOSAIX() || !IsPPC64))
128-
report_fatal_error(
129-
"The aix-small-local-exec-tls attribute is only supported on AIX in "
130-
"64-bit mode.\n", false);
127+
if (HasAIXSmallLocalExecTLS) {
128+
if (!TargetTriple.isOSAIX() || !IsPPC64)
129+
report_fatal_error(
130+
"The aix-small-local-exec-tls attribute is only supported on AIX in "
131+
"64-bit mode.\n",
132+
false);
133+
// The aix-small-local-exec-tls attribute should only be used with
134+
// -data-sections, as having data sections turned off with this option
135+
// is not ideal for performance. Moreover, the small-local-exec-tls region
136+
// is a limited resource, and should not be used for variables that may
137+
// be replaced.
138+
if (!TM.getDataSections())
139+
report_fatal_error(
140+
"The aix-small-local-exec-tls attribute can only be specified with "
141+
"-data-sections.\n",
142+
false);
143+
}
131144
}
132145

133146
bool PPCSubtarget::enableMachineScheduler() const { return true; }

llvm/test/CodeGen/PowerPC/check-aix-small-local-exec-tls-opt-IRattribute.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
; RUN: < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
55
; RUN: not llc -mtriple powerpc64le-unknown-linux-gnu -ppc-asm-full-reg-names \
66
; RUN: < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
7+
; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff -ppc-asm-full-reg-names \
8+
; RUN: -data-sections=false < %s 2>&1 | \
9+
; RUN: FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED-NO-DATASEC
710

811
define dso_local signext i32 @testWithIRAttr() #0 {
912
entry:
@@ -12,6 +15,10 @@ entry:
1215
; Check that the aix-small-local-exec-tls attribute is not supported on Linux and AIX (32-bit).
1316
; CHECK-NOT-SUPPORTED: The aix-small-local-exec-tls attribute is only supported on AIX in 64-bit mode.
1417

18+
; Check that the aix-small-local-exec-tls attribute is only supported when
19+
; data sections are enabled.
20+
; CHECK-NOT-SUPPORTED-NO-DATASEC: The aix-small-local-exec-tls attribute can only be specified with -data-sections.
21+
1522
; Make sure that the test was actually compiled successfully after using the
1623
; aix-small-local-exec-tls attribute.
1724
; CHECK-LABEL: testWithIRAttr:

0 commit comments

Comments
 (0)