Patchwork Add missing unwind information to ld.so on powerpc32 (bug 23707)

login
register
mail settings
Submitter Andreas Schwab
Date Sept. 26, 2018, 9:31 a.m.
Message ID <mvm4leca9ko.fsf@suse.de>
Download mbox | patch
Permalink /patch/29541/
State New
Headers show

Comments

Andreas Schwab - Sept. 26, 2018, 9:31 a.m.
[BZ #23707]
	* sysdeps/powerpc/powerpc32/dl-start.S: Add unwind information.
	* elf/Makefile (tests): Add tst-unwind-ctor.
	(modules-names): Add tst-unwind-ctor-lib.
	($(objpfx)tst-unwind-ctor): Depend on
	$(objpfx)tst-unwind-ctor-lib.so.
---
 elf/Makefile                         |  7 +++--
 elf/tst-unwind-ctor-lib.c            | 41 ++++++++++++++++++++++++++++
 elf/tst-unwind-ctor.c                | 25 +++++++++++++++++
 sysdeps/powerpc/powerpc32/dl-start.S |  3 ++
 4 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 elf/tst-unwind-ctor-lib.c
 create mode 100644 elf/tst-unwind-ctor.c
Florian Weimer - Sept. 26, 2018, 9:37 a.m.
* Andreas Schwab:

> diff --git a/elf/Makefile b/elf/Makefile
> index 037f68165b..455ec730fc 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile

> +$(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-lib.so

Does this link with libunwind on some targets?

Would it be possible to side-step this issue if we made it a C++ test,
so that the unwinder is linked in automatically?

> diff --git a/elf/tst-unwind-ctor-lib.c b/elf/tst-unwind-ctor-lib.c
> new file mode 100644
> index 0000000000..f517e43ec4
> --- /dev/null
> +++ b/elf/tst-unwind-ctor-lib.c

> +static void
> +__attribute__ ((constructor))
> +do_unwind (void)
> +{
> +  /* Arrange for this test to be killed if _Unwind_Backtrace runs into an
> +     endless loop.  */
> +  alarm (20);
> +  _Unwind_Backtrace (callback, 0);
> +}

Please augment the comment to indicate that this code would run before
the test driver has a chance to set up the timeout.

> diff --git a/elf/tst-unwind-ctor.c b/elf/tst-unwind-ctor.c
> new file mode 100644
> index 0000000000..96100527b2
> --- /dev/null
> +++ b/elf/tst-unwind-ctor.c

> +int
> +main (void)
> +{
> +  dummy ();
> +}

Perhaps add a comment saying that this tests an ELF constructor, so that
the test driver is useless?

(Of course, this should tell us something about our test framework …)

Otherwise, the fix and test look good to me.

Thanks,
Florian
Andreas Schwab - Sept. 26, 2018, 10:41 a.m.
On Sep 26 2018, Florian Weimer <fweimer@redhat.com> wrote:

> * Andreas Schwab:
>
>> diff --git a/elf/Makefile b/elf/Makefile
>> index 037f68165b..455ec730fc 100644
>> --- a/elf/Makefile
>> +++ b/elf/Makefile
>
>> +$(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-lib.so
>
> Does this link with libunwind on some targets?

If that's what you mean, the test builds successfully on ia64.

Andreas.
Florian Weimer - Sept. 26, 2018, 1:18 p.m.
* Andreas Schwab:

> On Sep 26 2018, Florian Weimer <fweimer@redhat.com> wrote:
>
>> * Andreas Schwab:
>>
>>> diff --git a/elf/Makefile b/elf/Makefile
>>> index 037f68165b..455ec730fc 100644
>>> --- a/elf/Makefile
>>> +++ b/elf/Makefile
>>
>>> +$(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-lib.so
>>
>> Does this link with libunwind on some targets?
>
> If that's what you mean, the test builds successfully on ia64.

I think this is what I meant, thanks.

Florian

Patch

diff --git a/elf/Makefile b/elf/Makefile
index 037f68165b..455ec730fc 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -186,7 +186,8 @@  tests += restest1 preloadtest loadfail multiload origtest resolvfail \
 	 tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \
 	 tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-noload \
 	 tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \
-	 tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note
+	 tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
+	 tst-unwind-ctor
 #	 reldep9
 tests-internal += loadtest unload unload2 circleload1 \
 	 neededtest neededtest2 neededtest3 neededtest4 \
@@ -273,7 +274,7 @@  modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
 		tst-latepthreadmod $(tst-tls-many-dynamic-modules) \
 		tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin \
 		tst-main1mod tst-libc_dlvsym-dso tst-absolute-sym-lib \
-		tst-absolute-zero-lib tst-big-note-lib
+		tst-absolute-zero-lib tst-big-note-lib tst-unwind-ctor-lib
 # Most modules build with _ISOMAC defined, but those filtered out
 # depend on internal headers.
 modules-names-tests = $(filter-out ifuncmod% tst-libc_dlvsym-dso tst-tlsmod%,\
@@ -1492,3 +1493,5 @@  tst-libc_dlvsym-static-ENV = \
 $(objpfx)tst-libc_dlvsym-static.out: $(objpfx)tst-libc_dlvsym-dso.so
 
 $(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so
+
+$(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-lib.so
diff --git a/elf/tst-unwind-ctor-lib.c b/elf/tst-unwind-ctor-lib.c
new file mode 100644
index 0000000000..f517e43ec4
--- /dev/null
+++ b/elf/tst-unwind-ctor-lib.c
@@ -0,0 +1,41 @@ 
+/* Unit test for _Unwind_Backtrace in a shared object constructor.
+   Copyright (C) 2018 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unwind.h>
+#include <unistd.h>
+
+static _Unwind_Reason_Code
+callback (struct _Unwind_Context *ctx, void *arg)
+{
+  return _URC_NO_REASON;
+}
+
+static void
+__attribute__ ((constructor))
+do_unwind (void)
+{
+  /* Arrange for this test to be killed if _Unwind_Backtrace runs into an
+     endless loop.  */
+  alarm (20);
+  _Unwind_Backtrace (callback, 0);
+}
+
+void
+dummy (void)
+{
+}
diff --git a/elf/tst-unwind-ctor.c b/elf/tst-unwind-ctor.c
new file mode 100644
index 0000000000..96100527b2
--- /dev/null
+++ b/elf/tst-unwind-ctor.c
@@ -0,0 +1,25 @@ 
+/* Unit test for _Unwind_Backtrace in a shared object constructor.
+   Copyright (C) 2018 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
+   <http://www.gnu.org/licenses/>.  */
+
+extern void dummy (void);
+
+int
+main (void)
+{
+  dummy ();
+}
diff --git a/sysdeps/powerpc/powerpc32/dl-start.S b/sysdeps/powerpc/powerpc32/dl-start.S
index 244d87fb6d..243fb8352b 100644
--- a/sysdeps/powerpc/powerpc32/dl-start.S
+++ b/sysdeps/powerpc/powerpc32/dl-start.S
@@ -34,6 +34,9 @@  ENTRY(_start)
    _dl_start to save the link register).  */
 	li	r4,0
 	addi	r1,r1,-16
+	cfi_adjust_cfa_offset (16)
+/* Mark lr as undefined to stop unwinding.  */
+	cfi_undefined (lr)
 	stw	r4,0(r1)
 	bl	_dl_start@local