[llvm] r341236 - [XRay] Change function record reader to be endian-aware

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 11:36:59 PDT 2018


Author: dberris
Date: Fri Aug 31 11:36:58 2018
New Revision: 341236

URL: http://llvm.org/viewvc/llvm-project?rev=341236&view=rev
Log:
[XRay] Change function record reader to be endian-aware

This change allows us to let the compiler do the right thing for when
handling big-endian and little-endian records for FDR mode function
records.

Previously, we assumed that the encoding was little-endian that reading
the first byte to look for the function id and function record types was
ordered in a little-endian manner. This change allows us to better
handle function records where the first four bytes may actually be
encoded in big-endian thus giving us the wrong bytes where we're seeking
the function information from.

This is a follow-up to D51210 and D51289.

Modified:
    llvm/trunk/lib/XRay/Trace.cpp

Modified: llvm/trunk/lib/XRay/Trace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/Trace.cpp?rev=341236&r1=341235&r2=341236&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/Trace.cpp (original)
+++ llvm/trunk/lib/XRay/Trace.cpp Fri Aug 31 11:36:58 2018
@@ -601,6 +601,19 @@ Error processFDRFunctionRecord(FDRState
     Records.emplace_back();
     auto &Record = Records.back();
     Record.RecordType = 0; // Record is type NORMAL.
+    // Back up one byte to re-read the first byte, which is important for
+    // computing the function id for a record.
+    --OffsetPtr;
+
+    auto PreReadOffset = OffsetPtr;
+    uint32_t FuncIdBitField = RecordExtractor.getU32(&OffsetPtr);
+    if (OffsetPtr == PreReadOffset)
+      return createStringError(
+          std::make_error_code(std::errc::executable_format_error),
+          "Failed reading truncated function id field at offset %d.",
+          OffsetPtr);
+
+    FirstByte = FuncIdBitField & 0xffu;
     // Strip off record type bit and use the next three bits.
     auto T = (FirstByte >> 1) & 0x07;
     switch (T) {
@@ -626,23 +639,11 @@ Error processFDRFunctionRecord(FDRState
     Record.TId = State.ThreadId;
     Record.PId = State.ProcessId;
 
-    // Back up one byte to re-read the first byte, which is important for
-    // computing the function id for a record.
-    --OffsetPtr;
-
     // Despite function Id being a signed int on XRayRecord,
     // when it is written to an FDR format, the top bits are truncated,
     // so it is effectively an unsigned value. When we shift off the
     // top four bits, we want the shift to be logical, so we read as
     // uint32_t.
-    auto PreReadOffset = OffsetPtr;
-    uint32_t FuncIdBitField = RecordExtractor.getU32(&OffsetPtr);
-    if (OffsetPtr == PreReadOffset)
-      return createStringError(
-          std::make_error_code(std::errc::executable_format_error),
-          "Failed reading truncated function id field at offset %d.",
-          OffsetPtr);
-
     Record.FuncId = FuncIdBitField >> 4;
 
     // FunctionRecords have a 32 bit delta from the previous absolute TSC




More information about the llvm-commits mailing list