From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27826 invoked by alias); 28 May 2012 21:18:29 -0000 Received: (qmail 27817 invoked by uid 22791); 28 May 2012 21:18:28 -0000 X-SWARE-Spam-Status: No, hits=-5.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-qa0-f48.google.com (HELO mail-qa0-f48.google.com) (209.85.216.48) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 May 2012 21:18:14 +0000 Received: by qady23 with SMTP id y23so1196020qad.14 for ; Mon, 28 May 2012 14:18:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.114.203 with SMTP id f11mr3009948qcq.10.1338239894090; Mon, 28 May 2012 14:18:14 -0700 (PDT) Received: by 10.229.169.130 with HTTP; Mon, 28 May 2012 14:18:14 -0700 (PDT) In-Reply-To: <201205282026.q4SKQ737007589@glazunov.sibelius.xs4all.nl> References: <20120511181737.GP29339@adacore.com> <201205202043.q4KKhRGw022215@glazunov.sibelius.xs4all.nl> <201205202138.q4KLcWBf011913@glazunov.sibelius.xs4all.nl> <201205282026.q4SKQ737007589@glazunov.sibelius.xs4all.nl> Date: Mon, 28 May 2012 21:18:00 -0000 Message-ID: Subject: Re: x32 ABI Support (was Re: Three weeks to branching (gdb 7.5 release)) From: "H.J. Lu" To: Mark Kettenis Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-05/txt/msg01004.txt.bz2 On Mon, May 28, 2012 at 1:26 PM, Mark Kettenis wr= ote: >> Date: Sun, 20 May 2012 15:48:54 -0700 >> From: "H.J. Lu" >> >> Does this one look OK. =A0I extracted x32_init_abi from amd64_x32_init_a= bi >> since amd64_x32_linux_init_abi can't call amd64_init_abi after >> calling amd64_linux_init_abi. > > I guess multiple-inheritance is a bad idea, even when implemented in C ;) > > I really do think that amd64_x32_linux_init_abi() should call > amd64_x32_init_abi(). =A0That way it is immediately obvious that the OS-s= pecific ABI inherits everything from the generic ABI. X32 kernel interface are highly OS specific. Different OSes can implement very different kernel interfaces. The only generic x32 bits are struct gdbarch_tdep *tdep =3D gdbarch_tdep (gdbarch); tdep->num_dword_regs =3D 17; set_tdesc_pseudo_register_type (gdbarch, amd64_x32_pseudo_register_type); set_gdbarch_long_bit (gdbarch, 32); set_gdbarch_ptr_bit (gdbarch, 32); They are the same for all x32 OSes since they are determined by hardware, not OS. > In order too avoid too much code duplication, the common bits should > be split out from amd64_linux_init_abi() into a seperate function that > gets called from both amd64_linux_init_abi() and > amd64_x32_linux_init_abi(). =A0As I wrote earlier, it isn't entirely > obvious that everything in amd64_linix_init_abi() applies to the x32 > ABI. =A0So we should be conservative in moving stuff into the common > function. =A0In fact it might be a good idea to start out with something > like the attached diff, and gradually move things over. Linux x32 kernel interface shares > 90% of Linux amd64 kernel interface (309 system calls out of 337 are the same). See 64-bit system call table in Linux kernel 3.4: http://git.kernel.org/?p=3Dlinux/kernel/git/stable/linux-stable.git;a=3Dblo= b;f=3Darch/x86/syscalls/syscall_64.tbl;h=3Ddd29a9ea27c560a9d2fcb6e1c2983f8b= 8e9be407;hb=3DHEAD I believe we should start with sharing everything between Linux/x32 and Linux/amd64. We can update x32 part as we go. > Cheers, > > Mark > > Index: amd64-linux-tdep.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 > RCS file: /cvs/src/src/gdb/amd64-linux-tdep.c,v > retrieving revision 1.50 > diff -u -p -r1.50 amd64-linux-tdep.c > --- amd64-linux-tdep.c =A012 May 2012 08:54:03 -0000 =A0 =A0 =A01.50 > +++ amd64-linux-tdep.c =A028 May 2012 20:24:28 -0000 > @@ -1298,8 +1298,6 @@ amd64_linux_init_abi (struct gdbarch_inf > > =A0 gdb_assert (tdesc_data); > > - =A0linux_init_abi (info, gdbarch); > - > =A0 tdep->gregset_reg_offset =3D amd64_linux_gregset_reg_offset; > =A0 tdep->gregset_num_regs =3D ARRAY_SIZE (amd64_linux_gregset_reg_offset= ); > =A0 tdep->sizeof_gregset =3D 27 * 8; > @@ -1323,6 +1321,8 @@ amd64_linux_init_abi (struct gdbarch_inf > =A0 if (!valid_p) > =A0 =A0 return; > > + =A0linux_init_abi (info, gdbarch); > + > =A0 tdep->sigtramp_p =3D amd64_linux_sigtramp_p; > =A0 tdep->sigcontext_addr =3D amd64_linux_sigcontext_addr; > =A0 tdep->sc_reg_offset =3D amd64_linux_sc_reg_offset; > @@ -1543,6 +1543,44 @@ amd64_linux_init_abi (struct gdbarch_inf > > =A0 tdep->i386_syscall_record =3D amd64_linux_syscall_record; > =A0} > + > +static void > +amd64_x32_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbar= ch) > +{ > + =A0struct gdbarch_tdep *tdep =3D gdbarch_tdep (gdbarch); > + =A0const struct target_desc *tdesc =3D info.target_desc; > + > + =A0gdb_assert (tdesc_data); > + > + =A0tdep->gregset_reg_offset =3D amd64_linux_gregset_reg_offset; > + =A0tdep->gregset_num_regs =3D ARRAY_SIZE (amd64_linux_gregset_reg_offse= t); > + =A0tdep->sizeof_gregset =3D 27 * 8; > + > + =A0amd64_x32_init_abi (info, gdbarch); > + > + =A0/* Reserve a number for orig_rax. =A0*/ > + =A0set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS); > + > + =A0if (! tdesc_has_registers (tdesc)) > + =A0 =A0tdesc =3D tdesc_x32_linux; > + =A0tdep->tdesc =3D tdesc; > + > + =A0feature =3D tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux"); > + =A0if (feature =3D=3D NULL) > + =A0 =A0return; > + > + =A0valid_p =3D tdesc_numbered_register (feature, tdesc_data, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= AMD64_LINUX_ORIG_RAX_REGNUM, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= "orig_rax"); > + =A0if (!valid_p) > + =A0 =A0return; > + > + =A0linux_init_abi (info, gdbarch); > + > + =A0/* GNU/Linux uses SVR4-style shared libraries. =A0*/ > + =A0set_solib_svr4_fetch_link_map_offsets > + =A0 =A0(gdbarch, svr4_ilp32_fetch_link_map_offsets); > +} These won't work for x32. We have to copy almost everything in amd64_linux_init_abi. > +void > +amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) > +{ > + =A0struct gdbarch_tdep *tdep =3D gdbarch_tdep (gdbarch); > + =A0const struct target_desc *tdesc =3D info.target_desc; > + > + =A0amd64_init_abi (info, gdbarch); > + > + =A0if (! tdesc_has_registers (tdesc)) > + =A0 =A0tdesc =3D tdesc_x32; > + =A0tdep->tdesc =3D tdesc; > + > + =A0tdep->num_dword_regs =3D 17; > + =A0set_tdesc_pseudo_register_type (gdbarch, amd64_x32_pseudo_register_t= ype); > + > + =A0set_gdbarch_long_bit (gdbarch, 32); > + =A0set_gdbarch_ptr_bit (gdbarch, 32); > +} > I think this is the wrong approach for x32 support. We should break amd64_x32_init_abi into 2 parts: 1. OS specific part. It should be private to amd64-tdep.c. 2. Generic part. It should be exported from amd64-tdep.c and can be used by all x32 OSes. Thanks. --=20 H.J.