Skip to content

Commit 95f4b2a

Browse files
[GSYM] Fix the initialization of DataExtractor (#67904)
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.
1 parent 0ef990d commit 95f4b2a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

llvm/lib/DebugInfo/GSYM/GsymReader.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ llvm::Expected<FunctionInfo> GsymReader::getFunctionInfo(uint64_t Addr) const {
261261
// Address info offsets size should have been checked in parse().
262262
assert(*AddressIndex < AddrInfoOffsets.size());
263263
auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
264-
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset), Endian, 4);
264+
assert((Endian == support::big || Endian == support::little) &&
265+
"Endian must be either big or little");
266+
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset),
267+
Endian == support::little, 4);
265268
if (std::optional<uint64_t> OptAddr = getAddress(*AddressIndex)) {
266269
auto ExpectedFI = FunctionInfo::decode(Data, *OptAddr);
267270
if (ExpectedFI) {
@@ -283,7 +286,10 @@ llvm::Expected<LookupResult> GsymReader::lookup(uint64_t Addr) const {
283286
// Address info offsets size should have been checked in parse().
284287
assert(*AddressIndex < AddrInfoOffsets.size());
285288
auto AddrInfoOffset = AddrInfoOffsets[*AddressIndex];
286-
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset), Endian, 4);
289+
assert((Endian == support::big || Endian == support::little) &&
290+
"Endian must be either big or little");
291+
DataExtractor Data(MemBuffer->getBuffer().substr(AddrInfoOffset),
292+
Endian == support::little, 4);
287293
if (std::optional<uint64_t> OptAddr = getAddress(*AddressIndex))
288294
return FunctionInfo::lookup(Data, *this, *OptAddr, Addr);
289295
return createStringError(std::errc::invalid_argument,

0 commit comments

Comments
 (0)