libpayload: Protect against trying to use weak symbols in the wrong way
Weak symbols don't work as expected when you try to override them from within the same static library. Static libraries are just archives of individual objects, and when the linker tries to resolve a symbol against it it simply uses the implementation from the first object that has one, weak or not. It does not search through all remaining objects to see if there's also a strong implementation. We've had multiple cases in libpayload where builds were incorrectly using the default implementation rather than an optimized arch-specific implementation for years due to this issue. To prevent it from recurring, this patch adds some postprocessing script to the Makefile that checks for this situation and makes the build fail if it creeps in again. Change-Id: I9fcbc9b873901d126322b12954c349c08300369f Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/87777 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
parent
d27e8ef460
commit
df0221e62a
1 changed files with 8 additions and 0 deletions
|
|
@ -110,6 +110,14 @@ includes-handler= \
|
|||
$(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs))
|
||||
printf " AR $(subst $(CURDIR)/,,$(@))\n"
|
||||
printf "create $@\n$(foreach objc,$(filter-out %.a,$^),addmod $(objc)\n)$(foreach lib,$(filter %.a,$^),addlib $(lib)\n)save\nend\n" | $(AR) -M
|
||||
for func in $$(nm $@ | awk '/ (w|W) / { print $$NF }'); do \
|
||||
if nm --no-weak --defined-only $@ | grep -Eq " $$func$$"; then \
|
||||
printf "\nERROR: Function '$$func' appears as both weak and strong symbol in libpayload.\n"; \
|
||||
printf " Weak symbol overrides don't work reliably from within the same library.\n\n"; \
|
||||
rm $@; \
|
||||
exit 1; \
|
||||
fi \
|
||||
done
|
||||
|
||||
$(obj)/%.a: $$(%-objs)
|
||||
printf " AR $(subst $(CURDIR)/,,$(@))\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue