From: Florian Weimer via Libc-alpha <libc-alpha@sourceware.org>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: libc-alpha@sourceware.org, bug-gnulib@gnu.org,
Florian Weimer via Binutils <binutils@sourceware.org>
Subject: Re: Undefined use of weak symbols in gnulib
Date: Tue, 27 Apr 2021 13:06:43 +0200 [thread overview]
Message-ID: <87eeewnfzw.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <87fszc8a1z.fsf@igel.home> (Andreas Schwab's message of "Tue, 27 Apr 2021 09:24:08 +0200")
* Andreas Schwab:
> On Apr 27 2021, Florian Weimer via Binutils wrote:
>
>> I think we can provide an libBrokenGnulib.so preload module which
>> defines pthread_mutexattr_gettype to zero (as an absolute address), so
>> there is a kludge to keep old binaries working, but this is really
>> something that must be fixed in gnulib.
>
> It is likely that the use of weak pthread symbols is not confined to
> gnulib.
True.
Here's a fairly representative test case, I think.
#include <pthread.h>
#include <stdio.h>
extern __typeof (pthread_key_create) __pthread_key_create __attribute__ ((weak));
extern __typeof (pthread_once) pthread_once __attribute__ ((weak));
void
f1 (void)
{
puts ("f1 called");
}
pthread_once_t once_var;
void __attribute__ ((weak))
f2 (void)
{
if (__pthread_key_create != NULL)
pthread_once (&once_var, f1);
}
int
main (void)
{
f2 ();
}
Building it with “gcc -O2 -fpie -pie” and linking with binutils 2.30
does not result in a crash with LD_PRELOAD=libpthread.so.0. That's
because the call-to-address-zero via pthread_once has been stubbed out
with NOPs, I think. This is still not correct and will undoubtedly
cause problems because pthread_once is usually called for its side
effect.
With binutils 2.35, the call-to-address-zero is not stubbed out anymore,
but there is still no dynamic symbol reference for pthread_once, so
there is a crash when running with LD_PRELOAD=libpthread.so.0.
This looks like a pre-existing toolchain issue on POWER, related to the
thread I quoted at the start. If we proceed with the glibc libpthread
changes as planned, things might turn out unacceptably bad.
I did a quick experiment and we cannot work around this using a
libpthread.so stub library and compatibility-only symbols in libc.so.6.
Unversioned weak symbols bind to the baseline symbol version, as they
probably should. Even a __pthread_key_create@GLIBC_2.17 compatibility
symbol triggers this issue. I have to think of something else to
salvage this.
Thanks,
Florian
next prev parent reply other threads:[~2021-04-27 11:06 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-27 5:53 Undefined use of weak symbols in gnulib Florian Weimer via Libc-alpha
2021-04-27 6:50 ` Paul Eggert
2021-04-27 6:58 ` Florian Weimer via Libc-alpha
2021-04-27 7:13 ` Paul Eggert
2021-04-27 7:24 ` Andreas Schwab
2021-04-27 11:06 ` Florian Weimer via Libc-alpha [this message]
2021-04-28 0:09 ` Bruno Haible
2021-04-28 2:10 ` H.J. Lu via Libc-alpha
2021-04-28 2:13 ` H.J. Lu via Libc-alpha
2021-05-05 20:31 ` Fangrui Song
2021-04-28 8:35 ` Florian Weimer via Libc-alpha
2021-04-28 13:15 ` Michael Matz
2021-04-28 7:44 ` Florian Weimer via Libc-alpha
2021-04-28 14:48 ` Bruno Haible
2021-04-28 17:44 ` Florian Weimer via Libc-alpha
2021-07-17 14:38 ` Bruno Haible
2021-07-17 14:55 ` Florian Weimer via Libc-alpha
2021-07-17 16:39 ` Bruno Haible
2021-07-27 20:02 ` Joseph Myers
2021-07-27 20:19 ` Florian Weimer via Libc-alpha
2021-07-27 23:38 ` Paul Eggert
2021-04-27 23:22 ` Bruno Haible
2021-04-27 23:47 ` Bruno Haible
2021-04-28 7:57 ` Florian Weimer via Libc-alpha
2021-04-28 14:40 ` Bruno Haible
2021-04-28 17:43 ` Florian Weimer via Libc-alpha
2021-04-29 15:15 ` Bruno Haible
2021-04-30 9:55 ` Florian Weimer via Libc-alpha
2021-04-29 6:33 ` Ben Pfaff via Libc-alpha
2021-05-03 1:44 ` Alan Modra via Libc-alpha
2021-07-12 10:04 ` Michael Hudson-Doyle via Libc-alpha
2021-07-12 15:03 ` Florian Weimer via Libc-alpha
2021-07-12 15:30 ` Matthias Klose
2021-07-12 15:37 ` Florian Weimer via Libc-alpha
2021-07-13 0:22 ` Michael Hudson-Doyle via Libc-alpha
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eeewnfzw.fsf@oldenburg.str.redhat.com \
--to=libc-alpha@sourceware.org \
--cc=binutils@sourceware.org \
--cc=bug-gnulib@gnu.org \
--cc=fweimer@redhat.com \
--cc=schwab@linux-m68k.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).