1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[llvm-cov] Warn when -arch spec is missing/invalid for universal binary (reland)

llvm-cov reports a poor error message when the -arch specifier is
missing or invalid, and a binary has multiple slices. Make the error
message more specific.

(This version of the patch avoids using llvm::none_of -- the way I used
the utility caused compile errors on many bots, possibly because the
wrong overload of `none_of` was selected.)

rdar://40312677
This commit is contained in:
Vedant Kumar 2020-10-13 16:20:40 -07:00
parent 65259aae54
commit 267d2a2041
4 changed files with 23 additions and 2 deletions

View File

@ -55,7 +55,8 @@ enum class coveragemap_error {
unsupported_version,
truncated,
malformed,
decompression_failed
decompression_failed,
invalid_or_missing_arch_specifier
};
const std::error_category &coveragemap_category();

View File

@ -816,6 +816,8 @@ static std::string getCoverageMapErrString(coveragemap_error Err) {
return "Malformed coverage data";
case coveragemap_error::decompression_failed:
return "Failed to decompress coverage data (zlib)";
case coveragemap_error::invalid_or_missing_arch_specifier:
return "`-arch` specifier is invalid or missing for universal binary";
}
llvm_unreachable("A value of coveragemap_error has no message.");
}

View File

@ -950,6 +950,19 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch) {
BytesInAddress, Endian);
}
/// Determine whether \p Arch is invalid or empty, given \p Bin.
static bool isArchSpecifierInvalidOrMissing(Binary *Bin, StringRef Arch) {
// If we have a universal binary and Arch doesn't identify any of its slices,
// it's user error.
if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin)) {
for (auto &ObjForArch : Universal->objects())
if (Arch == ObjForArch.getArchFlagName())
return false;
return true;
}
return false;
}
Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
BinaryCoverageReader::create(
MemoryBufferRef ObjectBuffer, StringRef Arch,
@ -970,6 +983,10 @@ BinaryCoverageReader::create(
return BinOrErr.takeError();
std::unique_ptr<Binary> Bin = std::move(BinOrErr.get());
if (isArchSpecifierInvalidOrMissing(Bin.get(), Arch))
return make_error<CoverageMapError>(
coveragemap_error::invalid_or_missing_arch_specifier);
// MachO universal binaries which contain archives need to be treated as
// archives, not as regular binaries.
if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin.get())) {

View File

@ -10,8 +10,9 @@ int main(int argc, const char *argv[]) {}
// COMBINED: showTemplateInstantiations.cpp
// COMBINED-NEXT: universal-binary.c
// RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -path-equivalence=/tmp,%S %s 2>&1 | FileCheck --check-prefix=WRONG-ARCH %s
// RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -path-equivalence=/tmp,%S %s -arch i386 2>&1 | FileCheck --check-prefix=WRONG-ARCH %s
// WRONG-ARCH: Failed to load coverage
// WRONG-ARCH: Failed to load coverage: `-arch` specifier is invalid or missing for universal binary
// RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -path-equivalence=/tmp,%S %s -arch definitly_a_made_up_architecture 2>&1 | FileCheck --check-prefix=MADE-UP-ARCH %s
// MADE-UP-ARCH: Unknown architecture: definitly_a_made_up_architecture