Skip to content

[AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections #79252

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions clang/lib/Basic/Targets/PPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,14 +671,6 @@ bool PPCTargetInfo::initFeatureMap(
return false;
}

if (llvm::is_contained(FeaturesVec, "+aix-small-local-exec-tls")) {
if (!getTriple().isOSAIX() || !getTriple().isArch64Bit()) {
Diags.Report(diag::err_opt_not_valid_on_target)
<< "-maix-small-local-exec-tls";
return false;
}
}

return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
}

Expand Down
19 changes: 19 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/PPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
Features.push_back("+secure-plt");

bool UseSeparateSections = isUseSeparateSections(Triple);
bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
if (!Triple.isOSAIX() || !Triple.isArch64Bit())
D.Diag(diag::err_opt_not_valid_on_target) << "-maix-small-local-exec-tls";

// The -maix-small-local-exec-tls option should only be used with
// -fdata-sections, as having data sections turned off with this option
// is not ideal for performance. Moreover, the small-local-exec-tls region
// is a limited resource, and should not be used for variables that may
// be replaced.
if (!Args.hasFlag(options::OPT_fdata_sections,
options::OPT_fno_data_sections,
UseSeparateSections || HasDefaultDataSections))
D.Diag(diag::err_drv_argument_only_allowed_with)
<< "-maix-small-local-exec-tls"
<< "-fdata-sections";
}
}

ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/aix-small-local-exec-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-exec-tls \
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-exec-tls \
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s

int test(void) {
return 0;
Expand All @@ -23,6 +29,7 @@ int test(void) {

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

// CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
// CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
Expand Down
21 changes: 17 additions & 4 deletions llvm/lib/Target/PowerPC/PPCSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,23 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
// Determine endianness.
IsLittleEndian = TM.isLittleEndian();

if (HasAIXSmallLocalExecTLS && (!TargetTriple.isOSAIX() || !IsPPC64))
report_fatal_error(
"The aix-small-local-exec-tls attribute is only supported on AIX in "
"64-bit mode.\n", false);
if (HasAIXSmallLocalExecTLS) {
if (!TargetTriple.isOSAIX() || !IsPPC64)
report_fatal_error(
"The aix-small-local-exec-tls attribute is only supported on AIX in "
"64-bit mode.\n",
false);
// The aix-small-local-exec-tls attribute should only be used with
// -data-sections, as having data sections turned off with this option
// is not ideal for performance. Moreover, the small-local-exec-tls region
// is a limited resource, and should not be used for variables that may
// be replaced.
if (!TM.getDataSections())
report_fatal_error(
"The aix-small-local-exec-tls attribute can only be specified with "
"-data-sections.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-data-sections.\n",
"-fdata-sections.\n",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the llvm portion as -data-sections since the option for llc is -data-sections rather than -fdata-sections (which is the option for clang).

false);
}
}

bool PPCSubtarget::enableMachineScheduler() const { return true; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
; RUN: < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
; RUN: not llc -mtriple powerpc64le-unknown-linux-gnu -ppc-asm-full-reg-names \
; RUN: < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff -ppc-asm-full-reg-names \
; RUN: -data-sections=false < %s 2>&1 | \
; RUN: FileCheck %s --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC

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

; Check that the aix-small-local-exec-tls attribute is only supported when
; data sections are enabled.
; CHECK-UNSUPPORTED-NO-DATASEC: The aix-small-local-exec-tls attribute can only be specified with -data-sections.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; CHECK-UNSUPPORTED-NO-DATASEC: The aix-small-local-exec-tls attribute can only be specified with -data-sections.
; CHECK-UNSUPPORTED-NO-DATASEC: The aix-small-local-exec-tls attribute can only be specified with -fdata-sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the llvm portion as -data-sections since the option for llc is -data-sections rather than -fdata-sections (which is the option for clang).


; Make sure that the test was actually compiled successfully after using the
; aix-small-local-exec-tls attribute.
; CHECK-LABEL: testWithIRAttr:
Expand Down