coreboot-kgpe-d16/tests
Julius Werner ab91407735 tests: Fix function mocking for clang
clang seems to like to do some aggressive optimizations that break our
approach of mocking functions for test by using objcopy to turn them
weak after the fact on individual compiled object files. For example, in
CB:56601 the function cbfs_get_boot_device() is mocked this way. When
compiling the cbfs_boot_lookup() function in src/lib/cbfs.c with clang,
it will generate a normal callq instruction to a relocation for
cbfs_boot_lookup(), which can then later be pointed to the mocked
version of that function. However, it will also somehow infer that the
version of cbfs_boot_lookup() in that file can only ever return a
pointer to the static local `ro` variable (because CONFIG_VBOOT is
disabled in the environment for that particular test), and instead
generate instructions that directly load the address of a relocation for
that variable into %rdi for the following call to cbfs_lookup(), rather
than using the real function return value. (Why it would do that is
anyone's guess because this seems unlikely to be faster than just moving
the function return value from %rax into %rdi like a normal compiler.)

Long story short, this optimization breaks our tests because
cbfs_lookup() will be called with the wrong pointer. clang doesn't
provide many options to disable individual optimizations, so the only
solution seems to be to make clang aware that the function is weak
during the compilation stage already, so it can be aware that it may get
replaced. This patch implements that by marking the mocked functions
weak via #pragma weak lines in the per-test autogenerated config header.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I1f9011f444248544de7a71bbefc54edc006ae0cd
Reviewed-on: https://review.coreboot.org/c/coreboot/+/57009
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
2021-08-25 20:54:16 +00:00
..
acpi tests: Add acpi/acpigen-test test case 2021-02-23 17:10:10 +00:00
commonlib helpers: Add GENMASK macro 2021-08-02 15:01:54 +00:00
console src/console/init.c: Make get_log_level static inline again 2021-06-15 16:12:52 +00:00
device tests: Rework mocking facility 2021-06-10 19:26:46 +00:00
include tests: Add lib/spd_cache-test test case 2021-05-14 08:59:29 +00:00
lib tests/Makefile.inc: Add missing include paths to TEST_CFLAGS 2021-08-13 18:05:55 +00:00
stubs Rename do_printk() to printk() 2021-04-14 10:38:09 +00:00
Makefile.inc tests: Fix function mocking for clang 2021-08-25 20:54:16 +00:00