Thu Jun 8 18:24:39 2017 UTC ()
Call _rtld_debug_state before running the global initialisers, so give
gdb a chance to set break points etc.


(joerg)
diff -r1.183 -r1.184 src/libexec/ld.elf_so/rtld.c

cvs diff -r1.183 -r1.184 src/libexec/ld.elf_so/rtld.c (expand / switch to unified diff)

--- src/libexec/ld.elf_so/rtld.c 2017/02/27 20:25:26 1.183
+++ src/libexec/ld.elf_so/rtld.c 2017/06/08 18:24:39 1.184
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rtld.c,v 1.183 2017/02/27 20:25:26 chs Exp $ */ 1/* $NetBSD: rtld.c,v 1.184 2017/06/08 18:24:39 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright 1996 John D. Polstra. 4 * Copyright 1996 John D. Polstra.
5 * Copyright 1996 Matt Thomas <matt@3am-software.com> 5 * Copyright 1996 Matt Thomas <matt@3am-software.com>
6 * Copyright 2002 Charles M. Hannum <root@ihack.net> 6 * Copyright 2002 Charles M. Hannum <root@ihack.net>
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35/* 35/*
36 * Dynamic linker for ELF. 36 * Dynamic linker for ELF.
37 * 37 *
38 * John Polstra <jdp@polstra.com>. 38 * John Polstra <jdp@polstra.com>.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42#ifndef lint 42#ifndef lint
43__RCSID("$NetBSD: rtld.c,v 1.183 2017/02/27 20:25:26 chs Exp $"); 43__RCSID("$NetBSD: rtld.c,v 1.184 2017/06/08 18:24:39 joerg Exp $");
44#endif /* not lint */ 44#endif /* not lint */
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/atomic.h> 47#include <sys/atomic.h>
48#include <sys/mman.h> 48#include <sys/mman.h>
49#include <err.h> 49#include <err.h>
50#include <errno.h> 50#include <errno.h>
51#include <fcntl.h> 51#include <fcntl.h>
52#include <lwp.h> 52#include <lwp.h>
53#include <stdarg.h> 53#include <stdarg.h>
54#include <stdio.h> 54#include <stdio.h>
55#include <stdlib.h> 55#include <stdlib.h>
56#include <string.h> 56#include <string.h>
@@ -723,43 +723,43 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) @@ -723,43 +723,43 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
723 (*real___progname) = NULL; 723 (*real___progname) = NULL;
724 } 724 }
725 } 725 }
726 real_environ = _rtld_objmain_sym("environ"); 726 real_environ = _rtld_objmain_sym("environ");
727 if (real_environ) 727 if (real_environ)
728 *real_environ = environ; 728 *real_environ = environ;
729 /* 729 /*
730 * Set __mainprog_obj for old binaries. 730 * Set __mainprog_obj for old binaries.
731 */ 731 */
732 real___mainprog_obj = _rtld_objmain_sym("__mainprog_obj"); 732 real___mainprog_obj = _rtld_objmain_sym("__mainprog_obj");
733 if (real___mainprog_obj) 733 if (real___mainprog_obj)
734 *real___mainprog_obj = _rtld_objmain; 734 *real___mainprog_obj = _rtld_objmain;
735 735
 736 _rtld_debug_state(); /* say hello to gdb! */
 737
736 _rtld_exclusive_enter(&mask); 738 _rtld_exclusive_enter(&mask);
737 739
738 dbg(("calling _init functions")); 740 dbg(("calling _init functions"));
739 _rtld_call_init_functions(&mask); 741 _rtld_call_init_functions(&mask);
740 742
741 dbg(("control at program entry point = %p, obj = %p, exit = %p", 743 dbg(("control at program entry point = %p, obj = %p, exit = %p",
742 _rtld_objmain->entry, _rtld_objmain, _rtld_exit)); 744 _rtld_objmain->entry, _rtld_objmain, _rtld_exit));
743 745
744 _rtld_exclusive_exit(&mask); 746 _rtld_exclusive_exit(&mask);
745 747
746 /* 748 /*
747 * Return with the entry point and the exit procedure in at the top 749 * Return with the entry point and the exit procedure in at the top
748 * of stack. 750 * of stack.
749 */ 751 */
750 752
751 _rtld_debug_state(); /* say hello to gdb! */ 
752 
753 ((void **) osp)[0] = _rtld_exit; 753 ((void **) osp)[0] = _rtld_exit;
754 ((void **) osp)[1] = _rtld_objmain; 754 ((void **) osp)[1] = _rtld_objmain;
755 return (Elf_Addr) _rtld_objmain->entry; 755 return (Elf_Addr) _rtld_objmain->entry;
756} 756}
757 757
758void 758void
759_rtld_die(void) 759_rtld_die(void)
760{ 760{
761 const char *msg = dlerror(); 761 const char *msg = dlerror();
762 762
763 if (msg == NULL) 763 if (msg == NULL)
764 msg = "Fatal error"; 764 msg = "Fatal error";
765 xerrx(1, "%s", msg); 765 xerrx(1, "%s", msg);