[ARM] Add pre-defined macros for ROPI and RWPI

This adds ACLE-defined macros to test for code being compiled in the ROPI and
RWPI position-independence modes.

Differential revision: https://reviews.llvm.org/D23610

llvm-svn: 354265
This commit is contained in:
Oliver Stannard 2019-02-18 12:39:47 +00:00
parent 6e0b562bf6
commit e3c8ce8b75
6 changed files with 33 additions and 2 deletions

View File

@ -170,6 +170,8 @@ VALUE_LANGOPT(MaxTypeAlign , 32, 0,
VALUE_LANGOPT(AlignDouble , 1, 0, "Controls if doubles should be aligned to 8 bytes (x86 only)")
COMPATIBLE_VALUE_LANGOPT(PICLevel , 2, 0, "__PIC__ level")
COMPATIBLE_VALUE_LANGOPT(PIE , 1, 0, "is pie")
LANGOPT(ROPI , 1, 0, "Read-only position independence")
LANGOPT(RWPI , 1, 0, "Read-write position independence")
COMPATIBLE_LANGOPT(GNUInline , 1, 0, "GNU inline semantics")
COMPATIBLE_LANGOPT(NoInlineDefine , 1, 0, "__NO_INLINE__ predefined macro")
COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro")

View File

@ -1606,9 +1606,9 @@ def fplt : Flag<["-"], "fplt">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Use the PLT to make function calls">;
def fno_plt : Flag<["-"], "fno-plt">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Do not use the PLT to make function calls">;
def fropi : Flag<["-"], "fropi">, Group<f_Group>;
def fropi : Flag<["-"], "fropi">, Group<f_Group>, Flags<[CC1Option]>;
def fno_ropi : Flag<["-"], "fno-ropi">, Group<f_Group>;
def frwpi : Flag<["-"], "frwpi">, Group<f_Group>;
def frwpi : Flag<["-"], "frwpi">, Group<f_Group>, Flags<[CC1Option]>;
def fno_rwpi : Flag<["-"], "fno-rwpi">, Group<f_Group>;
def fplugin_EQ : Joined<["-"], "fplugin=">, Group<f_Group>, Flags<[DriverOption]>, MetaVarName<"<dsopath>">,
HelpText<"Load the named plugin (dynamic shared object)">;

View File

@ -652,6 +652,12 @@ void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
if (SoftFloat)
Builder.defineMacro("__SOFTFP__");
// ACLE position independent code macros.
if (Opts.ROPI)
Builder.defineMacro("__ARM_ROPI", "1");
if (Opts.RWPI)
Builder.defineMacro("__ARM_RWPI", "1");
if (ArchKind == llvm::ARM::ArchKind::XSCALE)
Builder.defineMacro("__XSCALE__");

View File

@ -3810,6 +3810,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-pic-is-pie");
}
if (RelocationModel == llvm::Reloc::ROPI ||
RelocationModel == llvm::Reloc::ROPI_RWPI)
CmdArgs.push_back("-fropi");
if (RelocationModel == llvm::Reloc::RWPI ||
RelocationModel == llvm::Reloc::ROPI_RWPI)
CmdArgs.push_back("-frwpi");
if (Arg *A = Args.getLastArg(options::OPT_meabi)) {
CmdArgs.push_back("-meabi");
CmdArgs.push_back(A->getValue());

View File

@ -2662,6 +2662,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags);
Opts.AlignDouble = Args.hasArg(OPT_malign_double);
Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
Opts.ROPI = Args.hasArg(OPT_fropi);
Opts.RWPI = Args.hasArg(OPT_frwpi);
Opts.PIE = Args.hasArg(OPT_pic_is_pie);
Opts.Static = Args.hasArg(OPT_static_define);
Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple);

View File

@ -0,0 +1,14 @@
// REQUIRES: arm-registered-target
// RUN: %clang -target armv8--none-eabi -x c -E -dM %s -o - | FileCheck %s --check-prefix=NO-ROPI --check-prefix=NO-RWPI
// RUN: %clang -target armv8--none-eabi -x c -E -dM %s -o - -fropi | FileCheck %s --check-prefix=ROPI --check-prefix=NO-RWPI
// RUN: %clang -target armv8--none-eabi -x c -E -dM %s -o - -frwpi | FileCheck %s --check-prefix=NO-ROPI --check-prefix=RWPI
// RUN: %clang -target armv8--none-eabi -x c -E -dM %s -o - -fropi -frwpi | FileCheck %s --check-prefix=ROPI --check-prefix=RWPI
// Pre-defined macros for position-independence modes
// NO-ROPI-NOT: #define __APCS_ROPI
// ROPI: #define __ARM_ROPI
// NO-RWPI-NOT: #define __APCS_RWPI
// RWPI: #define __ARM_RWPI