From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21290 invoked by alias); 8 Jan 2013 16:54:43 -0000 Received: (qmail 21274 invoked by uid 22791); 8 Jan 2013 16:54:40 -0000 X-SWARE-Spam-Status: No, hits=-3.8 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-qc0-f177.google.com (HELO mail-qc0-f177.google.com) (209.85.216.177) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Jan 2013 16:54:33 +0000 Received: by mail-qc0-f177.google.com with SMTP id u28so829727qcs.36 for ; Tue, 08 Jan 2013 08:54:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.224.100.130 with SMTP id y2mr5077298qan.40.1357664072593; Tue, 08 Jan 2013 08:54:32 -0800 (PST) Received: by 10.49.12.210 with HTTP; Tue, 8 Jan 2013 08:54:32 -0800 (PST) In-Reply-To: <201301081059.40723.vapier@gentoo.org> References: <1357657280-24150-1-git-send-email-vapier@gentoo.org> <201301081059.40723.vapier@gentoo.org> Date: Tue, 08 Jan 2013 16:54:00 -0000 Message-ID: Subject: Re: [PATCH] gdb: x86: fix x32 builds with inline asm From: "H.J. Lu" To: Mike Frysinger Cc: gdb-patches@sourceware.org, jan.kratochvil@redhat.com Content-Type: text/plain; charset=ISO-8859-1 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: 2013-01/txt/msg00138.txt.bz2 On Tue, Jan 8, 2013 at 7:59 AM, Mike Frysinger wrote: > On Tuesday 08 January 2013 10:01:20 Mike Frysinger wrote: >> -#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"); > > hrm, this works for -m32 and -m64, but doesn't actually help with -mx32. this > doesn't seem to line up with my expectations. can you suggest something here > H.J. Lu ? > > $ cat test.c > main() { asm volatile ("push %0; ret;" : : "r"(main) : "sp", "memory"); } > > $ gcc -m32 test.c > 8: 50 push %eax > 9: c3 ret > > $ gcc -m64 test.c > 9: 50 push %rax > a: c3 retq > > $ gcc -mx32 test.c > test.c: Assembler messages: > test.c:2: Error: operand type mismatch for `push' > -mike Can you try this? -- H.J. --- diff --git a/gdb/common/linux-ptrace.c b/gdb/common/linux-ptrace.c index 761ef59..cc08b6a 100644 --- a/gdb/common/linux-ptrace.c +++ b/gdb/common/linux-ptrace.c @@ -103,21 +103,16 @@ 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"); +#ifdef __x86_64__ + : : "r" ((uint64_t) (uintptr_t) (return_address)) #else -# error "!__i386__ && !__x86_64__" + : : "r" (return_address) #endif + : "sp", "memory"); gdb_assert_not_reached ("asm block did not terminate"); }