tpm2: add support for LTO and partial link with gcc 11.2

gcc 11.2 changes default linker behavior and doesn't terminate LTO build
when partial link is used as gcc 8.3 does. We need to pass compiler
flag -flinker-output=nolto-rel to make this happen. However, this flag
is not supported by gcc 8.3. To overcome this we expect the higher level
makefile to set a variable CFLAGS_LTO_PARTIAL_LINK to this option when
compiling with gcc 11.2. Otherwise this variable will be empty and have
zero effect.

BUG=none
TEST=make BOARD=cr50 works

Cq-Depend: chromium:3218577
Change-Id: I17cdec08bd2a1c0fd36822bef5c19aa812c763d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/tpm2/+/3218665
Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
diff --git a/Makefile b/Makefile
index 82a828e..b31786b 100644
--- a/Makefile
+++ b/Makefile
@@ -349,7 +349,8 @@
 
 $(obj)/linkedtpm2.o: $(OBJS)
 	@echo "  LTO     $(notdir $@)"
-	$(Q)$(CC) $(CFLAGS) --static -Wl,--relocatable $^ -o $@
+	$(Q)$(CC) $(CFLAGS) $(CFLAGS_LTO_PARTIAL_LINK)\
+		  --static -Wl,--relocatable $^ -o $@
 
 # A helper target allowing the Cr50 Makefile to determine the exact list of
 # the updated object files to link in.