[lld] r240812 - COFF: Implement /lldmap flag.
Peter Collingbourne
peter at pcc.me.uk
Fri Jun 26 11:58:25 PDT 2015
Author: pcc
Date: Fri Jun 26 13:58:24 2015
New Revision: 240812
URL: http://llvm.org/viewvc/llvm-project?rev=240812&view=rev
Log:
COFF: Implement /lldmap flag.
This flag can be used to produce a map file, which is essentially a list
of objects linked into the final output file together with the RVAs of
their symbols. Because our format differs from MSVC's we expose it as a
separate flag.
Differential Revision: http://reviews.llvm.org/D10773
Added:
lld/trunk/test/COFF/lldmap.test
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Options.td
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=240812&r1=240811&r2=240812&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Jun 26 13:58:24 2015
@@ -34,6 +34,7 @@ using llvm::COFF::IMAGE_SUBSYSTEM_UNKNOW
using llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI;
using llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI;
using llvm::sys::Process;
+using llvm::sys::fs::OpenFlags::F_Text;
using llvm::sys::fs::file_magic;
using llvm::sys::fs::identify_magic;
@@ -597,6 +598,17 @@ bool LinkerDriver::link(llvm::ArrayRef<c
llvm::errs() << EC.message() << "\n";
return false;
}
+
+ if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
+ std::error_code EC;
+ llvm::raw_fd_ostream Out(Arg->getValue(), EC, F_Text);
+ if (EC) {
+ llvm::errs() << EC.message() << "\n";
+ return false;
+ }
+ Symtab.printMap(Out);
+ }
+
return true;
}
Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=240812&r1=240811&r2=240812&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Fri Jun 26 13:58:24 2015
@@ -88,8 +88,8 @@ def help_q : Flag<["/?", "-?"], "">, Ali
def DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>;
-// Flag for debug
-def lldmoduledeffile : Joined<["/", "-"], "lldmoduledeffile:">;
+// Flags for debugging
+def lldmap : Joined<["/", "-"], "lldmap:">;
//==============================================================================
// The flags below do nothing. They are defined only for link.exe compatibility.
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=240812&r1=240811&r2=240812&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Fri Jun 26 13:58:24 2015
@@ -237,6 +237,17 @@ void SymbolTable::dump() {
}
}
+void SymbolTable::printMap(llvm::raw_ostream &OS) {
+ for (ObjectFile *File : ObjectFiles) {
+ OS << File->getShortName() << ":\n";
+ for (SymbolBody *Body : File->getSymbols())
+ if (auto *R = dyn_cast<DefinedRegular>(Body))
+ if (R->isLive())
+ OS << Twine::utohexstr(Config->ImageBase + R->getRVA())
+ << " " << R->getName() << "\n";
+ }
+}
+
std::error_code SymbolTable::addCombinedLTOObject() {
if (BitcodeFiles.empty())
return std::error_code();
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=240812&r1=240811&r2=240812&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Fri Jun 26 13:58:24 2015
@@ -12,6 +12,7 @@
#include "InputFiles.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/raw_ostream.h"
#include <unordered_map>
namespace llvm {
@@ -62,6 +63,9 @@ public:
// Dump contents of the symbol table to stderr.
void dump();
+ // Print a layout map to OS.
+ void printMap(llvm::raw_ostream &OS);
+
// Build a COFF object representing the combined contents of BitcodeFiles
// and add it to the symbol table. Called after all files are added and
// before the writer writes results to a file.
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=240812&r1=240811&r2=240812&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Fri Jun 26 13:58:24 2015
@@ -134,6 +134,7 @@ public:
int compare(SymbolBody *Other) override;
std::string getDebugName() override;
bool isCOMDAT() { return IsCOMDAT; }
+ bool isLive() const { return (*Data)->isLive(); }
void markLive() { (*Data)->markLive(); }
Chunk *getChunk() { return *Data; }
Added: lld/trunk/test/COFF/lldmap.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lldmap.test?rev=240812&view=auto
==============================================================================
--- lld/trunk/test/COFF/lldmap.test (added)
+++ lld/trunk/test/COFF/lldmap.test Fri Jun 26 13:58:24 2015
@@ -0,0 +1,8 @@
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+# RUN: lld -flavor link2 /out:%t.exe /lldmap:%t.map %t.obj
+# RUN: FileCheck %s < %t.map
+
+# CHECK: .obj:
+# CHECK-NEXT: 140001000 .text$mn
+# CHECK-NEXT: 140001000 .data
+# CHECK-NEXT: 140001000 mainCRTStartup
More information about the llvm-commits
mailing list