<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Puyan,<div><br></div><div>This commit caused two Clang failures on Darwin:</div><div><br></div><div><div>    Clang :: InterfaceStubs/merge-conflict-test.c</div><div>    Clang :: InterfaceStubs/object-float.c</div></div><div><br></div><div>Here's the build log from out bot:</div><div><a href="http://lab.llvm.org:8080/green/job/clang-stage1-RA/3929/console">http://lab.llvm.org:8080/green/job/clang-stage1-RA/3929/console</a><br></div><div><br></div><div>Can you please resolve the issue with the tests?</div><div>Thanks,</div><div>Alex</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 20 Nov 2019 at 14:16, Puyan Lotfi via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Author: Puyan Lotfi<br>
Date: 2019-11-20T16:22:50-05:00<br>
New Revision: 73429126c91c2065c6f6ef29b3eec1b7798502bb<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/73429126c91c2065c6f6ef29b3eec1b7798502bb" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/73429126c91c2065c6f6ef29b3eec1b7798502bb</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/73429126c91c2065c6f6ef29b3eec1b7798502bb.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/73429126c91c2065c6f6ef29b3eec1b7798502bb.diff</a><br>
<br>
LOG: [clang][IFS] Driver Pipeline: generate stubs after standard pipeline (3)<br>
<br>
Third Landing Attempt (dropping any linker invocation from clang driver):<br>
<br>
Up until now, clang interface stubs has replaced the standard<br>
PP -> C -> BE -> ASM -> LNK pipeline. With this change, it will happen in<br>
conjunction with it. So what when you build your code you will get an<br>
a.out or lib.so as well as an interface stub file.<br>
<br>
Example:<br>
<br>
clang -shared -o libfoo.so -emit-interface-stubs ...<br>
<br>
will generate both a libfoo.so and a libfoo.ifso. The .so file will<br>
contain the code from the standard compilation pipeline and the .ifso<br>
file will contain the ELF stub library.<br>
<br>
Note: For driver-test.c I've added -S in order to prevent any bot failures on<br>
bots that don't have the proper linker for their native triple. You could always<br>
specify a triple like x86_64-unknown-linux-gnu and on bots like x86_64-scei-ps4<br>
the clang driver would invoke regular ld instead of getting the error<br>
'Executable "orbis-ld" doesn't exist!' but on bots like ppc64be and s390x you'd<br>
get an error "/usr/bin/ld: unrecognised emulation mode: elf_x86_64"<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D70274" rel="noreferrer" target="_blank">https://reviews.llvm.org/D70274</a><br>
<br>
Added: <br>
    clang/test/InterfaceStubs/driver-test2.c<br>
    clang/test/InterfaceStubs/ppc.cpp<br>
<br>
Modified: <br>
    clang/lib/Driver/Driver.cpp<br>
    clang/lib/Driver/ToolChains/InterfaceStubs.cpp<br>
    clang/lib/Driver/Types.cpp<br>
    clang/test/InterfaceStubs/driver-test.c<br>
    clang/test/InterfaceStubs/windows.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp<br>
index cdf4a579f431..83b5db3b2530 100644<br>
--- a/clang/lib/Driver/Driver.cpp<br>
+++ b/clang/lib/Driver/Driver.cpp<br>
@@ -292,10 +292,6 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,<br>
              (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {<br>
     FinalPhase = phases::Compile;<br>
<br>
-  // clang interface stubs<br>
-  } else if ((PhaseArg = DAL.getLastArg(options::OPT_emit_interface_stubs))) {<br>
-    FinalPhase = phases::IfsMerge;<br>
-<br>
   // -S only runs up to the backend.<br>
   } else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) {<br>
     FinalPhase = phases::Backend;<br>
@@ -3502,6 +3498,68 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,<br>
     Actions.push_back(<br>
         C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image));<br>
<br>
+  if (Arg *A = Args.getLastArg(options::OPT_emit_interface_stubs)) {<br>
+    llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhaseList;<br>
+    if (Args.hasArg(options::OPT_c)) {<br>
+      llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> CompilePhaseList;<br>
+      types::getCompilationPhases(types::TY_IFS_CPP, CompilePhaseList);<br>
+      llvm::copy_if(CompilePhaseList, std::back_inserter(PhaseList),<br>
+                    [&](phases::ID Phase) { return Phase <= phases::Compile; });<br>
+    } else {<br>
+      types::getCompilationPhases(types::TY_IFS_CPP, PhaseList);<br>
+    }<br>
+<br>
+    ActionList MergerInputs;<br>
+<br>
+    for (auto &I : Inputs) {<br>
+      types::ID InputType = I.first;<br>
+      const Arg *InputArg = I.second;<br>
+<br>
+      // Currently clang and the llvm assembler do not support generating symbol<br>
+      // stubs from assembly, so we skip the input on asm files. For ifs files<br>
+      // we rely on the normal pipeline setup in the pipeline setup code above.<br>
+      if (InputType == types::TY_IFS || InputType == types::TY_PP_Asm ||<br>
+          InputType == types::TY_Asm)<br>
+        continue;<br>
+<br>
+      Action *Current = C.MakeAction<InputAction>(*InputArg, InputType);<br>
+<br>
+      for (auto Phase : PhaseList) {<br>
+        switch (Phase) {<br>
+        default:<br>
+          llvm_unreachable(<br>
+              "IFS Pipeline can only consist of Compile followed by IfsMerge.");<br>
+        case phases::Compile: {<br>
+          // Only IfsMerge (llvm-ifs) can handle .o files by looking for ifs<br>
+          // files where the .o file is located. The compile action can not<br>
+          // handle this.<br>
+          if (InputType == types::TY_Object)<br>
+            break;<br>
+<br>
+          Current = C.MakeAction<CompileJobAction>(Current, types::TY_IFS_CPP);<br>
+          break;<br>
+        }<br>
+        case phases::IfsMerge: {<br>
+          assert(Phase == PhaseList.back() &&<br>
+                 "merging must be final compilation step.");<br>
+          MergerInputs.push_back(Current);<br>
+          Current = nullptr;<br>
+          break;<br>
+        }<br>
+        }<br>
+      }<br>
+<br>
+      // If we ended with something, add to the output list.<br>
+      if (Current)<br>
+        Actions.push_back(Current);<br>
+    }<br>
+<br>
+    // Add an interface stubs merge action if necessary.<br>
+    if (!MergerInputs.empty())<br>
+      Actions.push_back(<br>
+          C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image));<br>
+  }<br>
+<br>
   // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a custom<br>
   // Compile phase that prints out supported cpu models and quits.<br>
   if (Arg *A = Args.getLastArg(options::OPT_print_supported_cpus)) {<br>
@@ -3603,8 +3661,6 @@ Action *Driver::ConstructPhaseAction(<br>
       return C.MakeAction<CompileJobAction>(Input, types::TY_ModuleFile);<br>
     if (Args.hasArg(options::OPT_verify_pch))<br>
       return C.MakeAction<VerifyPCHJobAction>(Input, types::TY_Nothing);<br>
-    if (Args.hasArg(options::OPT_emit_interface_stubs))<br>
-      return C.MakeAction<CompileJobAction>(Input, types::TY_IFS_CPP);<br>
     return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);<br>
   }<br>
   case phases::Backend: {<br>
@@ -3633,11 +3689,16 @@ void Driver::BuildJobs(Compilation &C) const {<br>
   Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);<br>
<br>
   // It is an error to provide a -o option if we are making multiple output<br>
-  // files.<br>
+  // files. There is one exception, IfsMergeJob: when generating interface stubs<br>
+  // enabled we want to be able to generate the stub file at the same time that<br>
+  // we generate the real library/a.out. So when a .o, .so, etc are the output,<br>
+  // with clang interface stubs there will also be a .ifs and .ifso at the same<br>
+  // location.<br>
   if (FinalOutput) {<br>
     unsigned NumOutputs = 0;<br>
     for (const Action *A : C.getActions())<br>
-      if (A->getType() != types::TY_Nothing)<br>
+      if (A->getType() != types::TY_Nothing &&<br>
+          A->getKind() != Action::IfsMergeJobClass)<br>
         ++NumOutputs;<br>
<br>
     if (NumOutputs > 1) {<br>
<br>
diff  --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp<br>
index 6677843b2c53..f441f4787097 100644<br>
--- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp<br>
+++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp<br>
@@ -9,6 +9,7 @@<br>
 #include "InterfaceStubs.h"<br>
 #include "CommonArgs.h"<br>
 #include "clang/Driver/Compilation.h"<br>
+#include "llvm/Support/Path.h"<br>
<br>
 namespace clang {<br>
 namespace driver {<br>
@@ -21,13 +22,36 @@ void Merger::ConstructJob(Compilation &C, const JobAction &JA,<br>
   std::string Merger = getToolChain().GetProgramPath(getShortName());<br>
   llvm::opt::ArgStringList CmdArgs;<br>
   CmdArgs.push_back("-action");<br>
-  CmdArgs.push_back(Args.getLastArg(options::OPT_emit_merged_ifs)<br>
-                        ? "write-ifs"<br>
-                        : "write-bin");<br>
+  const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);<br>
+  CmdArgs.push_back(WriteBin ? "write-bin" : "write-ifs");<br>
   CmdArgs.push_back("-o");<br>
-  CmdArgs.push_back(Output.getFilename());<br>
-  for (const auto &Input : Inputs)<br>
-    CmdArgs.push_back(Input.getFilename());<br>
+<br>
+  // Normally we want to write to a side-car file ending in ".ifso" so for<br>
+  // example if `clang -emit-interface-stubs -shared -o libhello.so` were<br>
+  // invoked then we would like to get libhello.so and libhello.ifso. If the<br>
+  // stdout stream is given as the output file (ie `-o -`), that is the one<br>
+  // exception where we will just append to the same filestream as the normal<br>
+  // output.<br>
+  SmallString<128> OutputFilename(Output.getFilename());<br>
+  if (OutputFilename != "-") {<br>
+    if (Args.hasArg(options::OPT_shared))<br>
+      llvm::sys::path::replace_extension(OutputFilename,<br>
+                                         (WriteBin ? "ifso" : "ifs"));<br>
+    else<br>
+      OutputFilename += (WriteBin ? ".ifso" : ".ifs");<br>
+  }<br>
+<br>
+  CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str()));<br>
+<br>
+  // Here we append the input files. If the input files are object files, then<br>
+  // we look for .ifs files present in the same location as the object files.<br>
+  for (const auto &Input : Inputs) {<br>
+    SmallString<128> InputFilename(Input.getFilename());<br>
+    if (Input.getType() == types::TY_Object)<br>
+      llvm::sys::path::replace_extension(InputFilename, ".ifs");<br>
+    CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str()));<br>
+  }<br>
+<br>
   C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Merger),<br>
                                          CmdArgs, Inputs));<br>
 }<br>
<br>
diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp<br>
index 0e14e3d63fab..7d83be2521e7 100644<br>
--- a/clang/lib/Driver/Types.cpp<br>
+++ b/clang/lib/Driver/Types.cpp<br>
@@ -330,22 +330,6 @@ void types::getCompilationPhases(const clang::driver::Driver &Driver,<br>
     llvm::copy_if(PhaseList, std::back_inserter(P),<br>
                   [](phases::ID Phase) { return Phase <= phases::Precompile; });<br>
<br>
-  // Treat Interface Stubs like its own compilation mode.<br>
-  else if (DAL.getLastArg(options::OPT_emit_interface_stubs)) {<br>
-    llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> IfsModePhaseList;<br>
-    llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> &PL = PhaseList;<br>
-    phases::ID LastPhase = phases::IfsMerge;<br>
-    if (Id != types::TY_IFS) {<br>
-      if (DAL.hasArg(options::OPT_c))<br>
-        LastPhase = phases::Compile;<br>
-      PL = IfsModePhaseList;<br>
-      types::getCompilationPhases(types::TY_IFS_CPP, PL);<br>
-    }<br>
-    llvm::copy_if(PL, std::back_inserter(P), [&](phases::ID Phase) {<br>
-      return Phase <= LastPhase;<br>
-    });<br>
-  }<br>
-<br>
   // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.<br>
   else if (DAL.getLastArg(options::OPT_fsyntax_only) ||<br>
            DAL.getLastArg(options::OPT_print_supported_cpus) ||<br>
<br>
diff  --git a/clang/test/InterfaceStubs/driver-test.c b/clang/test/InterfaceStubs/driver-test.c<br>
index d4e50295411a..9ca5577a5c20 100644<br>
--- a/clang/test/InterfaceStubs/driver-test.c<br>
+++ b/clang/test/InterfaceStubs/driver-test.c<br>
@@ -1,7 +1,9 @@<br>
 // REQUIRES: x86-registered-target<br>
+// REQUIRES: shell<br>
<br>
-// RUN: %clang -target x86_64-unknown-linux-gnu -x c -o %t1.so -emit-interface-stubs %s %S/object.c %S/weak.cpp && \<br>
-// RUN: llvm-nm %t1.so 2>&1 | FileCheck --check-prefix=CHECK-IFS %s<br>
+// RUN: mkdir -p %t; cd %t<br>
+// RUN: %clang -target x86_64-unknown-linux-gnu -x c -S -emit-interface-stubs %s %S/object.c %S/weak.cpp && \<br>
+// RUN: llvm-nm %t/a.out.ifso 2>&1 | FileCheck --check-prefix=CHECK-IFS %s<br>
<br>
 // CHECK-IFS-DAG: data<br>
 // CHECK-IFS-DAG: foo<br>
<br>
diff  --git a/clang/test/InterfaceStubs/driver-test2.c b/clang/test/InterfaceStubs/driver-test2.c<br>
new file mode 100644<br>
index 000000000000..c3a3b31b212d<br>
--- /dev/null<br>
+++ b/clang/test/InterfaceStubs/driver-test2.c<br>
@@ -0,0 +1,16 @@<br>
+// REQUIRES: x86-registered-target<br>
+// REQUIRES: shell<br>
+<br>
+// RUN: mkdir -p %t; cd %t<br>
+// RUN: %clang -target x86_64-unknown-linux-gnu -c -emit-interface-stubs \<br>
+// RUN:   %s %S/object.c %S/weak.cpp<br>
+// RUN: %clang -emit-interface-stubs -emit-merged-ifs \<br>
+// RUN:   %t/driver-test2.o %t/object.o %t/weak.o -S -o - 2>&1 | FileCheck %s<br>
+<br>
+// CHECK-DAG: data<br>
+// CHECK-DAG: bar<br>
+// CHECK-DAG: strongFunc<br>
+// CHECK-DAG: weakFunc<br>
+<br>
+int bar(int a) { return a; }<br>
+int main() { return 0; }<br>
<br>
diff  --git a/clang/test/InterfaceStubs/ppc.cpp b/clang/test/InterfaceStubs/ppc.cpp<br>
new file mode 100644<br>
index 000000000000..9a91697d9506<br>
--- /dev/null<br>
+++ b/clang/test/InterfaceStubs/ppc.cpp<br>
@@ -0,0 +1,14 @@<br>
+// REQUIRES: powerpc-registered-target<br>
+<br>
+// RUN: %clang -x c++ -target powerpc64le-unknown-linux-gnu -o - %s \<br>
+// RUN:   -emit-interface-stubs -emit-merged-ifs -S | \<br>
+// RUN: FileCheck -check-prefix=CHECK-IFS %s<br>
+<br>
+ // CHECK-IFS: --- !experimental-ifs-v1<br>
+ // CHECK-IFS: IfsVersion:      1.0<br>
+ // CHECK-IFS: Triple: powerpc64le<br>
+ // CHECK-IFS: Symbols:<br>
+ // CHECK-IFS:   _Z8helloPPCv: { Type: Func }<br>
+ // CHECK-IFS: ...<br>
+<br>
+int helloPPC();<br>
<br>
diff  --git a/clang/test/InterfaceStubs/windows.cpp b/clang/test/InterfaceStubs/windows.cpp<br>
index 9ccb771a2f39..c81c702861e4 100644<br>
--- a/clang/test/InterfaceStubs/windows.cpp<br>
+++ b/clang/test/InterfaceStubs/windows.cpp<br>
@@ -1,6 +1,7 @@<br>
 // REQUIRES: x86-registered-target<br>
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -o - %s -emit-interface-stubs | FileCheck -check-prefix=CHECK-CC1 %s<br>
-// RUN: %clang -target x86_64-windows-msvc -o - %s -emit-interface-stubs -emit-merged-ifs | FileCheck -check-prefix=CHECK-IFS %s<br>
+// RUN: %clang -target x86_64-windows-msvc -o - %s -emit-interface-stubs -emit-merged-ifs -S | FileCheck -check-prefix=CHECK-IFS %s<br>
+// note: -S is added here to prevent clang from invoking link.exe<br>
<br>
 // CHECK-CC1: Symbols:<br>
 // CHECK-CC1-NEXT: ?helloWindowsMsvc@@YAHXZ<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>