Skip to content

Commit eb5d607

Browse files
gleocadieveerbia
authored andcommitted
[Profiler] Fix UBsan Job (#6380)
## Summary of changes Fix the UBSAN job. ## Reason for change A recent unit test was added. This test builds events by writing the field in raw memory (like the CLR does). But the alignment is not taken care of (like the CLR) and UBSAN shouts about. ## Implementation details Since it's a test, we just disable UBSAN on the function (in the test) that creates the event.
1 parent cee4e6b commit eb5d607

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

profiler/src/ProfilerEngine/Datadog.Profiler.Native/Log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ class Log final
7676
static std::once_flag UNIQUE_ONCE_FLAG_##__COUNTER__; \
7777
std::call_once( \
7878
UNIQUE_ONCE_FLAG_##__COUNTER__, [](auto&&... args) { Log::level(std::forward<decltype(args)>(args)...); }, __VA_ARGS__); \
79-
} while (0)
79+
} while (0) // NOLINT

profiler/test/Datadog.Profiler.Native.Tests/ClrEventsParserTest.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ TEST(ClrEventsParserTest, ContentionStartV2)
107107
parser.ParseEvent(1234ns, 2, KEYWORD_CONTENTION, EVENT_CONTENTION_START, sizeof(ContentionStartV2Payload), reinterpret_cast<LPCBYTE>(&payload));
108108
}
109109

110+
// The CLR sends events with misalign field.
111+
// In this case, since we create an event, it's ok to disregard the misalign issue
112+
// reported by UBSAN
110113
template <typename T>
111114
uint64_t Write(std::uint8_t* buffer, std::uint64_t offset, T const& value)
115+
#ifdef LINUX
116+
__attribute__((no_sanitize("alignment")))
117+
#endif
112118
{
113119
*reinterpret_cast<T*>(buffer + offset) = value;
114120
return offset + sizeof(T);

0 commit comments

Comments
 (0)