Re: [llvm-dev] [cfe-dev] Issue compiling x86 assembly code with clang

431 views
Skip to first unread message

Hans Wennborg via llvm-dev

unread,
Jul 20, 2017, 10:07:49 AM7/20/17
to ROHIT KUMAR, llvm-dev
(most lists to bcc)

Hi Rohit,

On Thu, Jul 20, 2017 at 11:24 AM, ROHIT KUMAR via cfe-dev
<cfe...@lists.llvm.org> wrote:
> I am trying to compile x86 assembly code with clang, which gets compiled
> successfully with -O1 flag but fails with -O0 flag with below-mentioned
> error:
>
> inline assembly requires more registers than available
> "pushl %%ebx \n\t"
>
>
> The code snippet is something like:
>
> __asm__ (
> "pushl %%ebx \n\t"
> ... // more assembly code
>
> : // No Input
>
> : // 6 output fields
>
> : "%eax", "%ecx", "%esi", "%edi", "memory" // all these clobbers
> );
>
>
> Does anyone have a clue on how should I debug this issue?
>
> Note: This assembly code works fine with gcc.

Please don't post to all mailing lists at once like this.

In this case, I think filing a bug at https://bugs.llvm.org/ would be the best.

Thanks,
Hans
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

ROHIT KUMAR via llvm-dev

unread,
Jul 20, 2017, 1:42:48 PM7/20/17
to Release-testers, llvm-dev, cfe-dev, LLDB Dev, openmp-dev (openmp-dev@lists.llvm.org)
Hey guys,

I am trying to compile x86 assembly code with clang, which gets compiled successfully with -O1 flag but fails with -O0 flag with below-mentioned error:

inline assembly requires more registers than available
                  "pushl       %%ebx           \n\t"


The code snippet is something like:

__asm__ (
           "pushl       %%ebx           \n\t"
             ... // more assembly code 

          : // No Input

          : // 6 output fields

          : "%eax", "%ecx", "%esi", "%edi", "memory" // all these clobbers 
 );


Does anyone have a clue on how should I debug this issue? 

Note: This assembly code works fine with gcc.

Thanks. 
Rohit

Joerg Sonnenberger via llvm-dev

unread,
Jul 20, 2017, 2:55:16 PM7/20/17
to ROHIT KUMAR, llvm-dev
On Thu, Jul 20, 2017 at 02:54:07PM +0530, ROHIT KUMAR via cfe-dev wrote:
> Hey guys,
>
> I am trying to compile *x86 assembly code* with clang, which gets compiled

> successfully with -O1 flag but fails with -O0 flag with below-mentioned
> error:
>
> inline assembly requires more registers than available

Well, keep in mind that there are only six general purpose register on
i386 and %ebx might still be reserved for the GOT in PIC code. Combine
that with the fast register allocator and code generator being somewhat
dumb and I'm not surprised at all, that this is failing. Sorry, though
luck -- it is unlikely to be fixed really.

> Note: This assembly code works fine with gcc.

Across all reasonable set of versions and optimization levels? I would
be surprised. GCC has a long history of rejecting dumb cpuid inline
assembler macros. Your best bet is very likely to reduce the clobber
list further to give the compiler some breathing room.

Joerg

Reply all
Reply to author
Forward
0 new messages