From b08ebff31f1e3a64ae4c537c3acc40dde7a83976 Mon Sep 17 00:00:00 2001 From: Ozan Tezcan Date: Thu, 6 Oct 2022 11:26:19 +0300 Subject: [PATCH] Pass -flto flag to the linker (#11350) Currently, we add -flto to the compile flags only. We are supposed to add it to the linker flags as well. Clang build fails because of this. Added a change to add -flto to REDIS_CFLAGS and REDIS_LDFLAGS if the build optimization flag is -O3. (noopt build will not use -flto) --- src/Makefile | 6 +++++- src/quicklist.c | 6 +++--- src/t_zset.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index a966d001a..2ffddef1b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,7 +15,11 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') -OPTIMIZATION?=-O3 -flto +OPTIMIZATION?=-O3 +ifeq ($(OPTIMIZATION),-O3) + REDIS_CFLAGS+=-flto + REDIS_LDFLAGS+=-flto +endif DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram NODEPS:=clean distclean diff --git a/src/quicklist.c b/src/quicklist.c index e82d8551e..69438165b 100644 --- a/src/quicklist.c +++ b/src/quicklist.c @@ -1573,9 +1573,9 @@ REDIS_STATIC void *_quicklistSaver(unsigned char *data, size_t sz) { * Returns malloc'd value from quicklist */ int quicklistPop(quicklist *quicklist, int where, unsigned char **data, size_t *sz, long long *slong) { - unsigned char *vstr; - size_t vlen; - long long vlong; + unsigned char *vstr = NULL; + size_t vlen = 0; + long long vlong = 0; if (quicklist->count == 0) return 0; int ret = quicklistPopCustom(quicklist, where, &vstr, &vlen, &vlong, diff --git a/src/t_zset.c b/src/t_zset.c index 34f8fb74b..4016fc925 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -1028,7 +1028,7 @@ unsigned char *zzlDelete(unsigned char *zl, unsigned char *eptr) { unsigned char *zzlInsertAt(unsigned char *zl, unsigned char *eptr, sds ele, double score) { unsigned char *sptr; char scorebuf[MAX_D2STRING_CHARS]; - int scorelen; + int scorelen = 0; long long lscore; int score_is_long = double2ll(score, &lscore); if (!score_is_long)