Skip to content

Commit

Permalink
[GSYM] Fix the initialization of DataExtractor (#67904)
Browse files Browse the repository at this point in the history
Without this patch, we pass Endian as one of the parameters to the
constructor of DataExtractor.  The problem is that Endian is of:

  enum endianness {big, little, native};

whereas the constructor is expecting "bool IsLittleEndian".  That is,
we are relying on an implicit conversion to convert big and little to
false and true, respectively.

When we migrate llvm::support::endianness to std::endian in future, we
can no longer rely on an implicit conversion because std::endian is
declared with "enum class".  Even if we could, the conversion would
not be guaranteed to work because, for example, libcxx defines:

  enum class endian {
    little = 0xDEAD,
    big = 0xFACE,
    :

where big and little are not boolean values.

This patch fixes the problem by properly converting Endian to a
boolean value.
  • Loading branch information
kazutakahirata authored Oct 1, 2023
1 parent 0ef990d commit 95f4b2a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions llvm/lib/DebugInfo/GSYM/GsymReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ llvm::Expected<FunctionInfo> GsymReader::getFunctionInfo(uint64_t Addr) const {
// Address info offsets size should have been checked in parse().
assert(*AddressIndex < AddrInfoOffsets.size());
auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset), Endian, 4);
assert((Endian == support::big || Endian == support::little) &&
"Endian must be either big or little");
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset),
Endian == support::little, 4);
if (std::optional<uint64_t> OptAddr = getAddress(*AddressIndex)) {
auto ExpectedFI = FunctionInfo::decode(Data, *OptAddr);
if (ExpectedFI) {
Expand All @@ -283,7 +286,10 @@ llvm::Expected<LookupResult> GsymReader::lookup(uint64_t Addr) const {
// Address info offsets size should have been checked in parse().
assert(*AddressIndex < AddrInfoOffsets.size());
auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset), Endian, 4);
assert((Endian == support::big || Endian == support::little) &&
"Endian must be either big or little");
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset),
Endian == support::little, 4);
if (std::optional<uint64_t> OptAddr = getAddress(*AddressIndex))
return FunctionInfo::lookup(Data, *this, *OptAddr, Addr);
return createStringError(std::errc::invalid_argument,
Expand Down

0 comments on commit 95f4b2a

Please sign in to comment.