[PATCH 24/31] build: Disable weak symbols for MSYS2

Simon Glass sjg at chromium.org
Sat Apr 29 20:41:51 CEST 2023


Hi Pali,

On Tue, 25 Apr 2023 at 10:21, Pali Rohár <pali at kernel.org> wrote:
>
> On Monday 24 April 2023 17:08:29 Simon Glass wrote:
> > Weak symbols are not well supported by the PE format, so disable them.
>
> They are supported by PE format. This is likely issue of (older)
> toolchain. What about rather requiring better toolchain version and
> fix special cases of weak functions do not work correctly?

What compiler are you using? How do weak symbols work in that compiler?

I am using:

$ gcc -v

Using built-in specs.

COLLECT_GCC=gcc

COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/11.3.0/lto-wrapper.exe

Target: x86_64-pc-msys

Configured with: /c/S/gcc/src/gcc-11.3.0/configure
--build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib
--enable-bootstrap --enable-shared --enable-shared-libgcc
--enable-static --enable-version-specific-runtime-libs
--with-arch=x86-64 --with-tune=generic --disable-multilib
--enable-__cxa_atexit --with-dwarf2
--enable-languages=c,c++,fortran,lto --enable-graphite
--enable-threads=posix --enable-libatomic --enable-libgomp
--disable-libitm --enable-libquadmath --enable-libquadmath-support
--disable-libssp --disable-win32-registry --disable-symvers
--with-gnu-ld --with-gnu-as --disable-isl-version-check
--enable-checking=release --without-libiconv-prefix
--without-libintl-prefix --with-system-zlib --enable-linker-build-id
--with-default-libstdcxx-abi=gcc4-compatible
--enable-libstdcxx-filesystem-ts

Thread model: posix

Supported LTO compression algorithms: zlib

gcc version 11.3.0 (GCC)


sglass at DESKTOP-OHNGJ4K MINGW64 ~/u-boot

$ ld -v

GNU ld (GNU Binutils) 2.40

Regards,
Simon


>
> > 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>
> > ---
> >
> >  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
> >


More information about the U-Boot mailing list