diff options
author | Justin Bogner <mail@justinbogner.com> | 2016-03-22 22:24:29 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2016-03-22 22:24:29 +0000 |
commit | 8809c4027092bcce5d0588cc2a907fd99fba9a01 (patch) | |
tree | 1b8c656ba444dfd02790afd0bb5d9204adc475e0 | |
parent | bfb75e9bbceae6e872107df5c4e8c367291fdd53 (diff) | |
download | bcm5719-llvm-8809c4027092bcce5d0588cc2a907fd99fba9a01.tar.gz bcm5719-llvm-8809c4027092bcce5d0588cc2a907fd99fba9a01.zip |
MC: Don't access the filesystem in MCContext's constructor
MCContext shouldn't be accessing the filesystem - that's a gross
layering violation and makes it awkward to use as a library or in a
daemon where it may not even be allowed filesystem access.
The CWD lookup here is normally redundant anyway, since the calling
context either also looks up the CWD or sets this to something more
specific. Here, we fix up the one caller that doesn't already set up a
debug compilation dir and make it clear that the responsibility for
such set up is in the users of MCContext.
llvm-svn: 264109
-rw-r--r-- | llvm/include/llvm/MC/MCContext.h | 7 | ||||
-rw-r--r-- | llvm/lib/MC/MCContext.cpp | 5 | ||||
-rw-r--r-- | llvm/tools/llvm-mc/llvm-mc.cpp | 6 |
3 files changed, 8 insertions, 10 deletions
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 608d15a27cf..a787664de2f 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -404,14 +404,11 @@ namespace llvm { /// @{ /// \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. - /// Returns an empty string if the current directory cannot be determined. + /// The compilation directory should be set with \c setCompilationDir before + /// calling this function. If it is unset, an empty string will be returned. StringRef 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(); } /// \brief Get the main file name for use in error messages and debug diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index c5243ef62c9..96e24de6b4d 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -44,11 +44,6 @@ MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4), AllowTemporaryLabels(true), DwarfCompileUnitID(0), AutoReset(DoAutoReset), HadError(false) { - - std::error_code EC = llvm::sys::fs::current_path(CompilationDir); - if (EC) - CompilationDir.clear(); - SecureLogFile = getenv("AS_SECURE_LOG_FILE"); SecureLog = nullptr; SecureLogUsed = false; diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index 7803e35a44c..b706c53299f 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -452,6 +452,12 @@ int main(int argc, char **argv) { Ctx.setDwarfDebugProducer(StringRef(DwarfDebugProducer)); if (!DebugCompilationDir.empty()) Ctx.setCompilationDir(DebugCompilationDir); + else { + // If no compilation dir is set, try to use the current directory. + SmallString<128> CWD; + if (!sys::fs::current_path(CWD)) + Ctx.setCompilationDir(CWD); + } if (!MainFileName.empty()) Ctx.setMainFileName(MainFileName); |