From 1da2dcf30d8172e424d57a01a2c24f84df8ea719 Mon Sep 17 00:00:00 2001 From: Nick Richardson Date: Fri, 10 Feb 2023 09:22:13 -0800 Subject: [PATCH] Fix "symbol in discarded section" linker error for bpf probes Summary: Fixes gnu ld linker error where the nop code point injected by a bpf probe was being discarded at linking time. The bpf probe would add reference from the .notes section to this discared func location and a "(...) defined in discarded section (...) referenced in section .note.stapsdt" error would occur. Previously tracked by github issue: (https://github.com/facebookincubator/fizz/issues/84) Reviewed By: mingtaoy Differential Revision: D42998995 fbshipit-source-id: a2d1eb0c98823fc90b9886b98e7e5e671362af63 --- fizz/CMakeLists.txt | 1 + fizz/client/AsyncFizzClient-inl.h | 12 +++++------- fizz/client/AsyncFizzClient.h | 2 +- fizz/server/AsyncFizzServer-inl.h | 7 ++----- fizz/server/AsyncFizzServer.h | 3 +-- fizz/util/Tracing.cpp | 21 +++++++++++++++++++++ fizz/util/Tracing.h | 22 ++++++++++++++++++++++ 7 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 fizz/util/Tracing.cpp create mode 100644 fizz/util/Tracing.h diff --git a/fizz/CMakeLists.txt b/fizz/CMakeLists.txt index 5c8a575bf05..21179a35898 100644 --- a/fizz/CMakeLists.txt +++ b/fizz/CMakeLists.txt @@ -218,6 +218,7 @@ set(FIZZ_SOURCES client/EarlyDataRejectionPolicy.cpp tool/FizzCommandCommon.cpp util/FizzUtil.cpp + util/Tracing.cpp ) add_library(fizz diff --git a/fizz/client/AsyncFizzClient-inl.h b/fizz/client/AsyncFizzClient-inl.h index d1dc6d803fc..75301a22432 100644 --- a/fizz/client/AsyncFizzClient-inl.h +++ b/fizz/client/AsyncFizzClient-inl.h @@ -608,16 +608,14 @@ void AsyncFizzClientT::ActionMoveVisitor::operator()( template void AsyncFizzClientT::ActionMoveVisitor::operator()( SecretAvailable& secret) { - client_.secretAvailable(secret.secret); -#if 0 - FOLLY_SDT( - fizz, - fizz_secret_available, + fizz_probe_secret_available( secret.secret.secret.size(), secret.secret.secret.data(), - secret.secret.type, + KeyLogWriter::secretToNSSLabel(secret.secret.type) + .value_or(std::numeric_limits::max()), client_.getClientRandom()->data()); -#endif + + client_.secretAvailable(secret.secret); } template diff --git a/fizz/client/AsyncFizzClient.h b/fizz/client/AsyncFizzClient.h index fae048c9c61..f113a40576a 100644 --- a/fizz/client/AsyncFizzClient.h +++ b/fizz/client/AsyncFizzClient.h @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include namespace fizz { namespace client { diff --git a/fizz/server/AsyncFizzServer-inl.h b/fizz/server/AsyncFizzServer-inl.h index d3f3d13b1a5..86666e6c4dc 100644 --- a/fizz/server/AsyncFizzServer-inl.h +++ b/fizz/server/AsyncFizzServer-inl.h @@ -343,16 +343,13 @@ void AsyncFizzServerT::ActionMoveVisitor::operator()( template void AsyncFizzServerT::ActionMoveVisitor::operator()( SecretAvailable& secret) { -#if 0 - FOLLY_SDT( - fizz, - fizz_secret_available, + fizz_probe_secret_available( secret.secret.secret.size(), secret.secret.secret.data(), KeyLogWriter::secretToNSSLabel(secret.secret.type) .value_or(std::numeric_limits::max()), server_.getClientRandom()->data()); -#endif + server_.secretAvailable(secret.secret); } diff --git a/fizz/server/AsyncFizzServer.h b/fizz/server/AsyncFizzServer.h index a63426ba6a9..0ea9b57f0b5 100644 --- a/fizz/server/AsyncFizzServer.h +++ b/fizz/server/AsyncFizzServer.h @@ -13,8 +13,7 @@ #include #include #include -#include -#include +#include namespace fizz { namespace server { diff --git a/fizz/util/Tracing.cpp b/fizz/util/Tracing.cpp new file mode 100644 index 00000000000..fd22535d6fa --- /dev/null +++ b/fizz/util/Tracing.cpp @@ -0,0 +1,21 @@ +#include +#include + +namespace fizz { +extern "C" { +void fizz_probe_secret_available( + long unsigned int secretSize, + unsigned char* secretData, + fizz::KeyLogWriter::Label nssLabel, + unsigned char* clientRandom) { + FOLLY_SDT( + fizz, + fizz_secret_available, + secretSize, + secretData, + nssLabel, + clientRandom); +} +} + +} // namespace fizz diff --git a/fizz/util/Tracing.h b/fizz/util/Tracing.h new file mode 100644 index 00000000000..2275a4cde0b --- /dev/null +++ b/fizz/util/Tracing.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once +#include + +namespace fizz { + +extern "C" { +void fizz_probe_secret_available( + long unsigned int secretSize, + unsigned char* secretData, + fizz::KeyLogWriter::Label nssLabel, + unsigned char* clientRandom); +} + +} // namespace fizz