]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/patches/patch-r262611-llvm-r196874-fix-invalid-pwd-crash.diff
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / patches / patch-r262611-llvm-r196874-fix-invalid-pwd-crash.diff
1 Pull in r196874 from upstream llvm trunk (by Andrew Trick):
2
3   Fix a crash that occurs when PWD is invalid.
4
5   MCJIT needs to be able to run in hostile environments, even when PWD
6   is invalid. There's no need to crash MCJIT in this case.
7
8   The obvious fix is to simply leave MCContext's CompilationDir empty
9   when PWD can't be determined. This way, MCJIT clients,
10   and other clients that link with LLVM don?\226?\128?\153t need a valid working directory.
11
12   If we do want to guarantee valid CompilationDir, that should be done
13   only for clients of getCompilationDir(). This is as simple as checking
14   for an empty string.
15
16   The only current use of getCompilationDir is EmitGenDwarfInfo, which
17   won?\226?\128?\153t conceivably run with an invalid working dir. However, in the
18   purely hypothetically and untestable case that this happens, the
19   AT_comp_dir will be omitted from the compilation_unit DIE.
20
21 Introduced here: http://svnweb.freebsd.org/changeset/base/262611
22
23 Index: include/llvm/MC/MCContext.h
24 ===================================================================
25 --- include/llvm/MC/MCContext.h
26 +++ include/llvm/MC/MCContext.h
27 @@ -278,6 +278,7 @@ namespace llvm {
28      /// This can be overridden by clients which want to control the reported
29      /// compilation directory and have it be something other than the current
30      /// working directory.
31 +    /// Returns an empty string if the current directory cannot be determined.
32      StringRef getCompilationDir() const { return CompilationDir; }
33  
34      /// \brief Set the compilation directory for DW_AT_comp_dir
35 Index: lib/MC/MCContext.cpp
36 ===================================================================
37 --- lib/MC/MCContext.cpp
38 +++ lib/MC/MCContext.cpp
39 @@ -47,8 +47,8 @@ MCContext::MCContext(const MCAsmInfo *mai, const M
40    AllowTemporaryLabels(true), DwarfCompileUnitID(0), AutoReset(DoAutoReset) {
41  
42    error_code EC = llvm::sys::fs::current_path(CompilationDir);
43 -  assert(!EC && "Could not determine the current directory");
44 -  (void)EC;
45 +  if (EC)
46 +    CompilationDir.clear();
47  
48    MachOUniquingMap = 0;
49    ELFUniquingMap = 0;
50 Index: lib/MC/MCDwarf.cpp
51 ===================================================================
52 --- lib/MC/MCDwarf.cpp
53 +++ lib/MC/MCDwarf.cpp
54 @@ -467,7 +467,8 @@ static void EmitGenDwarfAbbrev(MCStreamer *MCOS) {
55    EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
56    EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
57    EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
58 -  EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
59 +  if (!context.getCompilationDir().empty())
60 +    EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
61    StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
62    if (!DwarfDebugFlags.empty())
63      EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
64 @@ -643,8 +644,10 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
65    MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
66  
67    // AT_comp_dir, the working directory the assembly was done in.
68 -  MCOS->EmitBytes(context.getCompilationDir());
69 -  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
70 +  if (!context.getCompilationDir().empty()) {
71 +    MCOS->EmitBytes(context.getCompilationDir());
72 +    MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
73 +  }
74  
75    // AT_APPLE_flags, the command line arguments of the assembler tool.
76    StringRef DwarfDebugFlags = context.getDwarfDebugFlags();