[AIX] Consolidate Crt0Basename logic
authorMichael Francis <michaelfrancis@ibm.com>
Mon, 20 Mar 2023 18:00:32 +0000 (18:00 +0000)
committerMichael Francis <michaelfrancis@ibm.com>
Tue, 21 Mar 2023 00:47:05 +0000 (00:47 +0000)
when certain flags are specified, the Crt0 object files are not linked.
However, the logic for determining which files will always run. This
patch moves that logic so that the basename is only determined if it is
needed.

Differential Revision: https://reviews.llvm.org/D146443

clang/lib/Driver/ToolChains/AIX.cpp

index d4d13ce..5521a38 100644 (file)
@@ -163,19 +163,19 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-bpD:0x110000000");
   }
 
-  auto getCrt0Basename = [&Args, IsArch32Bit] {
-    if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
-      // Enable gprofiling when "-pg" is specified.
-      if (A->getOption().matches(options::OPT_pg))
-        return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o";
-      // Enable profiling when "-p" is specified.
-      return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o";
-    }
-    return IsArch32Bit ? "crt0.o" : "crt0_64.o";
-  };
-
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
                    options::OPT_shared, options::OPT_r)) {
+    auto getCrt0Basename = [&Args, IsArch32Bit] {
+      if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
+        // Enable gprofiling when "-pg" is specified.
+        if (A->getOption().matches(options::OPT_pg))
+          return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o";
+        // Enable profiling when "-p" is specified.
+        return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o";
+      }
+      return IsArch32Bit ? "crt0.o" : "crt0_64.o";
+    };
+
     CmdArgs.push_back(
         Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename())));