From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 09/10] elf: Add facility to create stub DSOs in elf/stub-dsos
Date: Mon, 24 May 2021 15:24:42 -0300 [thread overview]
Message-ID: <4fade004-5748-525c-e0e4-6f63c2837f5d@linaro.org> (raw)
In-Reply-To: <4ea2bdaebef66c6646aa0f8df13b4108d7933b7d.1621347402.git.fweimer@redhat.com>
On 18/05/2021 11:25, Florian Weimer via Libc-alpha wrote:
> And reference the elf/stub-dsos directory when linking installed
> programs.
So if I understood correctly, this is to trigger an invalid runtime
to avoid linking against system GLIBC_PRIVATE symbols, right?
I am not sure I fully understand the lib-stub trick here, how
exactly the lib-stub is preventing the wrong linkage here? And why
is this required for the libpthread move (my feeling this is orthogonal
to the project).
> ---
> Makeconfig | 10 ++++++++--
> elf/Makefile | 18 +++++++++++++++++-
> elf/lib-stub.S | 22 ++++++++++++++++++++++
> 3 files changed, 47 insertions(+), 3 deletions(-)
> create mode 100644 elf/lib-stub.S
>
> diff --git a/Makeconfig b/Makeconfig
> index 1d5e45926c..3ef71cc02b 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -425,7 +425,8 @@ ifndef +link-pie
> $(link-extra-libs)
> +link-pie-after-libc = $(+postctorS) $(+postinit)
> define +link-pie
> -$(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \
> +$(CC) $(link-libc-rpath-link)$(rpath-link-stubs) \
> + $(+link-pie-before-libc) $(rtld-LDFLAGS) \
> $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
> $(call after-link,$@)
> endef
Ok.
> @@ -487,7 +488,8 @@ else # not build-pie-default
> $(link-extra-libs)
> +link-after-libc = $(+postctor) $(+postinit)
> define +link
> -$(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \
> +$(CC) $(link-libc-rpath-link)$(rpath-link-stubs) \
> + $(+link-before-libc) $(rtld-LDFLAGS) \
> $(link-extra-flags) $(link-libc) $(+link-after-libc)
> $(call after-link,$@)
> endef
> @@ -581,6
Ok.
+583,10 @@ link-libc-printers-tests = $(link-libc-rpath) \
> rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support
> rpath-link = \
> $(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
> +
> +# See $(elf-stub-dso-files) in elf/Makefile.
> +rpath-link-stubs=:$(common-objdir)/elf/stub-dsos
> +
> else # build-static
> link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
> link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
Ok.
> diff --git a/elf/Makefile b/elf/Makefile
> index 834ec858a8..5f179bae19 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -505,7 +505,23 @@ ifeq (yes,$(build-shared))
> # to run programs during the `make others' pass.
> lib-noranlib: $(objpfx)$(rtld-installed-name) \
> $(addprefix $(objpfx),$(extra-objs))
> -endif
> +
> +# The system may have installed DSO that no longer exist as separate
> +# DSOs in the current glibc version. The link editor will try to
> +# resolve versioned GLIBC_PRIVATE symbol references in them against
> +# libc.so, but these exports do not exist anymore. Supplying these
> +# stub DSOs in a directory searched by -rpath-link prevents the link
> +# editor from picking up the installed system files.
> +ifneq ($(strip $(elf-stub-dsos)),)
> +elf-stub-dso-files :=\
> +$(foreach L,$(elf-stub-dsos),$(objpfx)/stub-dsos/lib$L.so$(lib$L.so-version))
> +$(elf-stub-dso-files): lib-stub.S
> + $(make-target-directory)
> + $(LINK.o) -shared -o $@ -B$(csu-objpfx) $(LDFLAGS.so) \
> + -Wl,-soname=$(@F) -nostdlib $<
> +subdir_lib: $(elf-stub-dso-files)
> +endif # $(elf-stub-dsos)
> +endif # $(build-shared)
>
> # Command to link into a larger single relocatable object.
> reloc-link = $(LINK.o) -nostdlib -nostartfiles -r
> diff --git a/elf/lib-stub.S b/elf/lib-stub.S
> new file mode 100644
> index 0000000000..2b5ae2010e
> --- /dev/null
> +++ b/elf/lib-stub.S
> @@ -0,0 +1,22 @@
> +/* Assembler source file for creating stub libraries.
> + Copyright (C) 2021 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> + /* Produce an invalid init function, so that loading the stub
> + crashes. */
> + .section .init_array,"a",%init_array
> + .dc.a 4096
>
next prev parent reply other threads:[~2021-05-24 18:24 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 14:24 [PATCH 00/10] nptl: Complete libpthread removal Florian Weimer
2021-05-18 14:24 ` [PATCH 01/10] nptl: Perform signal initialization upon pthread_create Florian Weimer
2021-05-20 19:15 ` Adhemerval Zanella
2021-05-20 19:41 ` Florian Weimer
2021-05-20 19:57 ` Adhemerval Zanella
2021-05-20 20:05 ` Florian Weimer
2021-05-20 20:32 ` Adhemerval Zanella
2021-05-21 9:58 ` Florian Weimer
2021-05-21 11:31 ` Adhemerval Zanella
2021-05-21 12:40 ` Adhemerval Zanella
2021-05-18 14:24 ` [PATCH 02/10] nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variables Florian Weimer
2021-05-18 14:25 ` [PATCH 03/10] nptl: Move semi-public __pthread_get_minstack symbol into libc Florian Weimer
2021-05-18 14:25 ` [PATCH 04/10] elf: Use custom NODELETE DSO for tst-dlopenfail, tst-dlopenfail-2 Florian Weimer
2021-05-20 20:36 ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 05/10] nptl: Move pthread_create, thrd_create into libc Florian Weimer
2021-05-20 20:44 ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 06/10] nptl: Remove unused __libc_pthread_init function Florian Weimer
2021-05-18 14:49 ` Andreas Schwab
2021-05-18 14:25 ` [PATCH 07/10] nptl: Remove remaining code from libpthread Florian Weimer
2021-05-20 20:49 ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 08/10] elf: Do not load libpthread for PTHREAD_IN_LIBC Florian Weimer
2021-05-20 20:53 ` Adhemerval Zanella
2021-05-21 19:15 ` Florian Weimer
2021-05-18 14:25 ` [PATCH 09/10] elf: Add facility to create stub DSOs in elf/stub-dsos Florian Weimer
2021-05-24 18:24 ` Adhemerval Zanella [this message]
2021-05-24 18:25 ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 10/10] nptl: Stop building libpthread Florian Weimer
2021-05-18 14:56 ` [PATCH 00/10] nptl: Complete libpthread removal Andreas Schwab
2021-05-18 15:04 ` Florian Weimer
2021-05-18 15:26 ` Andreas Schwab
2021-05-18 15:51 ` Florian Weimer
2021-05-18 16:27 ` Andreas Schwab
2021-05-18 16:31 ` Florian Weimer
2021-05-18 16:47 ` Andreas Schwab
2021-05-20 13:27 ` Florian Weimer
2021-05-20 13:50 ` Andreas Schwab
2021-05-20 13:54 ` Florian Weimer
2021-05-20 14:01 ` Andreas Schwab
2021-05-20 15:09 ` H.J. Lu
2021-05-20 15:13 ` Florian Weimer
2021-05-20 15:17 ` Andreas Schwab
2021-05-20 15:35 ` H.J. Lu
2021-05-20 15:39 ` Florian Weimer
2021-05-20 15:57 ` H.J. Lu
2021-05-19 11:57 ` Szabolcs Nagy
2021-05-19 12:35 ` Florian Weimer
2021-05-19 13:14 ` Szabolcs Nagy
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=4fade004-5748-525c-e0e4-6f63c2837f5d@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=libc-alpha@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).