diff options
author | Usman Nadeem <mnadeem@quicinc.com> | 2022-08-22 10:24:49 -0700 |
---|---|---|
committer | Usman Nadeem <mnadeem@quicinc.com> | 2022-08-22 11:10:42 -0700 |
commit | ef5ede52efbff6ffa9f8c40dc3c6276146e6ff45 (patch) | |
tree | 6aa5fdc45c195b7d09f13c7d03ec4b6af883ce3d /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | 274f86e7a6d5468b38be7a4a4008a883a27ce008 (diff) | |
download | llvm-ef5ede52efbff6ffa9f8c40dc3c6276146e6ff45.zip llvm-ef5ede52efbff6ffa9f8c40dc3c6276146e6ff45.tar.gz llvm-ef5ede52efbff6ffa9f8c40dc3c6276146e6ff45.tar.bz2 |
[Flang][Driver] Add support for PIC
This patch does the following:
- Consumes the PIC flags (fPIC/fPIE/fropi/frwpi etc) in flang-new.
tools::ParsePICArgs() in ToolChains/CommonArgs.cpp is used for this.
- Adds FC1Option to "-mrelocation-model", "-pic-level", and "-pic-is-pie"
command line options.
- Adds the above options to flang/Frontend/CodeGenOptions' data structure.
- Sets the relocation model in the target machine, and
- Sets module flags for the respective PIC/PIE type in LLVM IR.
I have tried my best to replicate how clang does things.
Differential Revision: https://reviews.llvm.org/D131533
Change-Id: I68fe64910be28147dc5617826641cea71b92d94d
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index a75c04d..cce4da3 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -124,6 +124,39 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, if (args.hasFlag(clang::driver::options::OPT_fdebug_pass_manager, clang::driver::options::OPT_fno_debug_pass_manager, false)) opts.DebugPassManager = 1; + + // -mrelocation-model option. + if (const llvm::opt::Arg *A = + args.getLastArg(clang::driver::options::OPT_mrelocation_model)) { + llvm::StringRef ModelName = A->getValue(); + auto RM = llvm::StringSwitch<llvm::Optional<llvm::Reloc::Model>>(ModelName) + .Case("static", llvm::Reloc::Static) + .Case("pic", llvm::Reloc::PIC_) + .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC) + .Case("ropi", llvm::Reloc::ROPI) + .Case("rwpi", llvm::Reloc::RWPI) + .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI) + .Default(llvm::None); + if (RM.has_value()) + opts.setRelocationModel(*RM); + else + diags.Report(clang::diag::err_drv_invalid_value) + << A->getAsString(args) << ModelName; + } + + // -pic-level and -pic-is-pie option. + if (int PICLevel = getLastArgIntValue( + args, clang::driver::options::OPT_pic_level, 0, diags)) { + if (PICLevel > 2) + diags.Report(clang::diag::err_drv_invalid_value) + << args.getLastArg(clang::driver::options::OPT_pic_level) + ->getAsString(args) + << PICLevel; + + opts.PICLevel = PICLevel; + if (args.hasArg(clang::driver::options::OPT_pic_is_pie)) + opts.IsPIE = 1; + } } /// Parses all target input arguments and populates the target |