From 9715af434579022b5ef31781be40b722d7e63bee Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Mon, 15 May 2023 11:14:05 -0400 Subject: [AIX][clang] Storage Locations for Constant Pointers This patch adds clang options `-mxcoff-roptr` and `-mno-xcoff-roptr` to specify storage locations for constant pointers on AIX. When the `-mxcoff-roptr` option is in effect, constant pointers, virtual function tables, and virtual type tables are placed in read-only storage. When the `-mno-xcoff-roptr` option is in effect, pointers, virtual function tables, and virtual type tables are placed are placed in read/write storage. This patch depends on https://reviews.llvm.org/D144189. Reviewed By: hubert.reinterpretcast, stephenpeckham Differential Revision: https://reviews.llvm.org/D144190 --- clang/lib/Frontend/CompilerInvocation.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index cbd2663..c111607 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1560,6 +1560,9 @@ void CompilerInvocation::GenerateCodeGenArgs( if (Opts.EnableAIXExtendedAltivecABI) GenerateArg(Args, OPT_mabi_EQ_vec_extabi, SA); + if (Opts.XCOFFReadOnlyPointers) + GenerateArg(Args, OPT_mxcoff_roptr, SA); + if (!Opts.OptRecordPasses.empty()) GenerateArg(Args, OPT_opt_record_passes, Opts.OptRecordPasses, SA); @@ -1933,6 +1936,25 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, } } + if (Arg *A = Args.getLastArg(OPT_mxcoff_roptr)) { + if (!T.isOSAIX()) + Diags.Report(diag::err_drv_unsupported_opt_for_target) + << A->getSpelling() << T.str(); + + // Since the storage mapping class is specified per csect, + // without using data sections, it is less effective to use read-only + // pointers. Using read-only pointers may cause other RO variables in the + // same csect to become RW when the linker acts upon `-bforceimprw`; + // therefore, we require that separate data sections + // are used when `-mxcoff-roptr` is in effect. We respect the setting of + // data-sections since we have not found reasons to do otherwise that + // overcome the user surprise of not respecting the setting. + if (!Args.hasFlag(OPT_fdata_sections, OPT_fno_data_sections, false)) + Diags.Report(diag::err_roptr_requires_data_sections); + + Opts.XCOFFReadOnlyPointers = true; + } + if (Arg *A = Args.getLastArg(OPT_mabi_EQ_quadword_atomics)) { if (!T.isOSAIX() || T.isPPC32()) Diags.Report(diag::err_drv_unsupported_opt_for_target) -- cgit v1.1