diff mbox

[BZ,#18479] : nptl: restore .interp section in libpthread.so

Message ID 20150602180401.GA28489@glebfm.cloud.tilaa.com
State New
Headers show

Commit Message

Gleb Fotengauer-Malinovskiy June 2, 2015, 6:04 p.m. UTC
In commit 02657da2cf4457804ed938ee08b8316249126444, .interp section was
removed from libpthread.so.  This led to an error:

  $ /lib64/libpthread.so.0
  Native POSIX Threads Library by Ulrich Drepper et al
  Copyright (C) 2015 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.
  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.
  Forced unwind support included.
  Segmentation fault

  (gdb) bt
  #0  0x00000000000055a6 in _exit@plt ()

Since NOT_IN_* macros were removed and new IS_IN* stuff is enforced,
a slightly different workaround has to be added to avoid inclusion
of symbol-hacks into interp.os file.

Unfortunately, there is no way to add a regression test for the bug
because .interp specifies the path to dynamic linker of the target
system.

Tested on x86_64, x86, and armhf.

[BZ #18479]
* sysdeps/generic/symbol-hacks.h: Skip if NO_SYMBOL_HACKS is defined.
* sysdeps/wordsize-32/symbol-hacks.h: Likewise.
* elf/Makefile (CPPFLAGS-interp.c): Set to -DNO_SYMBOL_HACKS=1.
* nptl/Makefile ($(objpfx)libpthread.so): Add $(+interp).

Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 elf/Makefile                       | 1 +
 nptl/Makefile                      | 1 +
 sysdeps/generic/symbol-hacks.h     | 3 ++-
 sysdeps/wordsize-32/symbol-hacks.h | 3 ++-
 4 files changed, 6 insertions(+), 2 deletions(-)

Comments

Roland McGrath June 2, 2015, 8:09 p.m. UTC | #1
I think it's better just to give libpthread its own build of interp.c.
The simplest thing is to add a pt-interp to libpthread-routines and
have pt-interp.c be: #include <elf/interp.c>.
Dmitry V. Levin June 2, 2015, 10:47 p.m. UTC | #2
On Tue, Jun 02, 2015 at 01:09:48PM -0700, Roland McGrath wrote:
> I think it's better just to give libpthread its own build of interp.c.
> The simplest thing is to add a pt-interp to libpthread-routines and
> have pt-interp.c be: #include <elf/interp.c>.

In that case $(objpfx)pt-interp.os would have to depend on
$(elf-objpfx)runtime-linker.h; this dependence doesn't work as is
and looks as dirty as -DNO_SYMBOL_HACKS.
Roland McGrath June 5, 2015, 9:05 p.m. UTC | #3
> On Tue, Jun 02, 2015 at 01:09:48PM -0700, Roland McGrath wrote:
> > I think it's better just to give libpthread its own build of interp.c.
> > The simplest thing is to add a pt-interp to libpthread-routines and
> > have pt-interp.c be: #include <elf/interp.c>.
> 
> In that case $(objpfx)pt-interp.os would have to depend on
> $(elf-objpfx)runtime-linker.h; this dependence doesn't work as is
> and looks as dirty as -DNO_SYMBOL_HACKS.

We could move runtime-linker.h to $(common-objpfx) and the rules for it to
Rules.
diff mbox

Patch

diff --git a/elf/Makefile b/elf/Makefile
index e5b142c..0f646a7 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -354,6 +354,7 @@  $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map)
 	mv -f $@.new $@
 
 # interp.c exists just to get the runtime linker path into libc.so.
+CPPFLAGS-interp.c = -DNO_SYMBOL_HACKS=1
 $(objpfx)interp.os: $(elf-objpfx)runtime-linker.h
 
 $(elf-objpfx)runtime-linker.h: $(elf-objpfx)runtime-linker.st; @:
diff --git a/nptl/Makefile b/nptl/Makefile
index 7c39d6d..0e546bb 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -542,6 +542,7 @@  extra-B-pthread.so = -B$(common-objpfx)nptl/
 $(objpfx)libpthread.so: $(addprefix $(objpfx),$(crti-objs) $(crtn-objs))
 $(objpfx)libpthread.so: +preinit += $(addprefix $(objpfx),$(crti-objs))
 $(objpfx)libpthread.so: +postinit += $(addprefix $(objpfx),$(crtn-objs))
+$(objpfx)libpthread.so: $(+interp)
 
 # Make sure we link with the thread library.
 ifeq ($(build-shared),yes)
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index ce576c9..e2da923 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -1,6 +1,7 @@ 
 /* Some compiler optimizations may transform loops into memset/memmove
    calls and without proper declaration it may generate PLT calls.  */
-#if !defined __ASSEMBLER__ && IS_IN (libc) && defined SHARED
+#if !defined __ASSEMBLER__ && IS_IN (libc) && defined SHARED \
+    && !defined NO_SYMBOL_HACKS
 asm ("memmove = __GI_memmove");
 asm ("memset = __GI_memset");
 asm ("memcpy = __GI_memcpy");
diff --git a/sysdeps/wordsize-32/symbol-hacks.h b/sysdeps/wordsize-32/symbol-hacks.h
index ceabb76..0bdf785 100644
--- a/sysdeps/wordsize-32/symbol-hacks.h
+++ b/sysdeps/wordsize-32/symbol-hacks.h
@@ -23,7 +23,8 @@ 
    therefore we get PLTs.  Unnecessarily so.  Changing gcc is a big
    task which might not be worth it so we play tricks with the
    assembler.  */
-#if !defined __ASSEMBLER__ && !defined in_divdi3_c && IS_IN (libc) && defined SHARED
+#if !defined __ASSEMBLER__ && !defined in_divdi3_c && IS_IN (libc) \
+    && defined SHARED && !defined NO_SYMBOL_HACKS
 asm ("__divdi3 = __divdi3_internal");
 asm ("__udivdi3 = __udivdi3_internal");
 asm ("__moddi3 = __moddi3_internal");