llvm.org GIT mirror llvm / 6c31d31
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 Chandler Carruth 7 years ago
5 changed file(s) with 30 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
9393 /// .secure_log_reset appearing between them.
9494 bool SecureLogUsed;
9595
96 /// The compilation directory to use for DW_AT_comp_dir.
97 std::string CompilationDir;
98
9699 /// The dwarf file and directory tables from the dwarf .file directive.
97100 std::vector MCDwarfFiles;
98101 std::vector MCDwarfDirs;
246249
247250 /// @name Dwarf Management
248251 /// @{
252
253 /// \brief Get the compilation directory for DW_AT_comp_dir
254 /// This can be overridden by clients which want to control the reported
255 /// compilation directory and have it be something other than the current
256 /// working directory.
257 const std::string &getCompilationDir() const { return CompilationDir; }
258
259 /// \brief Set the compilation directory for DW_AT_comp_dir
260 /// Override the default (CWD) compilation directory.
261 void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
249262
250263 /// GetDwarfFile - creates an entry in the dwarf file and directory tables.
251264 unsigned GetDwarfFile(StringRef Directory, StringRef FileName,
3434 bool DoAutoReset ) :
3535 SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi),
3636 Allocator(), Symbols(Allocator), UsedNames(Allocator),
37 NextUniqueID(0),
37 NextUniqueID(0),
38 CompilationDir(llvm::sys::Path::GetCurrentDirectory().str()),
3839 CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
3940 DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0),
4041 AllowTemporaryLabels(true), AutoReset(DoAutoReset) {
626626 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
627627
628628 // AT_comp_dir, the working directory the assembly was done in.
629 llvm::sys::Path CWD = llvm::sys::Path::GetCurrentDirectory();
630 MCOS->EmitBytes(StringRef(CWD.c_str()), 0);
629 MCOS->EmitBytes(context.getCompilationDir(), 0);
631630 MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
632631
633632 // AT_APPLE_flags, the command line arguments of the assembler tool.
0 // RUN: llvm-mc -g -fdebug-compilation-dir=/test/comp/dir %s -filetype=obj -o %t.o
1 // RUN: llvm-dwarfdump %t.o | FileCheck %s
2
3 // CHECK: DW_AT_comp_dir [DW_FORM_string] ("/test/comp/dir")
4
5 f:
6 nop
155155 static cl::opt
156156 GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly "
157157 "source files"));
158
159 static cl::opt
160 DebugCompilationDir("fdebug-compilation-dir",
161 cl::desc("Specifies the debug info's compilation dir"));
158162
159163 enum ActionType {
160164 AC_AsLex,
388392 Ctx.setAllowTemporaryLabels(false);
389393
390394 Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
391 if (!DwarfDebugFlags.empty())
395 if (!DwarfDebugFlags.empty())
392396 Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags));
397 if (!DebugCompilationDir.empty())
398 Ctx.setCompilationDir(DebugCompilationDir);
393399
394400 // Package up features to be passed to target/subtarget
395401 std::string FeaturesStr;