public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Achim Gratz <Stromeko@nexgo.de>
To: binutils@sourceware.org
Subject: [Bug] DWARF-5 section names in PE/PEP and weak symbols
Date: Wed, 08 Dec 2021 19:27:06 +0100	[thread overview]
Message-ID: <878rwvrlz9.fsf@Rainer.invalid> (raw)


The commit

--8<---------------cut here---------------start------------->8---
commit ba6eb62ff0ea9843a018cfd7cd06777bd66ae0a0
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Mar 1 16:25:06 2021 +0000

    Add DWARF-5 section names to PE and PEP linker scripts.
    
            PR 27268
            * scripttempl/pe.sc: Add DWARF-5 section names.
            * scripttempl/pep.sc: Likewise.
--8<---------------cut here---------------end--------------->8---

changed the behaviour of weak symbols in Cygwin.  The following test
from gnulib that should fail.  In other words fputs should have a symbol
value of 0x0 and the resulting executable should not be able to run
since the Windows loader does not resolve weak symbols):

--8<--weak.c-------cut here---------------start------------->8---
#include <stdio.h>
#pragma weak fputs
int main ()
{
  return (fputs == NULL);
}
--8<---------------cut here---------------end--------------->8---

$ gcc -o weak weak.c # w/ binutils 2.36.1
$ ./weak ; echo $?
./weak: ./weak: cannot execute binary file
126

Instead, starting with the above commit, the test succeeds since fputs
has the (expected) value from cygwin1.dll.  This then leads to
horrendous crashes in applications that attempt to actually use "real"
weak symbols based on the (probably too simplistic) test from gnulib:

$ gcc -o weak weak.c # w/ binutils 2.37
$ ./weak ; echo $?
0

I've narrowed it down to just one of the new DWARF5 sections and
removing them from the linker scripts restores the correct behaviour of
weak symbols in Cygwin (I have no idea if that triggers problems
elsewhere):

--8<---------------cut here---------------start------------->8---
diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
index e9d1f78cb32..2e64a681850 100644
--- a/ld/scripttempl/pe.sc
+++ b/ld/scripttempl/pe.sc
@@ -447,10 +447,12 @@ SECTIONS
   {
     *(.zdebug_line_str)
   }
+/* ===
   .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
     *(.debug_loclists)
   }
+=== */
   .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
     *(.zdebug_loclists)
diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
index afa2d23871c..dbb657c2090 100644
--- a/ld/scripttempl/pep.sc
+++ b/ld/scripttempl/pep.sc
@@ -452,10 +452,12 @@ SECTIONS
   {
     *(.zdebug_line_str)
   }
+/* ===
   .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
     *(.debug_loclists)
   }
+=== */
   .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
   {
     *(.zdebug_loclists)
--8<---------------cut here---------------end--------------->8---


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

             reply	other threads:[~2021-12-08 18:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 18:27 Achim Gratz [this message]
2021-12-15 13:12 ` Nick Clifton
2021-12-20 19:45   ` Achim Gratz
2022-01-23  8:10     ` Achim Gratz
2022-01-29  7:57   ` Achim Gratz
2022-02-13 20:17   ` Achim Gratz
2022-02-14 11:02     ` ASSI
2022-02-15 17:58       ` Achim Gratz
2022-02-15 19:08         ` Achim Gratz
2022-02-15 20:19         ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rwvrlz9.fsf@Rainer.invalid \
    --to=stromeko@nexgo.de \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).