================
@@ -421,13 +421,102 @@ void AIX::AddCXXStdlibLibArgs(const llvm::opt::ArgList 
&Args,
   llvm_unreachable("Unexpected C++ library type; only libc++ is supported.");
 }
 
+// This function processes all the mtocdata options to build the final
+// simplified toc data options to pass to CC1.
+static void addTocDataOptions(const llvm::opt::ArgList &Args,
+                              llvm::opt::ArgStringList &CC1Args,
+                              const Driver &D) {
+
+  // Check the global toc-data setting. The default is -mno-tocdata.
+  // To enable toc-data globally, -mtocdata must be specified.
+  // Additionally, it must be last to take effect.
+  const bool TOCDataGloballyinEffect = [&Args]() {
+    if (!Args.hasArg(options::OPT_mtocdata))
+      return false;
+
+    const Arg *LastArg =
+        Args.getLastArg(options::OPT_mtocdata, options::OPT_mno_tocdata);
+    return LastArg->getOption().matches(options::OPT_mtocdata);
+  }();
+
+  // Currently only supported for small code model.
+  if (TOCDataGloballyinEffect &&
+      (Args.getLastArgValue(options::OPT_mcmodel_EQ).equals("large") ||
+       Args.getLastArgValue(options::OPT_mcmodel_EQ).equals("medium"))) {
+    D.Diag(clang::diag::warn_drv_unsupported_tocdata);
+    return;
+  }
+
+  enum TOCDataSetting {
+    AddressInTOC = 0, // Address of the symbol stored in the TOC.
+    DataInTOC = 1     // Symbol defined in the TOC.
+  };
+
+  const TOCDataSetting DefaultTocDataSetting =
+      TOCDataGloballyinEffect ? DataInTOC : AddressInTOC;
+
+  // Process the list of variables in the explicitly specified options
+  // -mtocdata= and -mno-tocdata= to see which variables are opposite to
+  // the global setting of tocdata in TOCDataGloballyinEffect.
+  // Those that have the opposite setting to TOCDataGloballyinEffect, are added
+  // to ExplicitlySpecifiedGlobals.
+  llvm::StringSet<> ExplicitlySpecifiedGlobals;
+  for (const auto Arg :
+       Args.filtered(options::OPT_mtocdata_EQ, options::OPT_mno_tocdata_EQ)) {
+    TOCDataSetting ArgTocDataSetting =
+        Arg->getOption().matches(options::OPT_mtocdata_EQ) ? DataInTOC
+                                                           : AddressInTOC;
+
+    if (ArgTocDataSetting != DefaultTocDataSetting)
+      for (const char *Val : Arg->getValues())
+        ExplicitlySpecifiedGlobals.insert(Val);
+    else
+      for (const char *Val : Arg->getValues())
+        ExplicitlySpecifiedGlobals.erase(Val);
+  }
----------------
diggerlin wrote:

Is there a guideline or any discussions about how the multi options 
`-mno-tocdata=` and `-mtocdata=` interaction ?

in the implement , the order of option  `-mno-tocdata=` and `-mtocdata=` will 
cause different behavior's . for example in the test case  
`clang/test/Driver/toc-conf.c`

`bash> clang /scratch/zhijian/llvm/src_review/clang/test/Driver/toc-conf.c 
--target=powerpc-unknown-aix  -mtocdata=g1,g2 -mno-tocdata=g2 -mtocdata=g3,g4  
-mno-tocdata=g5,g1-###`

will generate `"-mtocdata=g3,g4"`. However, if I change the ` 
-mno-tocdata=g5,g1`  from the end to the beginning of the  command line.  

`bash>clang /scratch/zhijian/llvm/src_review/clang/test/Driver/toc-conf.c 
--target=powerpc-unknown-aix -mno-tocdata=g5,g1 -mtocdata=g1,g2 -mno-tocdata=g2 
-mtocdata=g3,g4 -###`

 will generate `"-mtocdata=g1,g3,g4"` 
 
 Is this behavior aligned with our needs or the customer's needs?"  
 
 


https://github.com/llvm/llvm-project/pull/67999
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to