Skip to content

Commit 71b27e9

Browse files
authored
fix: Add option to disable stacktrace feature (#3345)
1 parent 36932b2 commit 71b27e9

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ option(S2N_INTERN_LIBCRYPTO "This ensures that s2n-tls is compiled and deployed
2727
version of libcrypto by interning the code and hiding symbols. This also enables s2n-tls to be
2828
loaded in an application with an otherwise conflicting libcrypto version." OFF)
2929
option(S2N_LTO, "Enables link time optimizations when building s2n-tls." OFF)
30+
option(S2N_STACKTRACE "Enables stacktrace functionality in s2n-tls." ON)
31+
3032
# Turn BUILD_TESTING=ON by default
3133
include(CTest)
3234

@@ -434,8 +436,10 @@ if(ADX_SUPPORTED)
434436
message(STATUS "Support for ADX assembly instructions detected")
435437
endif()
436438

437-
if(S2N_HAVE_EXECINFO)
438-
target_compile_options(${PROJECT_NAME} PUBLIC -DS2N_HAVE_EXECINFO)
439+
if(S2N_HAVE_EXECINFO AND S2N_STACKTRACE)
440+
target_compile_options(${PROJECT_NAME} PUBLIC -DS2N_STACKTRACE)
441+
else()
442+
message(STATUS "Disabling stacktrace functionality")
439443
endif()
440444

441445
if(S2N_CPUID_AVAILABLE)

error/s2n_errno.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "utils/s2n_map.h"
2525
#include "utils/s2n_safety.h"
2626

27-
#if S2N_HAVE_EXECINFO
27+
#ifdef S2N_STACKTRACE
2828
# include <execinfo.h>
2929
#endif
3030

@@ -367,7 +367,7 @@ int s2n_stack_traces_enabled_set(bool newval)
367367
return S2N_SUCCESS;
368368
}
369369

370-
#ifdef S2N_HAVE_EXECINFO
370+
#ifdef S2N_STACKTRACE
371371

372372
#define MAX_BACKTRACE_DEPTH 20
373373
__thread struct s2n_stacktrace tl_stacktrace = {0};
@@ -418,7 +418,7 @@ int s2n_print_stacktrace(FILE *fptr)
418418
return S2N_SUCCESS;
419419
}
420420

421-
#else /* !S2N_HAVE_EXECINFO */
421+
#else /* !S2N_STACKTRACE */
422422
int s2n_free_stacktrace(void)
423423
{
424424
S2N_ERROR(S2N_ERR_UNIMPLEMENTED);
@@ -443,4 +443,4 @@ int s2n_print_stacktrace(FILE *fptr)
443443
{
444444
S2N_ERROR(S2N_ERR_UNIMPLEMENTED);
445445
}
446-
#endif /* S2N_HAVE_EXECINFO */
446+
#endif /* S2N_STACKTRACE */

s2n.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ try_compile = $(shell $(CC) $(CFLAGS) -c -o tmp.o $(1) > /dev/null 2>&1; echo $$
186186
# Determine if execinfo.h is available
187187
TRY_COMPILE_EXECINFO := $(call try_compile,$(S2N_ROOT)/tests/features/execinfo.c)
188188
ifeq ($(TRY_COMPILE_EXECINFO), 0)
189-
DEFAULT_CFLAGS += -DS2N_HAVE_EXECINFO
189+
DEFAULT_CFLAGS += -DS2N_STACKTRACE
190190
endif
191191

192192
# Determine if cpuid.h is available

tests/unit/s2n_stacktrace_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main(int argc, char **argv)
2828
{
2929
BEGIN_TEST();
3030
EXPECT_SUCCESS(s2n_disable_tls13_in_test());
31-
#ifdef S2N_HAVE_EXECINFO
31+
#ifdef S2N_STACKTRACE
3232
EXPECT_SUCCESS(s2n_stack_traces_enabled_set(true));
3333
struct s2n_stacktrace trace;
3434
/* If nothing has errored yet, we have no stacktrace */

0 commit comments

Comments
 (0)