Now that it is possible, use the mangler in IRObjectFile.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 28 Feb 2014 02:17:23 +0000 (02:17 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 28 Feb 2014 02:17:23 +0000 (02:17 +0000)
A really simple patch marks the end of a lot of yak shaving :-)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202463 91177308-0d34-0410-b5e6-96231b3b80d8

docs/ReleaseNotes.rst
include/llvm/Object/IRObjectFile.h
lib/Object/IRObjectFile.cpp
test/Object/mangle-ir.ll [new file with mode: 0644]

index 42127c81f707bf954bdbbccd5bc1938443eb6264..07d4d07069b428dead36b792e901d7c951a11417 100644 (file)
@@ -52,6 +52,9 @@ Non-comprehensive list of changes in this release
   for assembly output as well. The integrated assembler can be disabled with
   the ``-no-integrated-as`` option,
 
+* llvm-ar now handles IR files like regular object files. In particular, a
+  regular symbol table is created for symbols defined in IR files.
+
 .. NOTE
    For small 1-3 sentence descriptions, just add an entry at the end of
    this list. If your description won't fit comfortably in one bullet
index e1effa6745a7ad918a319254a02742218fbfdf21..e85dd6710326aad2ab1bd140f29ed518af1bb8ba 100644 (file)
 #include "llvm/Object/SymbolicFile.h"
 
 namespace llvm {
+class Mangler;
 class Module;
 class GlobalValue;
 
 namespace object {
 class IRObjectFile : public SymbolicFile {
   OwningPtr<Module> M;
+  OwningPtr<Mangler> Mang;
 public:
   IRObjectFile(MemoryBuffer *Object, error_code &EC, LLVMContext &Context,
                bool BufferOwned);
index 37e7eb80ca542e3c698ce9ce74a4515613313421..b3a5668fc20d13e3ec554152fed1cdda85e99fd0 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Mangler.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Support/raw_ostream.h"
@@ -27,6 +28,13 @@ IRObjectFile::IRObjectFile(MemoryBuffer *Object, error_code &EC,
     return;
 
   M.reset(MOrErr.get());
+
+  // If we have a DataLayout, setup a mangler.
+  const DataLayout *DL = M->getDataLayout();
+  if (!DL)
+    return;
+
+  Mang.reset(new Mangler(DL));
 }
 
 static const GlobalValue &getGV(DataRefImpl &Symb) {
@@ -86,9 +94,13 @@ void IRObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
 
 error_code IRObjectFile::printSymbolName(raw_ostream &OS,
                                          DataRefImpl Symb) const {
-  // FIXME: This should use the Mangler.
   const GlobalValue &GV = getGV(Symb);
-  OS << GV.getName();
+
+  if (Mang)
+    Mang->getNameWithPrefix(OS, &GV, false);
+  else
+    OS << GV.getName();
+
   return object_error::success;
 }
 
diff --git a/test/Object/mangle-ir.ll b/test/Object/mangle-ir.ll
new file mode 100644 (file)
index 0000000..725d788
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: llvm-as %s -o - | llvm-nm - | FileCheck %s
+
+target datalayout = "m:o"
+
+; CHECK: T _f
+define void @f() {
+  ret void
+}