From owner-freebsd-ppc@freebsd.org Sun Jun 9 08:49:53 2019 Return-Path: Delivered-To: freebsd-ppc@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5886D15C22C9 for ; Sun, 9 Jun 2019 08:49:53 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic306-20.consmr.mail.ne1.yahoo.com (sonic306-20.consmr.mail.ne1.yahoo.com [66.163.189.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F2C8E8FD2A for ; Sun, 9 Jun 2019 08:49:51 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: 8JsAKYIVM1lrqn5of9egCfmjayw2SHc.sCgHFHw1848OsUrP0sTWWa66A2p9tEU 7ht6H2vm11WkOsfqpnR28_fA_0O4I7qOzJsQ7NUFrQM3yQ56fe0QnG.hfQaUt3iMFTJCYFJFhhOr wuzklaUVYaiZ8F6YQzklC8b.QSGMEiBPSlxAPN7Hjq1bjh7OM.D7pZ53p1_Ec6._mDqnx1Re_Zaj QBYg0_J2BtvGgfeoiyb6AsjP8RhqZjdjBAWOThJi1ry0IEQmNmB4mOTTHCT1bWSRGr2q.mvIvDKu iOejUX7nisxDBLTkxycZTb0y5qeTLzxM5p6MRoqv9EjUQd0tXXKtX7PSZG29m4qIQGd31OilkcW. UVlEgbWYAs_tYrIvk9ZcYEtxYJXgmh.cIL_DsGT.6ImydILcQGhFlSLPqgcpjuJI.9ICiyDeYLxn pYQulAtbqYhuK1zmAtGpzmSS4.QiRdJ0YxHNX3kkM7i.hCtqZP6rVV7x9z_6pl.hiI3siUpKKfbe cFgfBDT4l51EIHZXZa.ja5Sn9PDyvnE4YRJHfJa2TtFWFFVEkaW4qWjSrQffPrXJQtWvNGDAhxSx OfOsBEaIZc49zkpNXxRdJ0ezPmXTmDHbaiC5hChe.n4LzL85bXSL5dS5r6mDe.peJK.xcqJzEmTO 4UP.EZMX37gvTVJTEQkl7xHrW.Mk_ONUsVb78s.NItkNdk38Oe5G3uoJ6LNBh7uJ.Hb003UVddxA gIUExtZ87abeA1onOOe4Eh28I29DhbhHvpWl087DwrCNE4c.oOXrwG5UitOKh7K13BD44OhKE0t9 wAGnsqfPFpI1bcOFFKsFRWIv8uV5hr0bzsn.Q42uz_iE32_xnJBUMyKbP4d8WE6iVtnb0ppycm5Z aEFt20ppvmFWxDFB77JKwEk47NXd0vHXRRJGQm5T2le2nGRTzP48Ft_xd5STWXPt0jAQnmARm1lt oFyXueiQlijak1hCufIcpKRE87AsgMz8NGHn4UtI8JkUy1X4aXuIeBf8_9OlIDeVeg78c.Kfu4k6 lUA9TlPWydTRNqTFWfsM98XhmRE3CTiBm.G9gAUrUyfjcZBGQfO0DpDfyOjBolOZm_wLjwzGTa1B IRVM3.XbLCZJRU4dw9by3M3AQHvnHVoXfX.eZNHSeQJuWvExlsXMvsrXfXZnm35eqUgWsvvOwNdw rJvm3hufTcOjE8tYU.bqFOXJiCwi5elQtrbgkNVDoP3RFt5iIM_0eNvg6IhXH6uVwNw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Sun, 9 Jun 2019 08:49:45 +0000 Received: from c-67-170-167-181.hsd1.or.comcast.net (EHLO [192.168.1.115]) ([67.170.167.181]) by smtp426.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ef1f26641a5e8235579f9327ab4d6227; Sun, 09 Jun 2019 08:49:44 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: crash of 32-bit powerpc -r347549 kernel built via system-clang-8, _init_tls is where the initial DIAGNOSTICS-reported SIGSEGV happens Date: Sun, 9 Jun 2019 01:49:42 -0700 References: <8F272F27-0BC3-402A-810A-4608162F9EEE@yahoo.com> To: FreeBSD Hackers , FreeBSD PowerPC ML In-Reply-To: <8F272F27-0BC3-402A-810A-4608162F9EEE@yahoo.com> Message-Id: <35F598E5-2400-4768-8B39-BC5F9B051443@yahoo.com> X-Mailer: Apple Mail (2.3445.104.11) X-Rspamd-Queue-Id: F2C8E8FD2A X-Spamd-Bar: + X-Spamd-Result: default: False [1.96 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; MV_CASE(0.50)[]; FREEMAIL_FROM(0.00)[yahoo.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: mta6.am0.yahoodns.net]; DKIM_TRACE(0.00)[yahoo.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[yahoo.com]; ASN(0.00)[asn:36646, ipnet:66.163.184.0/21, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[yahoo.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[yahoo.com:s=s2048]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(0.01)[0.008,0]; MIME_GOOD(-0.10)[text/plain]; IP_SCORE(1.51)[ip: (5.16), ipnet: 66.163.184.0/21(1.35), asn: 36646(1.08), country: US(-0.06)]; NEURAL_SPAM_MEDIUM(0.44)[0.441,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_LONG(0.51)[0.513,0]; RCVD_IN_DNSWL_NONE(0.00)[82.189.163.66.list.dnswl.org : 127.0.5.0] X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Jun 2019 08:49:53 -0000 So far I've not been able to find the code that is supposed to establish the value of environ in /sbin/init as matching the value of arginfo->ps_envstr from the exec_copyout_strings use by do_execve in the kernel. Anyone know where to point me to for what I seem to have missed? The issue driving the question is having the *sp++ in _init_tls code below get SIGSEGV on 32-bit FreeBSD when built via system-clang-8 and devel/powerpc64-binutils: sp =3D (Elf_Addr *) environ; while (*sp++ !=3D 0) ; The below is relevant detail that I've found. _start in /sbin/init 's instance of lib/csu/powerpc/crt1.c calls _init_tls that is from lib/libc/gen/tls.c but first might assign to environ : . . . #include "ignore_init.c" . . . void _start(int argc, char **argv, char **env, const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), struct ps_strings *ps_strings) { handle_argv(argc, argv, env); if (ps_strings !=3D (struct ps_strings *)0) __ps_strings =3D ps_strings; if (&_DYNAMIC !=3D NULL) atexit(cleanup); else _init_tls(); #ifdef GCRT atexit(_mcleanup); monstartup(&eprol, &etext); #endif handle_static_init(argc, argv, env); exit(main(argc, argv, env)); } lib/csu/common/ignore_init.c has: char **environ; . . . static inline void handle_argv(int argc, char *argv[], char **env) { const char *s; if (environ =3D=3D NULL) environ =3D env; if (argc > 0 && argv[0] !=3D NULL) { __progname =3D argv[0]; for (s =3D __progname; *s !=3D '\0'; s++) { if (*s =3D=3D '/') __progname =3D s + 1; } } } So _start's char**env argument might be used to assign environ. But either way I've not managed to find the binding to the kernel exec_copyout_strings operation. _init_tls has the *sp++ loop that I referenced earlier: extern char **environ; void _init_tls(void) { #ifndef PIC Elf_Addr *sp; Elf_Auxinfo *aux, *auxp; Elf_Phdr *phdr; size_t phent, phnum; int i; void *tls; sp =3D (Elf_Addr *) environ; while (*sp++ !=3D 0) ; . . . On the kernel side for invoking /sbin/init is . . . =46rom /usr/src/sys/sys/imgact.h : struct image_args { char *buf; /* pointer to string buffer */ void *bufkva; /* cookie for string buffer KVA */ char *begin_argv; /* beginning of argv in buf */ char *begin_envv; /* (interal use only) beginning of envv = in buf, * access with = exec_args_get_begin_envv(). */ char *endp; /* current `end' pointer of arg & env = strings */ char *fname; /* pointer to filename of executable = (system space) */ char *fname_buf; /* pointer to optional malloc(M_TEMP) = buffer */ int stringspace; /* space left in arg & env buffer */ int argc; /* count of argument strings */ int envc; /* count of environment strings */ int fd; /* file descriptor of the executable */ struct filedesc *fdp; /* new file descriptor table */ }; do_execve from sys/kern/kern_exec.c has use, including envc but avoiding begin_envv (via starting from begin_argv): static int do_execve(struct thread *td, struct image_args *args, struct mac *mac_p) { . . . /* * Copy out strings (args and env) and initialize stack base. */ stack_base =3D (*p->p_sysent->sv_copyout_strings)(imgp); =20 The exec_copyout_strings code (accessed via ->sv_copyout_strings) does stack_base =3D (register_t *)vectp; =20 stringp =3D imgp->args->begin_argv; argc =3D imgp->args->argc; envc =3D imgp->args->envc; . . . /* a null vector table pointer separates the argp's from the = envp's */ suword(vectp++, 0); suword(&arginfo->ps_envstr, (long)(intptr_t)vectp); suword32(&arginfo->ps_nenvstr, envc); /* * Fill in environment portion of vector table. */ for (; envc > 0; --envc) { suword(vectp++, (long)(intptr_t)destp); while (*stringp++ !=3D 0) destp++; destp++; } /* end of vector table is a null pointer */ suword(vectp, 0); . . . (=46rom what I've seen for /sbin/init being invoked, envc=3D=3D0 .) The use involves struct ps_strings from /usr/src/sys/sys/exec.h : struct ps_strings { char **ps_argvstr; /* first of 0 or more argument strings = */ unsigned int ps_nargvstr; /* the number of argument strings */ char **ps_envstr; /* first of 0 or more environment = strings */ unsigned int ps_nenvstr; /* the number of environment strings */ }; The initialization of the begin_envv and envc for much of the code seems to trace back to: static void start_init(void *dummy) { struct image_args args; . . . while ((path =3D strsep(&tmp_init_path, ":")) !=3D NULL) { if (bootverbose) printf("start_init: trying %s\n", path); memset(&args, 0, sizeof(args)); . . . =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)