From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: hjl.tools@gmail.com
Cc: gdb-patches@sourceware.org
Subject: Re: PATCH: Check bfd_mach_x64_32 to set tdesc for x32 binary
Date: Mon, 14 May 2012 18:42:00 -0000 [thread overview]
Message-ID: <201205141842.q4EIgXAV016110@glazunov.sibelius.xs4all.nl> (raw)
In-Reply-To: <CAMe9rOo8ydDn_AqiVmnM7ccjtnfQHNUvxOfwA9QKsCXHxdMo2A@mail.gmail.com> (hjl.tools@gmail.com)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5411 bytes --]
> Date: Fri, 11 May 2012 16:13:04 -0700
> From: "H.J. Lu" <hjl.tools@gmail.com>
>
> On Fri, May 11, 2012 at 1:20 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
> >> Hi,
> >>
> >> This patch checks bfd_mach_x64_32 to set tdesc for x32 binary. Tested
> >> on Linux/x86-64. OK to install?
> >>
> >> Thanks.
> >>
> >>
> >> H.J.
> >> ---
> >> * amd64-linux-tdep.c: Include features/i386/x32-linux.c
> >> and features/i386/x32-avx-linux.c.
> >> (amd64_linux_init_abi): Check bfd_mach_x64_32 for x32 process.
> >> (_initialize_amd64_linux_tdep): Register bfd_mach_x64_32. Call
> >> initialize_tdesc_x32_linux and initialize_tdesc_x32_avx_linux.
> >>
> >> * amd64-linux-tdep.h (tdesc_x32_linux): New.
> >> (tdesc_x32_avx_linux): Likewise.
> >>
> >> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> >> index acc7303..601ce20 100644
> >> --- a/gdb/amd64-linux-tdep.c
> >> +++ b/gdb/amd64-linux-tdep.c
> >> @@ -1545,8 +1578,12 @@ _initialize_amd64_linux_tdep (void)
> >> {
> >> gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
> >> GDB_OSABI_LINUX, amd64_linux_init_abi);
> >> + gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32,
> >> + GDB_OSABI_LINUX, amd64_linux_init_abi);
> >
> > Instead of doing this, you should introduce an
> > amd64_x32_linux_init_abi() function, make that call amd64_linix_init_abi() and ovverride the bits that are different for X32.
>
> I don't think I should override tdep->tdesc. Here is a different approach.
> I updated amd64_linux_init_abi to take amd64_linux_tdesc and fetch_func.
> I also added amd64_lp64_linux_init_abi and amd64_ilp32_linux_init_abi
> to pass the right ones to amd64_linux_init_abi. Tested on Linux/x86-64.
> OK to install?
No. Sorry, but you missed my point. I want you to introduce a
seperate function such that it will be easy to override stuff
specifically for x32 without adding lots of if statements that turn
the code into spaghetti.
> --
> H.J.
> --
> * amd64-linux-tdep.c (amd64_linux_init_abi): Add 2 arguments,
> amd64_linux_tdesc and fetch_func. Replace tdesc_amd64_linux
> with amd64_linux_tdesc and svr4_lp64_fetch_link_map_offsets
> with fetch_func.
> (amd64_lp64_linux_init_abi): New function.
> (amd64_ilp32_linux_init_abi): Likewise.
> (_initialize_amd64_linux_tdep): Replace amd64_linux_init_abi
> with amd64_lp64_linux_init_abi. Register bfd_mach_x64_32 with
> amd64_ilp32_linux_init_abi. Call initialize_tdesc_x32_linux
> and initialize_tdesc_x32_avx_linux.
>
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index cfe6e4b..e68d70f 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -1288,7 +1288,9 @@ amd64_linux_core_read_description (struct
> gdbarch *gdbarch,
> }
>
> static void
> -amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> +amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
> + const struct target_desc *amd64_linux_tdesc,
> + struct link_map_offsets *(*fetch_func) (void))
> {
> struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
> const struct target_desc *tdesc = info.target_desc;
> @@ -1310,7 +1312,7 @@ amd64_linux_init_abi (struct gdbarch_info info,
> struct gdbarch *gdbarch)
> set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
>
> if (! tdesc_has_registers (tdesc))
> - tdesc = tdesc_amd64_linux;
> + tdesc = amd64_linux_tdesc;
> tdep->tdesc = tdesc;
>
> feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
> @@ -1331,8 +1333,7 @@ amd64_linux_init_abi (struct gdbarch_info info,
> struct gdbarch *gdbarch)
> tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
>
> /* GNU/Linux uses SVR4-style shared libraries. */
> - set_solib_svr4_fetch_link_map_offsets
> - (gdbarch, svr4_lp64_fetch_link_map_offsets);
> + set_solib_svr4_fetch_link_map_offsets (gdbarch, fetch_func);
>
> /* Add the %orig_rax register used for syscall restarting. */
> set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc);
> @@ -1543,6 +1544,22 @@ amd64_linux_init_abi (struct gdbarch_info info,
> struct gdbarch *gdbarch)
>
> tdep->i386_syscall_record = amd64_linux_syscall_record;
> }
> +
> +static void
> +amd64_lp64_linux_init_abi (struct gdbarch_info info,
> + struct gdbarch *gdbarch)
> +{
> + amd64_linux_init_abi (info, gdbarch, tdesc_amd64_linux,
> + svr4_lp64_fetch_link_map_offsets);
> +}
> +
> +static void
> +amd64_ilp32_linux_init_abi (struct gdbarch_info info,
> + struct gdbarch *gdbarch)
> +{
> + amd64_linux_init_abi (info, gdbarch, tdesc_x32_linux,
> + svr4_ilp32_fetch_link_map_offsets);
> +}
>
>
>
> /* Provide a prototype to silence -Wmissing-prototypes. */
> @@ -1552,9 +1569,13 @@ void
> _initialize_amd64_linux_tdep (void)
> {
> gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
> - GDB_OSABI_LINUX, amd64_linux_init_abi);
> + GDB_OSABI_LINUX, amd64_lp64_linux_init_abi);
> + gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32,
> + GDB_OSABI_LINUX, amd64_ilp32_linux_init_abi);
>
> /* Initialize the Linux target description. */
> initialize_tdesc_amd64_linux ();
> initialize_tdesc_amd64_avx_linux ();
> + initialize_tdesc_x32_linux ();
> + initialize_tdesc_x32_avx_linux ();
> }
>
>
next prev parent reply other threads:[~2012-05-14 18:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 19:30 H.J. Lu
2012-05-11 20:20 ` Mark Kettenis
2012-05-11 23:13 ` H.J. Lu
2012-05-14 18:10 ` H.J. Lu
2012-05-14 18:42 ` Mark Kettenis [this message]
2012-05-14 19:02 ` H.J. Lu
2012-05-11 20:31 ` Mark Kettenis
2012-05-11 20:56 ` H.J. Lu
2012-05-12 1:38 ` Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201205141842.q4EIgXAV016110@glazunov.sibelius.xs4all.nl \
--to=mark.kettenis@xs4all.nl \
--cc=gdb-patches@sourceware.org \
--cc=hjl.tools@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox