Skip to content

Commit 4faef6e

Browse files
committed
Cleanup: Remove IF_VALGRIND
The purpose of the compress() wrapper my_compress_buffer() was twofold: silence Valgrind warnings about uninitialized memory access before zlib 1.2.4, and have PERFORMANCE_SCHEMA instrumentation of some zlib related memory allocation. Because of PERFORMANCE_SCHEMA, we cannot trivially replace my_compress_buffer() with compress(). az_open(): Remove a crc32() call. Any CRC of the empty string is 0.
1 parent 232af0c commit 4faef6e

File tree

5 files changed

+10
-199
lines changed

5 files changed

+10
-199
lines changed

include/my_valgrind.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@
8383
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
8484
#endif /* __has_feature(memory_sanitizer) */
8585

86-
#ifdef HAVE_valgrind
87-
#define IF_VALGRIND(A,B) A
88-
#else
89-
#define IF_VALGRIND(A,B) B
90-
#endif
91-
9286
#ifdef TRASH_FREED_MEMORY
9387
/*
9488
_TRASH_FILL() has to call MEM_MAKE_ADDRESSABLE() to cancel any effect of

mysql-test/valgrind.supp

Lines changed: 1 addition & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) 2005, 2015, Oracle and/or its affiliates.
2-
# Copyright (c) 2008, 2019, MariaDB
2+
# Copyright (c) 2008, 2022, MariaDB
33
#
44
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU Library General Public
@@ -100,137 +100,6 @@
100100
fun:_dl_start
101101
}
102102

103-
#
104-
# Warnings in libz becasue it works with aligned memory(?)
105-
#
106-
107-
{
108-
libz tr_flush_block
109-
Memcheck:Cond
110-
fun:_tr_flush_block
111-
fun:deflate_slow
112-
fun:deflate
113-
fun:do_flush
114-
fun:gzclose
115-
}
116-
117-
{
118-
libz tr_flush_block2
119-
Memcheck:Cond
120-
fun:_tr_flush_block
121-
fun:deflate_slow
122-
fun:deflate
123-
fun:compress2
124-
}
125-
126-
{
127-
libz longest_match
128-
Memcheck:Cond
129-
fun:longest_match
130-
fun:deflate_slow
131-
fun:deflate
132-
fun:do_flush
133-
}
134-
135-
{
136-
libz longest_match called from btr_store_big_rec_extern_fields
137-
Memcheck:Cond
138-
fun:longest_match
139-
fun:deflate_slow
140-
fun:deflate
141-
fun:btr_store_big_rec_extern_fields
142-
}
143-
144-
{
145-
libz longest_match called from page_zip_compress
146-
Memcheck:Cond
147-
fun:longest_match
148-
fun:deflate_slow
149-
fun:deflate
150-
fun:page_zip_compress
151-
}
152-
153-
{
154-
libz longest_match2
155-
Memcheck:Cond
156-
fun:longest_match
157-
fun:deflate_slow
158-
fun:deflate
159-
fun:compress2
160-
}
161-
162-
{
163-
libz longest_match 3
164-
Memcheck:Cond
165-
fun:longest_match
166-
fun:deflate_slow
167-
fun:deflate
168-
fun:gzclose
169-
}
170-
171-
{
172-
libz longest_match 4
173-
Memcheck:Cond
174-
fun:longest_match
175-
fun:deflate_slow
176-
fun:deflate
177-
fun:gzflush
178-
}
179-
180-
{
181-
libz longest_match3
182-
Memcheck:Cond
183-
fun:longest_match
184-
fun:deflate_slow
185-
fun:deflate
186-
fun:azflush
187-
}
188-
189-
{
190-
libz longest_match3
191-
Memcheck:Cond
192-
fun:longest_match
193-
fun:deflate_slow
194-
fun:deflate
195-
fun:azclose
196-
}
197-
198-
{
199-
libz deflate
200-
Memcheck:Cond
201-
obj:*/libz.so.*
202-
obj:*/libz.so.*
203-
fun:deflate
204-
fun:compress2
205-
}
206-
207-
{
208-
libz deflate2
209-
Memcheck:Cond
210-
obj:*/libz.so.*
211-
obj:*/libz.so.*
212-
fun:deflate
213-
obj:*/libz.so.*
214-
fun:gzflush
215-
}
216-
217-
{
218-
libz deflate3
219-
Memcheck:Cond
220-
obj:*/libz.so.*
221-
obj:*/libz.so.*
222-
fun:deflate
223-
fun:do_flush
224-
}
225-
226-
{
227-
libz inflatereset2
228-
Memcheck:Cond
229-
fun:inflateReset2
230-
fun:inflateInit2_
231-
fun:uncompress
232-
}
233-
234103

235104
#
236105
# Warning from my_thread_init becasue mysqld dies before kill thread exists
@@ -705,39 +574,6 @@
705574
fun:buf_buddy_relocate
706575
}
707576

708-
{
709-
Bug 59874 Valgrind warning in InnoDB compression code
710-
Memcheck:Cond
711-
fun:*
712-
fun:*
713-
fun:deflate
714-
fun:btr_store_big_rec_extern_fields_func
715-
fun:row_ins_index_entry_low
716-
fun:row_ins_index_entry
717-
fun:row_ins_index_entry_step
718-
fun:row_ins
719-
fun:row_ins_step
720-
fun:row_insert_for_mysql
721-
}
722-
723-
{
724-
In page0zip.c we have already checked that the memory is initialized before calling deflate()
725-
Memcheck:Cond
726-
fun:*
727-
fun:*
728-
fun:deflate
729-
fun:page_zip_compress
730-
}
731-
732-
{
733-
In page0zip.c we have already checked that the memory is initialized before calling deflate()
734-
Memcheck:Cond
735-
fun:*
736-
fun:*
737-
fun:deflate
738-
fun:page_zip_compress_deflate
739-
}
740-
741577
{
742578
Bug 59875 Valgrind warning in buf0buddy.c
743579
Memcheck:Addr1

mysys/my_compress.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2022, MariaDB Corporation.
23
34
This program is free software; you can redistribute it and/or modify
45
it under the terms of the GNU General Public License as published by
@@ -57,35 +58,11 @@ my_bool my_compress(uchar *packet, size_t *len, size_t *complen)
5758
}
5859

5960

60-
/*
61-
Valgrind normally gives false alarms for zlib operations, in the form of
62-
"conditional jump depends on uninitialised values" etc. The reason is
63-
explained in the zlib FAQ (http://www.zlib.net/zlib_faq.html#faq36):
64-
65-
"That is intentional for performance reasons, and the output of deflate
66-
is not affected."
67-
68-
Also discussed on a blog
69-
(http://www.sirena.org.uk/log/2006/02/19/zlib-generating-valgrind-warnings/):
70-
71-
"...loop unrolling in the zlib library causes the mentioned
72-
“Conditional jump or move depends on uninitialised value(s)”
73-
warnings. These are safe since the results of the comparison are
74-
subsequently ignored..."
75-
76-
"the results of the calculations are discarded by bounds checking done
77-
after the loop exits"
78-
79-
Fix by initializing the memory allocated by zlib when running under Valgrind.
80-
81-
This fix is safe, since such memory is only used internally by zlib, so we
82-
will not hide any bugs in mysql this way.
83-
*/
8461
void *my_az_allocator(void *dummy __attribute__((unused)), unsigned int items,
8562
unsigned int size)
8663
{
8764
return my_malloc(key_memory_my_compress_alloc, (size_t)items*(size_t)size,
88-
IF_VALGRIND(MY_ZEROFILL, MYF(0)));
65+
MYF(0));
8966
}
9067

9168
void my_az_free(void *dummy __attribute__((unused)), void *address)

sql/mysqld.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8706,12 +8706,16 @@ void set_server_version(char *buf, size_t size)
87068706
{
87078707
bool is_log= opt_log || global_system_variables.sql_log_slow || opt_bin_log;
87088708
bool is_debug= IF_DBUG(!strstr(MYSQL_SERVER_SUFFIX_STR, "-debug"), 0);
8709-
bool is_valgrind= IF_VALGRIND(!strstr(MYSQL_SERVER_SUFFIX_STR, "-valgrind"), 0);
8709+
const char *is_valgrind=
8710+
#ifdef HAVE_VALGRIND
8711+
!strstr(MYSQL_SERVER_SUFFIX_STR, "-valgrind") ? "-valgrind" :
8712+
#endif
8713+
"";
87108714
strxnmov(buf, size - 1,
87118715
MYSQL_SERVER_VERSION,
87128716
MYSQL_SERVER_SUFFIX_STR,
87138717
IF_EMBEDDED("-embedded", ""),
8714-
is_valgrind ? "-valgrind" : "",
8718+
is_valgrind,
87158719
is_debug ? "-debug" : "",
87168720
is_log ? "-log" : "",
87178721
NullS);

storage/archive/azio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int az_open (azio_stream *s, const char *path, int Flags, File fd)
7171
s->in = 0;
7272
s->out = 0;
7373
s->back = EOF;
74-
s->crc = crc32(0L, Z_NULL, 0);
74+
s->crc = 0;
7575
s->transparent = 0;
7676
s->mode = 'r';
7777
s->version = (unsigned char)az_magic[1]; /* this needs to be a define to version */

0 commit comments

Comments
 (0)