This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gdb: x86: fix x32 builds with inline asm


On Tue, Jan 8, 2013 at 7:01 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> The inline assembly fails with x32 targets due to pushq used with a 32bit
> register.  Since the assembler can do the right thing with a "push" insn
> and a 32bit or 64bit register (i.e. it'll pushl or pushq as needed), just
> use that insn.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>
> 2012-01-08  Mike Frysinger  <vapier@gentoo.org>
>
>         * common/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Change pushl
>         to push in i386 inline asm and %esp to sp.  Delete __i386__ check
>         and __x86_64__ inline asm.
> ---
> Note: I'm not 100% on the "sp" constraint.  Seems to work, and reading
>         the gcc constraints list looks like it aliases sp/esp/rsp to the same
>         thing.
>
>  gdb/common/linux-ptrace.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/gdb/common/linux-ptrace.c b/gdb/common/linux-ptrace.c
> index 761ef59..abb502c 100644
> --- a/gdb/common/linux-ptrace.c
> +++ b/gdb/common/linux-ptrace.c
> @@ -103,21 +103,11 @@ linux_ptrace_test_ret_to_nx (void)
>                  strerror (errno));
>        else
>         {
> -#if defined __i386__
> -         asm volatile ("pushl %0;"
> -                       ".globl linux_ptrace_test_ret_to_nx_instr;"
> -                       "linux_ptrace_test_ret_to_nx_instr:"
> -                       "ret"
> -                       : : "r" (return_address) : "%esp", "memory");
> -#elif defined __x86_64__
> -         asm volatile ("pushq %0;"
> +         asm volatile ("push %0;"
>                         ".globl linux_ptrace_test_ret_to_nx_instr;"
>                         "linux_ptrace_test_ret_to_nx_instr:"
>                         "ret"
> -                       : : "r" (return_address) : "%rsp", "memory");
> -#else
> -# error "!__i386__ && !__x86_64__"
> -#endif
> +                       : : "r" (return_address) : "sp", "memory");
>           gdb_assert_not_reached ("asm block did not terminate");
>         }
>

I think we should keep

#else
# error "!__i386__ && !__x86_64__"
#endif

Thanks.

-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]