ArchSpec: fix unintentional promotion of unspecified unknowns to specified unknowns

* ArchSpec::MergeFrom() would erroneously promote an unspecified
  unknown to a specified unknown when both the ArchSpec and the merged
  in ArchSpec were both unspecified unknowns. This no longer happens,
  which fixes issues with global module cache lookup in some
  situations.

* Added ArchSpec::DumpTriple(Stream&) that now properly prints
  unspecified unknowns as '*' and specified unknows as 'unknown'.
  This makes it trivial to tell the difference between the two.
  Converted printing code over ot using DumpTriple() rather than
  building from scratch.

* Fixed up a couple places that were not guaranteeing that an
  unspecified unknown was recorded as such.

llvm-svn: 250253
This commit is contained in:
Todd Fiala 2015-10-13 23:41:19 +00:00
parent a59fcbae4f
commit 7df337f85c
10 changed files with 85 additions and 27 deletions

View File

@ -340,12 +340,24 @@ public:
return !m_triple.getVendorName().empty();
}
bool
TripleVendorIsUnspecifiedUnknown() const
{
return m_triple.getVendor() == llvm::Triple::UnknownVendor && m_triple.getVendorName().empty();
}
bool
TripleOSWasSpecified() const
{
return !m_triple.getOSName().empty();
}
bool
TripleOSIsUnspecifiedUnknown() const
{
return m_triple.getOS() == llvm::Triple::UnknownOS && m_triple.getOSName().empty();
}
//------------------------------------------------------------------
/// Merges fields from another ArchSpec into this ArchSpec.
///
@ -484,6 +496,9 @@ public:
return m_triple;
}
void
DumpTriple(Stream &s) const;
//------------------------------------------------------------------
/// Architecture tripple setter.
///

View File

@ -329,7 +329,7 @@ public:
}
void
Dump (Stream &strm)
Dump (Stream &strm) const
{
bool dumped_something = false;
if (m_file)
@ -361,7 +361,8 @@ public:
{
if (dumped_something)
strm.PutCString(", ");
strm.Printf("arch = %s", m_arch.GetTriple().str().c_str());
strm.Printf("arch = ");
m_arch.DumpTriple(strm);
dumped_something = true;
}
if (m_uuid.IsValid())

View File

@ -79,7 +79,8 @@ DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bo
uint32_t properties = 0;
if (target_arch.IsValid())
{
strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
strm.Printf ("%sarch=", properties++ > 0 ? ", " : " ( ");
target_arch.DumpTriple (strm);
properties++;
}
PlatformSP platform_sp (target->GetPlatform());
@ -1459,15 +1460,18 @@ DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t
{
if (module)
{
const char *arch_cstr;
StreamString arch_strm;
if (full_triple)
arch_cstr = module->GetArchitecture().GetTriple().str().c_str();
module->GetArchitecture().DumpTriple(arch_strm);
else
arch_cstr = module->GetArchitecture().GetArchitectureName();
arch_strm.PutCString(module->GetArchitecture().GetArchitectureName());
std::string arch_str = arch_strm.GetString();
if (width)
strm.Printf("%-*s", width, arch_cstr);
strm.Printf("%-*s", width, arch_str.c_str());
else
strm.PutCString(arch_cstr);
strm.PutCString(arch_str.c_str());
}
}

View File

@ -844,9 +844,9 @@ ArchSpec::SetTriple (const char *triple_cstr, Platform *platform)
void
ArchSpec::MergeFrom(const ArchSpec &other)
{
if (GetTriple().getVendor() == llvm::Triple::UnknownVendor && !TripleVendorWasSpecified())
if (TripleVendorIsUnspecifiedUnknown() && !other.TripleVendorIsUnspecifiedUnknown())
GetTriple().setVendor(other.GetTriple().getVendor());
if (GetTriple().getOS() == llvm::Triple::UnknownOS && !TripleOSWasSpecified())
if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown())
GetTriple().setOS(other.GetTriple().getOS());
if (GetTriple().getArch() == llvm::Triple::UnknownArch)
GetTriple().setArch(other.GetTriple().getArch());
@ -1444,3 +1444,18 @@ ArchSpec::GetStopInfoOverrideCallback () const
return StopInfoOverrideCallbackTypeARM;
return NULL;
}
void
ArchSpec::DumpTriple(Stream &s) const
{
const llvm::Triple &triple = GetTriple();
llvm::StringRef arch_str = triple.getArchName();
llvm::StringRef vendor_str = triple.getVendorName();
llvm::StringRef os_str = triple.getOSName();
s.Printf("%s-%s-%s",
arch_str.empty() ? "*" : arch_str.str().c_str(),
vendor_str.empty() ? "*" : vendor_str.str().c_str(),
os_str.empty() ? "*" : os_str.str().c_str()
);
}

View File

@ -271,12 +271,12 @@ HostInfoLinux::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_
{
arch_32.SetDistributionId(distribution_id);
if (arch_32.GetTriple().getVendor() == llvm::Triple::UnknownVendor)
arch_32.GetTriple().setVendorName("");
arch_32.GetTriple().setVendorName(llvm::StringRef());
}
if (arch_64.IsValid())
{
arch_64.SetDistributionId(distribution_id);
if (arch_64.GetTriple().getVendor() == llvm::Triple::UnknownVendor)
arch_64.GetTriple().setVendorName("");
arch_64.GetTriple().setVendorName(llvm::StringRef());
}
}

View File

@ -1605,6 +1605,12 @@ ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
}
}
// Make any unknown triple components to be unspecified unknowns.
if (arch_spec.GetTriple().getVendor() == llvm::Triple::UnknownVendor)
arch_spec.GetTriple().setVendorName (llvm::StringRef());
if (arch_spec.GetTriple().getOS() == llvm::Triple::UnknownOS)
arch_spec.GetTriple().setOSName (llvm::StringRef());
return section_headers.size();
}
}

View File

@ -475,7 +475,11 @@ Platform::GetStatus (Stream &strm)
if (arch.IsValid())
{
if (!arch.GetTriple().str().empty())
strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str());
{
strm.Printf(" Triple: ");
arch.DumpTriple(strm);
strm.EOL();
}
}
if (GetOSVersion(major, minor, update))

View File

@ -316,8 +316,12 @@ ProcessInstanceInfo::Dump (Stream &s, Platform *platform) const
}
}
if (m_arch.IsValid())
s.Printf (" arch = %s\n", m_arch.GetTriple().str().c_str());
if (m_arch.IsValid())
{
s.Printf (" arch = ");
m_arch.DumpTriple(s);
s.EOL();
}
if (m_uid != UINT32_MAX)
{
@ -370,7 +374,10 @@ ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_ar
const char *cstr;
s.Printf ("%-6" PRIu64 " %-6" PRIu64 " ", m_pid, m_parent_pid);
StreamString arch_strm;
if (m_arch.IsValid())
m_arch.DumpTriple(arch_strm);
if (verbose)
{
cstr = platform->GetUserName (m_uid);
@ -396,13 +403,14 @@ ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_ar
s.Printf ("%-10s ", cstr);
else
s.Printf ("%-10u ", m_egid);
s.Printf ("%-24s ", m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : "");
s.Printf ("%-24s ", arch_strm.GetString().c_str());
}
else
{
s.Printf ("%-10s %-24s ",
platform->GetUserName (m_euid),
m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : "");
arch_strm.GetString().c_str());
}
if (verbose || show_args)

View File

@ -179,9 +179,14 @@ TargetList::CreateTargetInternal (Debugger &debugger,
}
else
{
StreamString platform_arch_strm;
StreamString module_arch_strm;
platform_arch.DumpTriple(platform_arch_strm);
matching_module_spec.GetArchitecture().DumpTriple(module_arch_strm);
error.SetErrorStringWithFormat("the specified architecture '%s' is not compatible with '%s' in '%s'",
platform_arch.GetTriple().str().c_str(),
matching_module_spec.GetArchitecture().GetTriple().str().c_str(),
platform_arch_strm.GetString().c_str(),
module_arch_strm.GetString().c_str(),
module_spec.GetFileSpec().GetPath().c_str());
return error;
}

View File

@ -19,13 +19,13 @@ class TestImageListMultiArchitecture(TestBase):
def test_image_list_shows_multiple_architectures(self):
"""Test that image list properly shows the correct architecture for a set of different architecture object files."""
images = {
"hello-freebsd-10.0-x86_64-clang-3.3": re.compile(r"x86_64-(unknown)?-freebsd10.0(-unknown)? x86_64"),
"hello-freebsd-10.0-x86_64-gcc-4.7.3": re.compile(r"x86_64-(unknown)?-freebsd10.0(-unknown)? x86_64"),
"hello-netbsd-6.1-x86_64-gcc-4.5.3": re.compile(r"x86_64-(unknown)?-netbsd(-unknown)? x86_64"),
"hello-ubuntu-14.04-x86_64-gcc-4.8.2": re.compile(r"x86_64-(unknown)?-linux(-unknown)? x86_64"),
"hello-ubuntu-14.04-x86_64-clang-3.5pre": re.compile(r"x86_64-(unknown)?-linux(-unknown)? x86_64"),
"hello-unknown-kalimba_arch4-kcc-36": re.compile(r"kalimba4-csr-unknown(-unknown)? kalimba"),
"hello-unknown-kalimba_arch5-kcc-39": re.compile(r"kalimba5-csr-unknown(-unknown)? kalimba"),
"hello-freebsd-10.0-x86_64-clang-3.3": re.compile(r"x86_64-(\*)?-freebsd10.0(-unknown)? x86_64"),
"hello-freebsd-10.0-x86_64-gcc-4.7.3": re.compile(r"x86_64-(\*)?-freebsd10.0(-unknown)? x86_64"),
"hello-netbsd-6.1-x86_64-gcc-4.5.3": re.compile(r"x86_64-(\*)?-netbsd(-unknown)? x86_64"),
"hello-ubuntu-14.04-x86_64-gcc-4.8.2": re.compile(r"x86_64-(\*)?-linux(-unknown)? x86_64"),
"hello-ubuntu-14.04-x86_64-clang-3.5pre": re.compile(r"x86_64-(\*)?-linux(-unknown)? x86_64"),
"hello-unknown-kalimba_arch4-kcc-36": re.compile(r"kalimba4-csr-(unknown|\*)(-unknown)? kalimba"),
"hello-unknown-kalimba_arch5-kcc-39": re.compile(r"kalimba5-csr-(unknown|\*)(-unknown)? kalimba"),
}
for image_name in images: