[PATCH v2 26/30] build: Disable weak symbols for MSYS2
Simon Glass
sjg at chromium.org
Sun Apr 30 03:29:59 CEST 2023
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 <sjg at chromium.org>
---
(no changes since v1)
Kconfig | 12 ++++++++++++
include/linux/compiler_attributes.h | 4 ++++
2 files changed, 16 insertions(+)
diff --git a/Kconfig b/Kconfig
index 9ac816abef1c..985b09680934 100644
--- a/Kconfig
+++ b/Kconfig
@@ -75,6 +75,18 @@ config CLANG_VERSION
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.1.495.gc816e09b53d-goog
More information about the U-Boot
mailing list