[llvm-branch-commits] [llvm] PR for llvm/llvm-project#80024 (PR #80025)

2024-01-30 Thread Stefan Gränitz via llvm-branch-commits

weliveindetail wrote:

Great, I think we can consider this done. IIRC the PR is waiting here for 
someone to merge it and then the ticket will be closed automatically.

https://github.com/llvm/llvm-project/pull/80025
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 6edc3fe - [Orc] Fix OrcV2Examples after D94690

2021-01-15 Thread Stefan Gränitz via llvm-branch-commits

Author: Stefan Gränitz
Date: 2021-01-15T13:45:46+01:00
New Revision: 6edc3fe598aff04f9c1de6cc2ac97950b73b832d

URL: 
https://github.com/llvm/llvm-project/commit/6edc3fe598aff04f9c1de6cc2ac97950b73b832d
DIFF: 
https://github.com/llvm/llvm-project/commit/6edc3fe598aff04f9c1de6cc2ac97950b73b832d.diff

LOG: [Orc] Fix OrcV2Examples after D94690

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

Added: 


Modified: 
llvm/examples/OrcV2Examples/LLJITDumpObjects/LLJITDumpObjects.cpp

llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp

llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp

Removed: 




diff  --git a/llvm/examples/OrcV2Examples/LLJITDumpObjects/LLJITDumpObjects.cpp 
b/llvm/examples/OrcV2Examples/LLJITDumpObjects/LLJITDumpObjects.cpp
index 9b020ef8c49d..2c975b188fb6 100644
--- a/llvm/examples/OrcV2Examples/LLJITDumpObjects/LLJITDumpObjects.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITDumpObjects/LLJITDumpObjects.cpp
@@ -9,6 +9,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ExecutionEngine/Orc/DebugUtils.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"

diff  --git 
a/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
 
b/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
index e37b761913fc..78a0c5b197db 100644
--- 
a/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
+++ 
b/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
   // Make sure the debug info sections aren't stripped.
   ObjLinkingLayer->setProcessAllSections(true);
 
-  return std::move(ObjLinkingLayer);
+  return ObjLinkingLayer;
 })
 .create());
 

diff  --git 
a/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
 
b/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
index 36d28ab1..f349ce900e61 100644
--- 
a/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
+++ 
b/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
 ES, std::make_unique());
 // Add an instance of our plugin.
 ObjLinkingLayer->addPlugin(std::make_unique());
-return std::move(ObjLinkingLayer);
+return ObjLinkingLayer;
   })
   .create());
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] cf90527 - [Orc] Allow LLJITBuilder's CreateObjectLinkingLayer to return errors

2021-01-15 Thread Stefan Gränitz via llvm-branch-commits

Author: Stefan Gränitz
Date: 2021-01-15T12:53:41+01:00
New Revision: cf905274c6f4ec119fdb06a283070dcae4ed5881

URL: 
https://github.com/llvm/llvm-project/commit/cf905274c6f4ec119fdb06a283070dcae4ed5881
DIFF: 
https://github.com/llvm/llvm-project/commit/cf905274c6f4ec119fdb06a283070dcae4ed5881.diff

LOG: [Orc] Allow LLJITBuilder's CreateObjectLinkingLayer to return errors

It can be useful for an ObjectLinkingLayerCreator to allow callee errors to get 
propagated to the builder. Specifically, this is the case when the ObjectLayer 
uses the EHFrameRegistrationPlugin, because it requires a TPCEHFrameRegistrar 
and instantiation for it may fail (e.g. if the required registration symbols 
are missing in the target process).

Reviewed By: lhames

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

Added: 


Modified: 

llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp

llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Removed: 




diff  --git 
a/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
 
b/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
index 78a0c5b197db..e37b761913fc 100644
--- 
a/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
+++ 
b/llvm/examples/OrcV2Examples/LLJITWithGDBRegistrationListener/LLJITWithGDBRegistrationListener.cpp
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
   // Make sure the debug info sections aren't stripped.
   ObjLinkingLayer->setProcessAllSections(true);
 
-  return ObjLinkingLayer;
+  return std::move(ObjLinkingLayer);
 })
 .create());
 

diff  --git 
a/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
 
b/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
index f349ce900e61..36d28ab1 100644
--- 
a/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
+++ 
b/llvm/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/LLJITWithObjectLinkingLayerPlugin.cpp
@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
 ES, std::make_unique());
 // Add an instance of our plugin.
 ObjLinkingLayer->addPlugin(std::make_unique());
-return ObjLinkingLayer;
+return std::move(ObjLinkingLayer);
   })
   .create());
 

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h 
b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index b0a06aa9cb4b..ff0aa0238523 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -186,7 +186,7 @@ class LLJIT {
   }
 
 protected:
-  static std::unique_ptr
+  static Expected>
   createObjectLinkingLayer(LLJITBuilderState , ExecutionSession );
 
   static Expected>
@@ -250,8 +250,9 @@ class LLLazyJIT : public LLJIT {
 
 class LLJITBuilderState {
 public:
-  using ObjectLinkingLayerCreator = std::function(
-  ExecutionSession &, const Triple )>;
+  using ObjectLinkingLayerCreator =
+  std::function>(ExecutionSession &,
+   const Triple &)>;
 
   using CompileFunctionCreator =
   std::function>(

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 056f7b7e5cc0..d26cc6549487 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -954,8 +954,9 @@ Error LLJITBuilderState::prepareForConstruction() {
   JTMB->setRelocationModel(Reloc::PIC_);
   JTMB->setCodeModel(CodeModel::Small);
   CreateObjectLinkingLayer =
-  [TPC = this->TPC](ExecutionSession ,
-const Triple &) -> std::unique_ptr {
+  [TPC = this->TPC](
+  ExecutionSession ,
+  const Triple &) -> Expected> {
 std::unique_ptr ObjLinkingLayer;
 if (TPC)
   ObjLinkingLayer =
@@ -1011,7 +1012,7 @@ Expected 
LLJIT::lookupLinkerMangled(JITDylib ,
   makeJITDylibSearchOrder(, JITDylibLookupFlags::MatchAllSymbols), 
Name);
 }
 
-std::unique_ptr
+Expected>
 LLJIT::createObjectLinkingLayer(LLJITBuilderState , ExecutionSession ) {
 
   // If the config state provided an ObjectLinkingLayer factory then use it.
@@ -1057,8 +1058,7 @@ LLJIT::createCompileFunction(LLJITBuilderState ,
 
 LLJIT::LLJIT(LLJITBuilderState , Error )
 : ES(S.ES ? std::move(S.ES) : std::make_unique()), 
Main(),
-  

[llvm-branch-commits] [llvm] a5eb9df - [Orc][NFC] Turn LLJIT member ObjTransformLayer into unique_ptr

2021-01-15 Thread Stefan Gränitz via llvm-branch-commits

Author: Stefan Gränitz
Date: 2021-01-15T12:53:24+01:00
New Revision: a5eb9df1e3ba0a1c5d755f29f6f4cdcca4aec285

URL: 
https://github.com/llvm/llvm-project/commit/a5eb9df1e3ba0a1c5d755f29f6f4cdcca4aec285
DIFF: 
https://github.com/llvm/llvm-project/commit/a5eb9df1e3ba0a1c5d755f29f6f4cdcca4aec285.diff

LOG: [Orc][NFC] Turn LLJIT member ObjTransformLayer into unique_ptr

All other layers in LLJIT are stored as unique_ptr's already. At this point, it 
is not strictly necessary for ObjTransformLayer, but it makes a follow-up 
change more straightforward.

Reviewed By: lhames

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

Added: 


Modified: 
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Removed: 




diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h 
b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index 354cf8ff757e..b0a06aa9cb4b 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -19,7 +19,6 @@
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
-#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ThreadPool.h"
@@ -29,6 +28,7 @@ namespace orc {
 
 class LLJITBuilderState;
 class LLLazyJITBuilderState;
+class ObjectTransformLayer;
 class TargetProcessControl;
 
 /// A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
@@ -169,7 +169,7 @@ class LLJIT {
   ObjectLayer () { return *ObjLinkingLayer; }
 
   /// Returns a reference to the object transform layer.
-  ObjectTransformLayer () { return ObjTransformLayer; }
+  ObjectTransformLayer () { return *ObjTransformLayer; }
 
   /// Returns a reference to the IR transform layer.
   IRTransformLayer () { return *TransformLayer; }
@@ -209,7 +209,7 @@ class LLJIT {
   std::unique_ptr CompileThreads;
 
   std::unique_ptr ObjLinkingLayer;
-  ObjectTransformLayer ObjTransformLayer;
+  std::unique_ptr ObjTransformLayer;
   std::unique_ptr CompileLayer;
   std::unique_ptr TransformLayer;
   std::unique_ptr InitHelperTransformLayer;

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 13d447563d37..056f7b7e5cc0 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
 #include "llvm/ExecutionEngine/Orc/MachOPlatform.h"
 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
 #include "llvm/ExecutionEngine/Orc/OrcError.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
@@ -997,7 +998,7 @@ Error LLJIT::addObjectFile(ResourceTrackerSP RT,
std::unique_ptr Obj) {
   assert(Obj && "Can not add null object");
 
-  return ObjTransformLayer.add(std::move(RT), std::move(Obj));
+  return ObjTransformLayer->add(std::move(RT), std::move(Obj));
 }
 
 Error LLJIT::addObjectFile(JITDylib , std::unique_ptr Obj) {
@@ -1057,8 +1058,7 @@ LLJIT::createCompileFunction(LLJITBuilderState ,
 LLJIT::LLJIT(LLJITBuilderState , Error )
 : ES(S.ES ? std::move(S.ES) : std::make_unique()), 
Main(),
   DL(""), TT(S.JTMB->getTargetTriple()),
-  ObjLinkingLayer(createObjectLinkingLayer(S, *ES)),
-  ObjTransformLayer(*this->ES, *ObjLinkingLayer) {
+  ObjLinkingLayer(createObjectLinkingLayer(S, *ES)) {
 
   ErrorAsOutParameter _();
 
@@ -1078,6 +1078,9 @@ LLJIT::LLJIT(LLJITBuilderState , Error )
 return;
   }
 
+  ObjTransformLayer =
+  std::make_unique(*ES, *ObjLinkingLayer);
+
   {
 auto CompileFunction = createCompileFunction(S, std::move(*S.JTMB));
 if (!CompileFunction) {
@@ -1085,7 +1088,7 @@ LLJIT::LLJIT(LLJITBuilderState , Error )
   return;
 }
 CompileLayer = std::make_unique(
-*ES, ObjTransformLayer, std::move(*CompileFunction));
+*ES, *ObjTransformLayer, std::move(*CompileFunction));
 TransformLayer = std::make_unique(*ES, *CompileLayer);
 InitHelperTransformLayer =
 std::make_unique(*ES, *TransformLayer);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 332e220 - [docs] Update DebuggingJITedCode page after fix in LLDB

2021-01-14 Thread Stefan Gränitz via llvm-branch-commits

Author: Stefan Gränitz
Date: 2021-01-14T15:43:11+01:00
New Revision: 332e220ef42b92df4e080cfa5b91c9accbe9731b

URL: 
https://github.com/llvm/llvm-project/commit/332e220ef42b92df4e080cfa5b91c9accbe9731b
DIFF: 
https://github.com/llvm/llvm-project/commit/332e220ef42b92df4e080cfa5b91c9accbe9731b.diff

LOG: [docs] Update DebuggingJITedCode page after fix in LLDB

Generalize the documentation to include both, GDB and LLDB. Add a link to the 
interface
definition. Make a note on MCJIT's restriction to ELF. Mention the regression 
and bugfix
in LLDB as well as the jit-loader setting for macOS. Update the command line 
session to
use LLDB instead of GDB.

Reviewed By: lhames

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

Added: 


Modified: 
llvm/docs/DebuggingJITedCode.rst

Removed: 




diff  --git a/llvm/docs/DebuggingJITedCode.rst 
b/llvm/docs/DebuggingJITedCode.rst
index e4885e42fa10..e1583648978a 100644
--- a/llvm/docs/DebuggingJITedCode.rst
+++ b/llvm/docs/DebuggingJITedCode.rst
@@ -1,35 +1,48 @@
-==
-Debugging JIT-ed Code With GDB
-==
+=
+Debugging JIT-ed Code
+=
 
 Background
 ==
 
-Without special runtime support, debugging dynamically generated code with
-GDB (as well as most debuggers) can be quite painful.  Debuggers generally
-read debug information from the object file of the code, but for JITed
-code, there is no such file to look for.
-
-In order to communicate the necessary debug info to GDB, an interface for
-registering JITed code with debuggers has been designed and implemented for
-GDB and LLVM MCJIT.  At a high level, whenever MCJIT generates new machine 
code,
-it does so in an in-memory object file that contains the debug information in
-DWARF format.  MCJIT then adds this in-memory object file to a global list of
-dynamically generated object files and calls a special function
-(``__jit_debug_register_code``) marked noinline that GDB knows about.  When
-GDB attaches to a process, it puts a breakpoint in this function and loads all
-of the object files in the global list.  When MCJIT calls the registration
-function, GDB catches the breakpoint signal, loads the new object file from
-the inferior's memory, and resumes the execution.  In this way, GDB can get the
-necessary debug information.
+Without special runtime support, debugging dynamically generated code can be
+quite painful.  Debuggers generally read debug information from object files on
+disk, but for JITed code there is no such file to look for.
+
+In order to hand over the necessary debug info, `GDB established an
+interface 
`_
+for registering JITed code with debuggers. LLDB implements it in the
+JITLoaderGDB plugin.  On the JIT side, LLVM MCJIT does implement the interface
+for ELF object files.
+
+At a high level, whenever MCJIT generates new machine code, it does so in an
+in-memory object file that contains the debug information in DWARF format.
+MCJIT then adds this in-memory object file to a global list of dynamically
+generated object files and calls a special function
+``__jit_debug_register_code`` that the debugger knows about. When the debugger
+attaches to a process, it puts a breakpoint in this function and associates a
+special handler with it.  Once MCJIT calls the registration function, the
+debugger catches the breakpoint signal, loads the new object file from the
+inferior's memory and resumes execution.  This way it can obtain debug
+information for pure in-memory object files.
+
 
 GDB Version
 ===
 
 In order to debug code JIT-ed by LLVM, you need GDB 7.0 or newer, which is
 available on most modern distributions of Linux.  The version of GDB that
-Apple ships with Xcode has been frozen at 6.3 for a while.  LLDB may be a
-better option for debugging JIT-ed code on macOS.
+Apple ships with Xcode has been frozen at 6.3 for a while.
+
+
+LLDB Version
+
+
+Due to a regression in release 6.0, LLDB didn't support JITed code debugging 
for
+a while.  The bug was fixed in mainline recently, so that debugging JITed ELF
+objects should be possible again from the upcoming release 12.0 on. On macOS 
the
+feature must be enabled explicitly using the ``plugin.jit-loader.gdb.enable``
+setting.
 
 
 Debugging MCJIT-ed code
@@ -39,8 +52,8 @@ The emerging MCJIT component of LLVM allows full debugging of 
JIT-ed code with
 GDB.  This is due to MCJIT's ability to use the MC emitter to provide full
 DWARF debugging information to GDB.
 
-Note that lli has to be passed the ``-jit-kind=mcjit`` flag to JIT the code 
with
-MCJIT instead of the old JIT.
+Note that lli has to be passed the ``--jit-kind=mcjit`` flag to JIT the code
+with MCJIT instead of the newer ORC JIT.
 
 Example
 ---
@@ -81,63 +94,89 @@ easier to follow):
22  }
 

[llvm-branch-commits] [llvm] c54d827 - [Orc] Two small fixes in TPCDynamicLibrarySearchGenerator

2020-12-08 Thread Stefan Gränitz via llvm-branch-commits

Author: Stefan Gränitz
Date: 2020-12-08T10:58:20+01:00
New Revision: c54d827fdb12d033dca2155c416f02791fc86786

URL: 
https://github.com/llvm/llvm-project/commit/c54d827fdb12d033dca2155c416f02791fc86786
DIFF: 
https://github.com/llvm/llvm-project/commit/c54d827fdb12d033dca2155c416f02791fc86786.diff

LOG: [Orc] Two small fixes in TPCDynamicLibrarySearchGenerator

There is one result per lookup symbol, so we have to advance the result 
iterator no matter whether it's NULL or not.
MissingSymbols variable is unused.

Reviewed By: lhames

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

Added: 


Modified: 
llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp

Removed: 




diff  --git a/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp 
b/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp
index f275c634a6d5..80d8f34ea447 100644
--- a/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TPCDynamicLibrarySearchGenerator.cpp
@@ -50,12 +50,13 @@ Error TPCDynamicLibrarySearchGenerator::tryToGenerate(
   assert(Result->front().size() == LookupSymbols.size() &&
  "Result has incorrect number of elements");
 
-  SymbolNameVector MissingSymbols;
   auto ResultI = Result->front().begin();
-  for (auto  : LookupSymbols)
+  for (auto  : LookupSymbols) {
 if (*ResultI)
   NewSymbols[KV.first] =
-  JITEvaluatedSymbol(*ResultI++, JITSymbolFlags::Exported);
+  JITEvaluatedSymbol(*ResultI, JITSymbolFlags::Exported);
+ResultI++;
+  }
 
   // If there were no resolved symbols bail out.
   if (NewSymbols.empty())



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 83b52b5 - [JITLink][ELF] Route objects to their matching linker backends based on header info

2020-12-08 Thread Stefan Gränitz via llvm-branch-commits

Author: Stefan Gränitz
Date: 2020-12-08T10:56:01+01:00
New Revision: 83b52b5ba27815200e76343f2a2f1614bb1960d9

URL: 
https://github.com/llvm/llvm-project/commit/83b52b5ba27815200e76343f2a2f1614bb1960d9
DIFF: 
https://github.com/llvm/llvm-project/commit/83b52b5ba27815200e76343f2a2f1614bb1960d9.diff

LOG: [JITLink][ELF] Route objects to their matching linker backends based on 
header info

Distinguish objects by target properties address size, endian and machine 
architecture. So far we only
support x86-64 (ELFCLASS64, ELFDATA2LSB, EM_X86_64).

Reviewed By: lhames

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

Added: 


Modified: 
llvm/lib/ExecutionEngine/JITLink/ELF.cpp

Removed: 




diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF.cpp 
b/llvm/lib/ExecutionEngine/JITLink/ELF.cpp
index 6160583b13fe5..19b8782577097 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF.cpp
@@ -15,6 +15,7 @@
 
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/ExecutionEngine/JITLink/ELF_x86_64.h"
+#include "llvm/Object/ELF.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -27,24 +28,56 @@ using namespace llvm;
 namespace llvm {
 namespace jitlink {
 
-void jitLink_ELF(std::unique_ptr Ctx) {
+Expected readTargetMachineArch(StringRef Buffer) {
+  const char *Data = Buffer.data();
 
-  // We don't want to do full ELF validation here. We just verify it is 
elf'ish.
-  // Probably should parse into an elf header when we support more than x86 :)
+  if (Data[ELF::EI_DATA] == ELF::ELFDATA2LSB) {
+if (Data[ELF::EI_CLASS] == ELF::ELFCLASS64) {
+  if (auto File = llvm::object::ELF64LEFile::create(Buffer)) {
+return File->getHeader().e_machine;
+  } else {
+return File.takeError();
+  }
+} else if (Data[ELF::EI_CLASS] == ELF::ELFCLASS32) {
+  if (auto File = llvm::object::ELF32LEFile::create(Buffer)) {
+return File->getHeader().e_machine;
+  } else {
+return File.takeError();
+  }
+}
+  }
 
-  StringRef Data = Ctx->getObjectBuffer().getBuffer();
-  if (Data.size() < llvm::ELF::EI_MAG3 + 1) {
+  return ELF::EM_NONE;
+}
+
+void jitLink_ELF(std::unique_ptr Ctx) {
+  StringRef Buffer = Ctx->getObjectBuffer().getBuffer();
+  if (Buffer.size() < ELF::EI_MAG3 + 1) {
 Ctx->notifyFailed(make_error("Truncated ELF buffer"));
 return;
   }
 
-  if (!memcmp(Data.data(), llvm::ELF::ElfMagic, strlen(llvm::ELF::ElfMagic))) {
-if (Data.data()[llvm::ELF::EI_CLASS] == ELF::ELFCLASS64) {
-  return jitLink_ELF_x86_64(std::move(Ctx));
-}
+  if (memcmp(Buffer.data(), ELF::ElfMagic, strlen(ELF::ElfMagic)) != 0) {
+Ctx->notifyFailed(make_error("ELF magic not valid"));
+return;
+  }
+
+  Expected TargetMachineArch = readTargetMachineArch(Buffer);
+  if (!TargetMachineArch) {
+Ctx->notifyFailed(TargetMachineArch.takeError());
+return;
   }
 
-  Ctx->notifyFailed(make_error("ELF magic not valid"));
+  switch (*TargetMachineArch) {
+  case ELF::EM_X86_64:
+jitLink_ELF_x86_64(std::move(Ctx));
+return;
+  default:
+Ctx->notifyFailed(make_error(
+"Unsupported target machine architecture in ELF object " +
+Ctx->getObjectBuffer().getBufferIdentifier()));
+return;
+  }
 }
 
 } // end namespace jitlink



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits