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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170371 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth 2012-12-17 21:32:42 +00:00
parent c83b8fec01
commit 6c31d31357
5 changed files with 30 additions and 4 deletions

View File

@ -94,6 +94,9 @@ namespace llvm {
/// .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 @@ namespace llvm {
/// @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);

View File

@ -35,7 +35,8 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
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) {

View File

@ -627,8 +627,7 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
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.

7
test/MC/ELF/comp-dir.s Normal file
View File

@ -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

View File

@ -157,6 +157,10 @@ static cl::opt<bool>
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 @@ int main(int argc, char **argv) {
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;