[PATCH] D21471: [MCContext] Don't use getenv inside class constructor

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 17 07:30:34 PDT 2016


igor-laevsky created this revision.
igor-laevsky added reviewers: rnk, enderby, rafael.
igor-laevsky added a subscriber: llvm-commits.

In our llvm use case we are observing rare crashes inside MCContext constructor. Apparently they were caused by the non thread safe getenv call. This change handles this problem by moving getenv call into initialisation of a static command line option. It's slightly better then explicit locks and less complicated than adding new constructor argument.

This issue was already discussed sometime ago (see http://lists.llvm.org/pipermail/llvm-dev/2013-May/062367.html) but I haven't found any evidence that it was fixed back then.

http://reviews.llvm.org/D21471

Files:
  lib/MC/MCContext.cpp

Index: lib/MC/MCContext.cpp
===================================================================
--- lib/MC/MCContext.cpp
+++ lib/MC/MCContext.cpp
@@ -25,14 +25,22 @@
 #include "llvm/MC/MCSymbolELF.h"
 #include "llvm/MC/MCSymbolMachO.h"
 #include "llvm/Support/COFF.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/SourceMgr.h"
 
 using namespace llvm;
 
+static cl::opt<char*>
+AsSecureLogFileName("as-secure-log-file-name",
+        cl::desc("As secure log file name (initialized from "
+                 "AS_SECURE_LOG_FILE env variable)"),
+        cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden);
+
+
 MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
                      const MCObjectFileInfo *mofi, const SourceMgr *mgr,
                      bool DoAutoReset)
@@ -42,7 +50,7 @@
       GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
       AllowTemporaryLabels(true), DwarfCompileUnitID(0),
       AutoReset(DoAutoReset), HadError(false) {
-  SecureLogFile = getenv("AS_SECURE_LOG_FILE");
+  SecureLogFile = AsSecureLogFileName;
   SecureLog = nullptr;
   SecureLogUsed = false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21471.61094.patch
Type: text/x-patch
Size: 1299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160617/078e9277/attachment.bin>


More information about the llvm-commits mailing list