Skip to content

Commit

Permalink
Fix link-time optimization to work correctly for unit tests (i.e. -fl…
Browse files Browse the repository at this point in the history
…to flag) (#1290)

* We compile various c files into object and package them into library
  (.a file) using ar to feed to unit tests. With new GCC versions, the
  objects inside such library don't participate in LTO process without
  additional flags.
* Here is a direct quote from gcc documentation explaining this issue:
  "If you are not using a linker with plugin support and/or do not
  enable the linker plugin, then the objects inside libfoo.a are extracted
  and linked as usual, but they do not participate in the LTO optimization
  process. In order to make a static library suitable for both LTO
  optimization and usual linkage, compile its object files with -flto-ffat-lto-objects."
* Read full documentation about -flto at https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
* Without this additional flag, I get following errors while executing
  "make test-unit". With this change, those errors go away.

```
ARCHIVE libvalkey.a
ar: threads_mngr.o: plugin needed to handle lto object
...
..
.
/tmp/ccDYbMXL.ltrans0.ltrans.o: In function `dictClear':
/local/workplace/elasticache/valkey/src/unit/../dict.c:776: undefined
reference to `valkey_free'
/local/workplace/elasticache/valkey/src/unit/../dict.c:770: undefined
reference to `valkey_free'
/tmp/ccDYbMXL.ltrans0.ltrans.o: In function `dictGetVal':
```

Signed-off-by: Parth Patel <[email protected]>
  • Loading branch information
parthpatel committed Nov 13, 2024
1 parent 2df56d8 commit b7a0b29
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ifeq ($(OPTIMIZATION),-O3)
else
OPTIMIZATION+=-flto=auto
endif
OPTIMIZATION += -ffat-lto-objects
endif
ifneq ($(OPTIMIZATION),-O0)
OPTIMIZATION+=-fno-omit-frame-pointer
Expand Down

0 comments on commit b7a0b29

Please sign in to comment.