From owner-freebsd-hackers@freebsd.org Mon Dec 3 04:07:59 2018 Return-Path: Delivered-To: freebsd-hackers@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 653C31314AB6 for ; Mon, 3 Dec 2018 04:07:59 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic307-12.consmr.mail.ne1.yahoo.com (sonic307-12.consmr.mail.ne1.yahoo.com [66.163.190.35]) (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 BAB656FC1D for ; Mon, 3 Dec 2018 04:07:58 +0000 (UTC) (envelope-from marklmi@yahoo.com) X-YMail-OSG: THA7kCUVM1lnLii57wr8yjcfhE8qIGzw0vOCLKNlaQ8DJofdw5ffE23b8gCRPXR 4GF6b6lpruHpyFFz4IxRmz4oupj9H659hC7VJTpO_5EBGJod2odb5iMKiopMu4L2_ig9snXreMQd ha.FjsKcjsrNOet9PvxlcrM3JaPPWFSXYUu2zUycjtPfzZE0HtdudyJT5W48RuxxNXdnEa9rIZhT 2abRPCflxUTIstyXpKVTD4N5g8KPBJAf47V5Zfu.JfiXlVmMb_BIh8Uy0ewvugCau.bzItwMOslr 1e.k0fHlj2FeWR3RT5jV.XQ.h7Q72IZvwoIzamaDZRlbGYXNo7SP3xpypw9dxyUHZg3ZR.4ePJ6E FoqcGHA_qyvp4vU3X2TsY3WfzNWlP1eodk8HofEmz5mKg_t1jpJ5Fu4hQpOEixilbTI9LwmhXZo1 GGhIwtUmqcvvIIvBq8Z7raJV1h9sOtxamkbkdGkbpdkz1njA2OwlL_KST9zcgJicB6IJqAji_hkU wYYqnXGVgFFEIRRMsO9O4F1drS8oBTB5S8mg72UV4wZwXu8ZIJqMcNjaHPEDSF9TKUNCZ.OOhR1I cFoaw1lwoUA1mYZqFaFRAGZUePvrazXEeSlKz4ot2d1k_e.mvl3qnH.R5SNDiIb8oyncEkIVFqji urdhu0Q8Nb5kohFph7Q2RWkr6HYSbUMupbxCdqfh5RQvn9z6i7MmQWI8xwwwIyzsFLFpRVMi5k2a teB6TRybwubSs4Q_dgH4YhfviIFhghp4fIXCfiIBlThrjsz1BT2yq4E0OllP7mryjVF5cQ2p78uI yzfU3UtVB0NLCBG0_l_Sb_5YF0t4mh4xwEomRIYOiGKjnBFhYwHgBVR8_WLNL6lxceCxntgHJQkA lW1g6YSNTb8MuAoB.vkeYeCpkQbShJJ3ComFBLcHuthFVrEoM4bl6G6ygesXPKPNlI9mbrOkRkn7 mJcrm0TomaZ8bM5C2Dtw.PQc.QbN6Uq9cdYq7truj0DHoiYn7rR1jyuiyn8_TYhtXwzMM3yKwEW. P0AAjc..03OEmrGBaT25.781OhJLiTKe.kocu_5mxG6PZQbJfmdkrqz.lJgU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Mon, 3 Dec 2018 04:07:52 +0000 Received: from c-67-170-167-181.hsd1.or.comcast.net (EHLO [192.168.1.109]) ([67.170.167.181]) by smtp410.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0abc309ed31810f102ce0da15dc4718a; Mon, 03 Dec 2018 04:07:52 +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.1 \(3445.101.1\)) Subject: How to get /lib/libgcc_s.so.1 's thrown exception handling to work for the likes of powerpc64 with buildworld via devel/powerpc64-xtoolchain-gcc Message-Id: <502FA1DF-65C2-41B6-BF10-7E712CD44BA9@yahoo.com> Date: Sun, 2 Dec 2018 20:07:50 -0800 To: FreeBSD PowerPC ML , freebsd-hackers Hackers X-Mailer: Apple Mail (2.3445.101.1) X-Rspamd-Queue-Id: BAB656FC1D X-Spamd-Result: default: False [0.36 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[yahoo.com]; NEURAL_HAM_MEDIUM(-0.20)[-0.203,0]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_FROM(0.00)[yahoo.com]; NEURAL_HAM_LONG(-0.66)[-0.658,0]; NEURAL_SPAM_SHORT(0.99)[0.993,0]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[yahoo.com:+]; MX_GOOD(-0.01)[cached: mta6.am0.yahoodns.net]; RCVD_IN_DNSWL_NONE(0.00)[35.190.163.66.list.dnswl.org : 127.0.5.0]; RCPT_COUNT_TWO(0.00)[2]; IP_SCORE(0.74)[ip: (1.33), ipnet: 66.163.184.0/21(1.36), asn: 36646(1.09), country: US(-0.09)]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; 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)[] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Dec 2018 04:07:59 -0000 [This is without the longer term technique of getting llvm's libunwind working.] The code changes in my example are deliberately set up to approximately minimize the number of lines with textual changes. The patching fixes the handling of DW_CFA_remember_state and DW_CFA_restore_state . Without the changes _Unwind_RaiseException can end up looping looking at the same frame over and over when DW_CFA_remember_state and DW_CFA_restore_state are in use. While gcc 4.2.1 generally avoids these, more modern toolchains use them. # svnlite diff --diff-cmd diff -x "-U12" = /usr/src/contrib/gcc/unwind-dw2.* Index: /usr/src/contrib/gcc/unwind-dw2.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- /usr/src/contrib/gcc/unwind-dw2.c (revision 340287) +++ /usr/src/contrib/gcc/unwind-dw2.c (working copy) @@ -949,32 +949,40 @@ case DW_CFA_remember_state: { struct frame_state_reg_info *new_rs; if (unused_rs) { new_rs =3D unused_rs; unused_rs =3D unused_rs->prev; } else new_rs =3D alloca (sizeof (struct frame_state_reg_info)); *new_rs =3D fs->regs; + new_rs->cfa_offset =3D fs->cfa_offset; + new_rs->cfa_reg =3D fs->cfa_reg; + new_rs->cfa_exp =3D fs->cfa_exp; + new_rs->cfa_how =3D fs->cfa_how; fs->regs.prev =3D new_rs; } break; case DW_CFA_restore_state: { struct frame_state_reg_info *old_rs =3D fs->regs.prev; fs->regs =3D *old_rs; + fs->cfa_offset =3D fs->regs.cfa_offset; + fs->cfa_reg =3D fs->regs.cfa_reg; + fs->cfa_exp =3D fs->regs.cfa_exp; + fs->cfa_how =3D fs->regs.cfa_how; old_rs->prev =3D unused_rs; unused_rs =3D old_rs; } break; case DW_CFA_def_cfa: insn_ptr =3D read_uleb128 (insn_ptr, &fs->cfa_reg); insn_ptr =3D read_uleb128 (insn_ptr, &utmp); fs->cfa_offset =3D utmp; fs->cfa_how =3D CFA_REG_OFFSET; break; Index: /usr/src/contrib/gcc/unwind-dw2.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- /usr/src/contrib/gcc/unwind-dw2.h (revision 340287) +++ /usr/src/contrib/gcc/unwind-dw2.h (working copy) @@ -28,60 +28,70 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* A target can override (perhaps for backward compatibility) how many dwarf2 columns are unwound. */ #ifndef DWARF_FRAME_REGISTERS #define DWARF_FRAME_REGISTERS FIRST_PSEUDO_REGISTER #endif /* The result of interpreting the frame unwind info for a frame. This is all symbolic at this point, as none of the values can be resolved until the target pc is located. */ +enum frame_state_cfa_how_values { + CFA_UNSET, + CFA_REG_OFFSET, + CFA_EXP +}; typedef struct { /* Each register save state can be described in terms of a CFA slot, another register, or a location expression. */ struct frame_state_reg_info { struct { union { _Unwind_Word reg; _Unwind_Sword offset; const unsigned char *exp; } loc; enum { REG_UNSAVED, REG_SAVED_OFFSET, REG_SAVED_REG, REG_SAVED_EXP, REG_SAVED_VAL_OFFSET, REG_SAVED_VAL_EXP } how; } reg[DWARF_FRAME_REGISTERS+1]; /* Used to implement DW_CFA_remember_state. */ struct frame_state_reg_info *prev; + + /* The following are just for DW_CFA_{remember,restore}_state + handling. */ + /* The CFA can be described in terms of a reg+offset or a + location expression. */ + _Unwind_Sword cfa_offset; + _Unwind_Word cfa_reg; + const unsigned char *cfa_exp; + enum frame_state_cfa_how_values cfa_how; } regs; /* The CFA can be described in terms of a reg+offset or a location expression. */ _Unwind_Sword cfa_offset; _Unwind_Word cfa_reg; const unsigned char *cfa_exp; - enum { - CFA_UNSET, - CFA_REG_OFFSET, - CFA_EXP - } cfa_how; + enum frame_state_cfa_how_values cfa_how; /* The PC described by the current frame state. */ void *pc; /* The information we care about from the CIE/FDE. */ _Unwind_Personality_Fn personality; _Unwind_Sword data_align; _Unwind_Word code_align; _Unwind_Word retaddr_column; unsigned char fde_encoding; unsigned char lsda_encoding; unsigned char saw_z; Without such changes building devel/gdb and devel/kyua via, say, g++8 but still binding to /lib/libgcc_s.so.1 leads to failure of both programs: both make use of thrown c++ exceptions in normal operation and DW_CFA_remember_state and DW_CFA_restore_state end up involved. Even the following program fails, looping in __Unwind_RaiseException: #include // -O2 context used (but not required for the problem // to occur). volatile unsigned int v =3D 1; extern int f() { volatile unsigned char c =3D 'a'; v++; // despite volatile the access to v in g // was otherwise optimized out and the // std::exception was not followed by // code for f(). return c; } extern void g() { if (v) throw std::exception(); f(); // ends up inlined but the problem is demonstrated. } int main(void) { try {g();} // Used a separate function to avoid any potential // special handling of code in main. Call not // optimized out. catch (std::exception& e) {f();} return 0; } Previous to the changes the following were classified as broken by timing out without completing: # kyua report lib/atf/libatf-c++/detail/exceptions_test =3D=3D=3D> Summary Results read from = /root/.kyua/store/results.usr_tests.20181203-001618-953311.db Test cases: 3 total, 0 skipped, 0 expected failures, 0 broken, 0 failed Total time: 0.064s Using a gcc 4.2.1 based kernel and a devel/powerpc64-xtoolchain-gcc based world, I've done a complete kyua test -k /usr/tests/Kyuafile that completed. (The above report is based on that run.) The reason for the gcc 4.2.1 kernel is the crash in vnet_epair_init during the kyua test -k /usr/tests/Kyuafile run when the kernel was built by devel/powerpc64-xtoolchain-gcc . The linkage/relocation and vnet's code do not seem to be matched when devel/powerpc64-xtoolchain-gcc is used to build the kernel. =3D=3D=3D Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)