[llvm-commits] [llvm] r170371 - in /llvm/trunk: include/llvm/MC/MCContext.h lib/MC/MCContext.cpp lib/MC/MCDwarf.cpp test/MC/ELF/comp-dir.s tools/llvm-mc/llvm-mc.cpp
Chandler Carruth
chandlerc at gmail.com
Mon Dec 17 13:32:43 PST 2012
Author: chandlerc
Date: Mon Dec 17 15:32:42 2012
New Revision: 170371
URL: http://llvm.org/viewvc/llvm-project?rev=170371&view=rev
Log:
Prepare LLVM to fix PR14625, exposing a hook in MCContext to manage the
compilation directory.
This defaults to the current working directory, just as it always has,
but now an assembler can choose to override it with a custom directory.
I've taught llvm-mc about this option and added a test case.
Added:
llvm/trunk/test/MC/ELF/comp-dir.s
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCDwarf.cpp
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=170371&r1=170370&r2=170371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Mon Dec 17 15:32:42 2012
@@ -94,6 +94,9 @@
/// .secure_log_reset appearing between them.
bool SecureLogUsed;
+ /// The compilation directory to use for DW_AT_comp_dir.
+ std::string CompilationDir;
+
/// The dwarf file and directory tables from the dwarf .file directive.
std::vector<MCDwarfFile *> MCDwarfFiles;
std::vector<StringRef> MCDwarfDirs;
@@ -248,6 +251,16 @@
/// @name Dwarf Management
/// @{
+ /// \brief Get the compilation directory for DW_AT_comp_dir
+ /// This can be overridden by clients which want to control the reported
+ /// compilation directory and have it be something other than the current
+ /// working directory.
+ const std::string &getCompilationDir() const { return CompilationDir; }
+
+ /// \brief Set the compilation directory for DW_AT_comp_dir
+ /// Override the default (CWD) compilation directory.
+ void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
+
/// GetDwarfFile - creates an entry in the dwarf file and directory tables.
unsigned GetDwarfFile(StringRef Directory, StringRef FileName,
unsigned FileNumber);
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=170371&r1=170370&r2=170371&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Mon Dec 17 15:32:42 2012
@@ -35,7 +35,8 @@
bool DoAutoReset ) :
SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi),
Allocator(), Symbols(Allocator), UsedNames(Allocator),
- NextUniqueID(0),
+ NextUniqueID(0),
+ CompilationDir(llvm::sys::Path::GetCurrentDirectory().str()),
CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0),
AllowTemporaryLabels(true), AutoReset(DoAutoReset) {
Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=170371&r1=170370&r2=170371&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Mon Dec 17 15:32:42 2012
@@ -627,8 +627,7 @@
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
// AT_comp_dir, the working directory the assembly was done in.
- llvm::sys::Path CWD = llvm::sys::Path::GetCurrentDirectory();
- MCOS->EmitBytes(StringRef(CWD.c_str()), 0);
+ MCOS->EmitBytes(context.getCompilationDir(), 0);
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
// AT_APPLE_flags, the command line arguments of the assembler tool.
Added: llvm/trunk/test/MC/ELF/comp-dir.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/comp-dir.s?rev=170371&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/comp-dir.s (added)
+++ llvm/trunk/test/MC/ELF/comp-dir.s Mon Dec 17 15:32:42 2012
@@ -0,0 +1,7 @@
+// RUN: llvm-mc -g -fdebug-compilation-dir=/test/comp/dir %s -filetype=obj -o %t.o
+// RUN: llvm-dwarfdump %t.o | FileCheck %s
+
+// CHECK: DW_AT_comp_dir [DW_FORM_string] ("/test/comp/dir")
+
+f:
+ nop
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=170371&r1=170370&r2=170371&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Mon Dec 17 15:32:42 2012
@@ -157,6 +157,10 @@
GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly "
"source files"));
+static cl::opt<std::string>
+DebugCompilationDir("fdebug-compilation-dir",
+ cl::desc("Specifies the debug info's compilation dir"));
+
enum ActionType {
AC_AsLex,
AC_Assemble,
@@ -389,8 +393,10 @@
Ctx.setAllowTemporaryLabels(false);
Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
- if (!DwarfDebugFlags.empty())
+ if (!DwarfDebugFlags.empty())
Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags));
+ if (!DebugCompilationDir.empty())
+ Ctx.setCompilationDir(DebugCompilationDir);
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
More information about the llvm-commits
mailing list