Hi! As mentioned in the PR, before the https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ba6eb62ff0ea9843a018cfd7cd06777bd66ae0a0 fix from March 1st, PECOFF ld.bfd didn't know about .debug_loclists, .debug_rnglists and other debug sections new in DWARF 5. Unfortunately, unlike for ELF linkers, that means the sections were placed in wrong ordering with wrong VMA/LMA, so the resulting executables are apparently unusable.
As that is pretty new change, newer than 2.35.2 or 2.36 binutils releases, the following patch adds a workaround that turns -gdwarf-4 by default instead of -gdwarf-5 if a broken linker is found at configure time. Users can still explicitly play with -gdwarf-5 and either use a non-broken linker or use custom linker scripts for the broken one, but at least by default it should work. Bootstrapped/regtested on x86_64-linux and i686-linux and Jonathan said he has tested it on Windows in the PR. Ok for trunk? 2021-03-24 Jakub Jelinek <ja...@redhat.com> PR bootstrap/98860 * configure.ac (HAVE_LD_BROKEN_PE_DWARF5): New AC_DEFINE if PECOFF linker doesn't support DWARF sections new in DWARF5. * config/i386/i386-options.c (ix86_option_override_internal): Default to dwarf_version 4 if HAVE_LD_BROKEN_PE_DWARF5 for TARGET_PECOFF targets. * config.in: Regenerated. * configure: Regenerated. --- gcc/configure.ac.jj 2021-01-25 14:20:01.818334183 +0100 +++ gcc/configure.ac 2021-03-23 16:59:47.199192635 +0100 @@ -6190,6 +6190,31 @@ if test x"$ld64_flag" = x"yes"; then [Define to 1 if ld64 supports '-export_dynamic'.]) fi +case $target_os in + win32 | pe | cygwin* | mingw32*) + AC_MSG_CHECKING(broken PE linker dwarf5 support) + gcc_cv_ld_broken_pe_dwarf5=yes + if test $in_tree_ld = yes ; then + if grep -q '\.debug_loclists.*BLOCK.*__section_alignment__.*NOLOAD.*:' \ + $gcc_cv_ld_gld_srcdir/scripttempl/pe*.sc \ + && grep -q '\.debug_rnglists.*BLOCK.*__section_alignment__.*NOLOAD.*:' \ + $gcc_cv_ld_gld_srcdir/scripttempl/pe*.sc; then + gcc_cv_ld_broken_pe_dwarf5=no + fi + else + if $gcc_cv_ld --verbose 2>&1 | grep -q '\.debug_loclists.*BLOCK.*__section_alignment__.*NOLOAD.*:' \ + && $gcc_cv_ld --verbose 2>&1 | grep -q '\.debug_rnglists.*BLOCK.*__section_alignment__.*NOLOAD.*:'; then + gcc_cv_ld_broken_pe_dwarf5=no + fi + fi + if test x$gcc_cv_ld_broken_pe_dwarf5 = xyes; then + AC_DEFINE(HAVE_LD_BROKEN_PE_DWARF5, 1, + [Define if the PE linker has broken DWARF 5 support.]) + fi + AC_MSG_RESULT($gcc_cv_ld_broken_pe_dwarf5) + ;; +esac + # -------- # UNSORTED # -------- --- gcc/config/i386/i386-options.c.jj 2021-03-19 18:36:23.018588431 +0100 +++ gcc/config/i386/i386-options.c 2021-03-23 16:58:52.536791866 +0100 @@ -1861,6 +1861,13 @@ ix86_option_override_internal (bool main SUBSUBTARGET_OVERRIDE_OPTIONS; #endif +#ifdef HAVE_LD_BROKEN_PE_DWARF5 + /* If the PE linker has broken DWARF 5 support, make + DWARF 4 the default. */ + if (TARGET_PECOFF) + SET_OPTION_IF_UNSET (opts, opts_set, dwarf_version, 4); +#endif + /* -fPIC is the default for x86_64. */ if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags)) opts->x_flag_pic = 2; --- gcc/config.in.jj 2020-12-28 12:27:32.302754870 +0100 +++ gcc/config.in 2021-03-23 16:59:11.450584412 +0100 @@ -1580,6 +1580,12 @@ #endif +/* Define if the PE linker has broken DWARF 5 support. */ +#ifndef USED_FOR_TARGET +#undef HAVE_LD_BROKEN_PE_DWARF5 +#endif + + /* Define if your linker supports --build-id. */ #ifndef USED_FOR_TARGET #undef HAVE_LD_BUILDID --- gcc/configure.jj 2021-01-25 14:20:01.821334150 +0100 +++ gcc/configure 2021-03-23 16:59:53.375124921 +0100 @@ -19392,7 +19392,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19405 "configure" +#line 19395 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -19498,7 +19498,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19511 "configure" +#line 19501 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -22237,16 +22237,6 @@ freebsd* | dragonfly*) esac ;; -gnu*) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - hardcode_into_libs=yes - ;; - haiku*) version_type=linux need_lib_prefix=no @@ -22368,7 +22358,7 @@ linux*oldld* | linux*aout* | linux*coff* # project, but have not yet been accepted: they are GCC-local changes # for the time being. (See # https://lists.gnu.org/archive/html/libtool-patches/2018-05/msg00000.html) -linux* | k*bsd*-gnu | kopensolaris*-gnu | uclinuxfdpiceabi) +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu* | uclinuxfdpiceabi) version_type=linux need_lib_prefix=no need_version=no @@ -30223,6 +30213,34 @@ _ACEOF fi +case $target_os in + win32 | pe | cygwin* | mingw32*) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking broken PE linker dwarf5 support" >&5 +$as_echo_n "checking broken PE linker dwarf5 support... " >&6; } + gcc_cv_ld_broken_pe_dwarf5=yes + if test $in_tree_ld = yes ; then + if grep -q '\.debug_loclists.*BLOCK.*__section_alignment__.*NOLOAD.*:' \ + $gcc_cv_ld_gld_srcdir/scripttempl/pe*.sc \ + && grep -q '\.debug_rnglists.*BLOCK.*__section_alignment__.*NOLOAD.*:' \ + $gcc_cv_ld_gld_srcdir/scripttempl/pe*.sc; then + gcc_cv_ld_broken_pe_dwarf5=no + fi + else + if $gcc_cv_ld --verbose 2>&1 | grep -q '\.debug_loclists.*BLOCK.*__section_alignment__.*NOLOAD.*:' \ + && $gcc_cv_ld --verbose 2>&1 | grep -q '\.debug_rnglists.*BLOCK.*__section_alignment__.*NOLOAD.*:'; then + gcc_cv_ld_broken_pe_dwarf5=no + fi + fi + if test x$gcc_cv_ld_broken_pe_dwarf5 = xyes; then + +$as_echo "#define HAVE_LD_BROKEN_PE_DWARF5 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_broken_pe_dwarf5" >&5 +$as_echo "$gcc_cv_ld_broken_pe_dwarf5" >&6; } + ;; +esac + # -------- # UNSORTED # -------- Jakub