Weak symbols are not well supported by the PE format, so disable them. We need to manually ensure that only one function is present in the source code.
Add a Kconfig option to control this and enable it when building for Windows. Signed-off-by: Simon Glass <s...@chromium.org> --- Kconfig | 15 +++++++++++++++ include/linux/compiler_attributes.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/Kconfig b/Kconfig index f24e4f0a331e..ca1402d09d10 100644 --- a/Kconfig +++ b/Kconfig @@ -72,6 +72,21 @@ config CLANG_VERSION int default $(shell,$(srctree)/scripts/clang-version.sh $(CC)) +config CC_IS_MSYS + def_bool $(success,uname -o | grep -q Msys) + +config WEAK_SYMBOLS + bool "Enable use of weak symbols" + default y if !CC_IS_MSYS + help + The Portable Executable (PE) format used by Windows does not support + weak symbols very well. Even where it can be made to work, the __weak + function attribute cannot be made to work with PE. Supporting weak + symbols would involve changing the source code in undesirable ways. + + This option controls whether weak symbols are used, or not. When + disabled, the __weak function attribute does nothing. + choice prompt "Optimization level" default CC_OPTIMIZE_FOR_SIZE diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 44c9a08d7346..c954109a065b 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -268,6 +268,10 @@ * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-weak-variable-attribute */ +#ifdef CONFIG_WEAK_SYMBOLS #define __weak __attribute__((__weak__)) +#else +#define __weak +#endif #endif /* __LINUX_COMPILER_ATTRIBUTES_H */ -- 2.40.0.634.g4ca3ef3211-goog