# Buggy code
def get_build_ext_override():
    """
    Custom build_ext command to tweak extension building.
    """
    from numpy.distutils.command.build_ext import build_ext as old_build_ext

    class build_ext(old_build_ext):
        def build_extension(self, ext):
            # When compiling with GNU compilers, use a version script to
            # hide symbols during linking.
            if self.__is_using_gnu_linker(ext):
                export_symbols = self.get_export_symbols(ext)
                text = "{global: %s; local: *; };" % (";".join(export_symbols),)

                script_fn = os.path.join(
                    self.build_temp, "link-version-{}.map".format(ext.name)
                )
                with open(script_fn, "w") as f:
                    f.write(text)
                    ext.extra_link_args.append("-Wl,--version-script=" + script_fn)

            old_build_ext.build_extension(self, ext)

        def __is_using_gnu_linker(self, ext):
            if not sys.platform.startswith("linux"):
                return False

            # Fortran compilation with gfortran uses it also for
            # linking. For the C compiler, we detect gcc in a similar
            # way as distutils does it in
            # UnixCCompiler.runtime_library_dir_option
            if ext.language == "f90":
                is_gcc = self._f90_compiler.compiler_type in ("gnu", "gnu95")
            elif ext.language == "f77":
                is_gcc = self._f77_compiler.compiler_type in ("gnu", "gnu95")
            else:
                is_gcc = False
                if self.compiler.compiler_type == "unix":
                    cc = sysconfig.get_config_var("CC")
                    if not cc:
                        cc = ""
                    compiler_name = os.path.basename(cc)
                    is_gcc = "gcc" in compiler_name or "g++" in compiler_name
            return is_gcc and sysconfig.get_config_var("GNULD") == "yes"

    return build_ext


# Traceback (AttributeError)
<<Output from 'import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)'>>

Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: module 'scipy' has no attribute '__version__'

# Fixed code
def get_build_ext_override():
    """
    Custom build_ext command to tweak extension building.
    """
    from numpy.distutils.command.build_ext import build_ext as old_build_ext

    class build_ext(old_build_ext):
        def build_extension(self, ext):
            # When compiling with GNU compilers, use a version script to
            # hide symbols during linking.
            if self.__is_using_gnu_linker(ext):
                export_symbols = self.get_export_symbols(ext)
                text = "{global: %s; local: *; };" % (";".join(export_symbols),)

                script_fn = os.path.join(
                    self.build_temp, "link-version-{}.map".format(ext.name)
                )
                with open(script_fn, "w") as f:
                    f.write(text)
                    # line below fixes gh-8680
                    ext.extra_link_args = [
                        arg
                        for arg in ext.extra_link_args
                        if not "version-script" in arg
                    ]
                    ext.extra_link_args.append("-Wl,--version-script=" + script_fn)

            old_build_ext.build_extension(self, ext)

        def __is_using_gnu_linker(self, ext):
            if not sys.platform.startswith("linux"):
                return False

            # Fortran compilation with gfortran uses it also for
            # linking. For the C compiler, we detect gcc in a similar
            # way as distutils does it in
            # UnixCCompiler.runtime_library_dir_option
            if ext.language == "f90":
                is_gcc = self._f90_compiler.compiler_type in ("gnu", "gnu95")
            elif ext.language == "f77":
                is_gcc = self._f77_compiler.compiler_type in ("gnu", "gnu95")
            else:
                is_gcc = False
                if self.compiler.compiler_type == "unix":
                    cc = sysconfig.get_config_var("CC")
                    if not cc:
                        cc = ""
                    compiler_name = os.path.basename(cc)
                    is_gcc = "gcc" in compiler_name or "g++" in compiler_name
            return is_gcc and sysconfig.get_config_var("GNULD") == "yes"

    return build_ext