[Lldb-commits] [lldb] r226849 - Don't stomp the triple when loading a PECOFF target.

Zachary Turner zturner at google.com
Thu Jan 22 10:59:06 PST 2015


Author: zturner
Date: Thu Jan 22 12:59:05 2015
New Revision: 226849

URL: http://llvm.org/viewvc/llvm-project?rev=226849&view=rev
Log:
Don't stomp the triple when loading a PECOFF target.

When you create a target, it tries to look for the platform's list
of supported architectures for a match.  The match it finds can
contain specific triples, like i386-pc-windows-msvc.  Later, we
overwrite this value with the most generic triple that can apply
to any platform with COFF support, causing some of the fields of
the triple to get overwritten.

This patch changes the behavior to only merge in values from the COFF
triple if the fields of the matching triple were unknown/unspecified
to begin with.

This fixes load address resolution on Windows, since it enables the
DynamicLoaderWindows to be used instead of DynamicLoaderStatic.

Reviewed by: Greg Clayton
Differential Revision: http://reviews.llvm.org/D7120

Modified:
    lldb/trunk/include/lldb/Core/ArchSpec.h
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Modified: lldb/trunk/include/lldb/Core/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=226849&r1=226848&r2=226849&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ArchSpec.h Thu Jan 22 12:59:05 2015
@@ -277,6 +277,21 @@ public:
     }
 
     //------------------------------------------------------------------
+    /// Merges fields from another ArchSpec into this ArchSpec.
+    ///
+    /// This will use the supplied ArchSpec to fill in any fields of
+    /// the triple in this ArchSpec which were unspecified.  This can
+    /// be used to refine a generic ArchSpec with a more specific one.
+    /// For example, if this ArchSpec's triple is something like
+    /// i386-unknown-unknown-unknown, and we have a triple which is
+    /// x64-pc-windows-msvc, then merging that triple into this one
+    /// will result in the triple i386-pc-windows-msvc.
+    ///
+    //------------------------------------------------------------------
+    void
+    MergeFrom(const ArchSpec &other);
+
+    //------------------------------------------------------------------
     /// Sets this ArchSpec according to the given architecture name.
     ///
     /// The architecture name can be one of the generic system default

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=226849&r1=226848&r2=226849&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Thu Jan 22 12:59:05 2015
@@ -765,6 +765,19 @@ ArchSpec::SetTriple (const char *triple_
     return IsValid();
 }
 
+void
+ArchSpec::MergeFrom(const ArchSpec &other)
+{
+    if (GetTriple().getVendor() == llvm::Triple::UnknownVendor && !TripleVendorWasSpecified())
+        GetTriple().setVendor(other.GetTriple().getVendor());
+    if (GetTriple().getOS() == llvm::Triple::UnknownOS && !TripleOSWasSpecified())
+        GetTriple().setOS(other.GetTriple().getOS());
+    if (GetTriple().getArch() == llvm::Triple::UnknownArch)
+        GetTriple().setArch(other.GetTriple().getArch());
+    if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment)
+        GetTriple().setEnvironment(other.GetTriple().getEnvironment());
+}
+
 bool
 ArchSpec::SetArchitecture (ArchitectureType arch_type, uint32_t cpu, uint32_t sub)
 {

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=226849&r1=226848&r2=226849&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Thu Jan 22 12:59:05 2015
@@ -1304,10 +1304,14 @@ Module::GetObjectFile()
                                                    data_offset);
             if (m_objfile_sp)
             {
-                // Once we get the object file, update our module with the object file's 
+                // Once we get the object file, update our module with the object file's
                 // architecture since it might differ in vendor/os if some parts were
-                // unknown.
-                m_objfile_sp->GetArchitecture (m_arch);
+                // unknown.  But since the matching arch might already be more specific
+                // than the generic COFF architecture, only merge in those values that
+                // overwrite unspecified unknown values.
+                ArchSpec new_arch;
+                m_objfile_sp->GetArchitecture(new_arch);
+                m_arch.MergeFrom(new_arch);
             }
             else
             {

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=226849&r1=226848&r2=226849&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Thu Jan 22 12:59:05 2015
@@ -130,10 +130,17 @@ ObjectFilePECOFF::GetModuleSpecification
             {
                 ArchSpec spec;
                 if (coff_header.machine == MachineAmd64)
+                {
                     spec.SetTriple("x86_64-pc-windows");
+                    specs.Append(ModuleSpec(file, spec));
+                }
                 else if (coff_header.machine == MachineX86)
+                {
                     spec.SetTriple("i386-pc-windows");
-                specs.Append(ModuleSpec(file, spec));
+                    specs.Append(ModuleSpec(file, spec));
+                    spec.SetTriple("i686-pc-windows");
+                    specs.Append(ModuleSpec(file, spec));
+                }
             }
         }
     }





More information about the lldb-commits mailing list