Undefined symbols when compiling drivers: cpufreq_get etc. (solved by disabling CONFIG_TRIM_UNUSED_KSYMS)

In case somebody else hits the same problem:
Starting with kernel 5.12, I wasn’t able to install NVIDIA drivers anymore. Installing failed with lots of undefined symbols, e.g. "ERROR: modpost: “pm_vt_switch_unregister” undefined!

I did pretty intensive research and found out that setting kernel option CONFIG_TRIM_UNUSED_KSYMS caused the trouble. After disabling, driver compilation worked fine again.