Skip to content

Commit 6cee3c2

Browse files
committed
[trace] Remove default definitions of weak symbols
Instead of providing a default no-op implementation, check the symbols for `NULL` before accessing them. Providing a default implementation doesn't reliably work with dynamic linking. Depending on link order the default implementations may not be overridden. By skipping the default implementation, all link order issues are resolved. If the symbols aren't provided the weak function will be `NULL`.
1 parent 3e2fbfd commit 6cee3c2

File tree

5 files changed

+11
-52
lines changed

5 files changed

+11
-52
lines changed

build/meson/lib/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'),
2222
join_paths(zstd_rootdir, 'lib/common/threading.c'),
2323
join_paths(zstd_rootdir, 'lib/common/pool.c'),
2424
join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
25-
join_paths(zstd_rootdir, 'lib/common/zstd_trace.c'),
2625
join_paths(zstd_rootdir, 'lib/common/error_private.c'),
2726
join_paths(zstd_rootdir, 'lib/common/xxhash.c'),
2827
join_paths(zstd_rootdir, 'lib/compress/hist.c'),

lib/common/zstd_trace.c

Lines changed: 0 additions & 42 deletions
This file was deleted.

lib/common/zstd_trace.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ typedef unsigned long long ZSTD_TraceCtx;
114114
* @returns Non-zero if tracing is enabled. The return value is
115115
* passed to ZSTD_trace_compress_end().
116116
*/
117-
ZSTD_TraceCtx ZSTD_trace_compress_begin(struct ZSTD_CCtx_s const* cctx);
117+
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(
118+
struct ZSTD_CCtx_s const* cctx);
118119

119120
/**
120121
* Trace the end of a compression call.
121122
* @param ctx The return value of ZSTD_trace_compress_begin().
122123
* @param trace The zstd tracing info.
123124
*/
124-
void ZSTD_trace_compress_end(
125+
ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(
125126
ZSTD_TraceCtx ctx,
126127
ZSTD_Trace const* trace);
127128

@@ -132,14 +133,15 @@ void ZSTD_trace_compress_end(
132133
* @returns Non-zero if tracing is enabled. The return value is
133134
* passed to ZSTD_trace_compress_end().
134135
*/
135-
ZSTD_TraceCtx ZSTD_trace_decompress_begin(struct ZSTD_DCtx_s const* dctx);
136+
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(
137+
struct ZSTD_DCtx_s const* dctx);
136138

137139
/**
138140
* Trace the end of a decompression call.
139141
* @param ctx The return value of ZSTD_trace_decompress_begin().
140142
* @param trace The zstd tracing info.
141143
*/
142-
void ZSTD_trace_decompress_end(
144+
ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(
143145
ZSTD_TraceCtx ctx,
144146
ZSTD_Trace const* trace);
145147

lib/compress/zstd_compress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,7 +4379,7 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
43794379
ZSTD_buffered_policy_e zbuff)
43804380
{
43814381
#if ZSTD_TRACE
4382-
cctx->traceCtx = ZSTD_trace_compress_begin(cctx);
4382+
cctx->traceCtx = (ZSTD_trace_compress_begin != NULL) ? ZSTD_trace_compress_begin(cctx) : 0;
43834383
#endif
43844384
DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params->cParams.windowLog);
43854385
/* params are supposed to be fully validated at this point */
@@ -4510,7 +4510,7 @@ static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity)
45104510
void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize)
45114511
{
45124512
#if ZSTD_TRACE
4513-
if (cctx->traceCtx) {
4513+
if (cctx->traceCtx && ZSTD_trace_compress_end != NULL) {
45144514
int const streaming = cctx->inBuffSize > 0 || cctx->outBuffSize > 0 || cctx->appliedParams.nbWorkers > 0;
45154515
ZSTD_Trace trace;
45164516
ZSTD_memset(&trace, 0, sizeof(trace));
@@ -5456,7 +5456,7 @@ static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx,
54565456
}
54575457
if (params.nbWorkers > 0) {
54585458
#if ZSTD_TRACE
5459-
cctx->traceCtx = ZSTD_trace_compress_begin(cctx);
5459+
cctx->traceCtx = (ZSTD_trace_compress_begin != NULL) ? ZSTD_trace_compress_begin(cctx) : 0;
54605460
#endif
54615461
/* mt context creation */
54625462
if (cctx->mtctx == NULL) {

lib/decompress/zstd_decompress.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static size_t ZSTD_setRleBlock(void* dst, size_t dstCapacity,
788788
static void ZSTD_DCtx_trace_end(ZSTD_DCtx const* dctx, U64 uncompressedSize, U64 compressedSize, unsigned streaming)
789789
{
790790
#if ZSTD_TRACE
791-
if (dctx->traceCtx) {
791+
if (dctx->traceCtx && ZSTD_trace_decompress_end != NULL) {
792792
ZSTD_Trace trace;
793793
ZSTD_memset(&trace, 0, sizeof(trace));
794794
trace.version = ZSTD_VERSION_NUMBER;
@@ -1383,7 +1383,7 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx)
13831383
{
13841384
assert(dctx != NULL);
13851385
#if ZSTD_TRACE
1386-
dctx->traceCtx = ZSTD_trace_decompress_begin(dctx);
1386+
dctx->traceCtx = (ZSTD_trace_decompress_begin != NULL) ? ZSTD_trace_decompress_begin(dctx) : 0;
13871387
#endif
13881388
dctx->expected = ZSTD_startingInputLength(dctx->format); /* dctx->format must be properly set */
13891389
dctx->stage = ZSTDds_getFrameHeaderSize;

0 commit comments

Comments
 (0)