[LLVMdev] how to compile asm output for x86 with Micorsoft's ML

206 views
Skip to first unread message

Jim Crafton

unread,
Jan 21, 2010, 3:26:39 PM1/21/10
to llv...@cs.uiuc.edu
I was recently trying to compile some bitcode generated like so:

llc --x86-asm-syntax=intel test.out

it generates a test.out.s file, and while I'm not much of an assembly
person, it looks OK. When I feed this to ML

ml test.out.s

I get tons of errors, most of which appear to be syntax errors. Stuff like:

test.out.s(2) : error A2008:syntax error : .
error A2008:syntax error : objc_class_name_Fraction

etc. Is it possible to generate X86 code that Microsoft's assembler
will accept? Is there another option that I missed? I looked around a
bit but couldn't find anything. The example on the llvm site mentions
being able to compile to C code, but when I try
llc -march=c test.out

it errors out with:
error: invalid target 'c'.

Checking the code (I built LLVM 2.7svn) it looks like the C target
isn't registered, and llc -version gives me:
llc -version
Low Level Virtual Machine (http://llvm.org/):
llvm version 2.7svn
DEBUG build with assertions.
Built Jan 20 2010 (14:58:43).
Host: i686-pc-win32
Host CPU: core2

Registered Targets:
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64

Cheers

Jim
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Óscar Fuentes

unread,
Jan 21, 2010, 3:35:43 PM1/21/10
to llv...@cs.uiuc.edu
Jim Crafton <jim.c...@gmail.com> writes:

[snip]

> I looked around a bit but couldn't find anything. The example on the
> llvm site mentions being able to compile to C code, but when I try llc
> -march=c test.out
>
> it errors out with:
> error: invalid target 'c'.

[snip]

> Registered Targets:
> x86 - 32-bit X86: Pentium-Pro and above
> x86-64 - 64-bit X86: EM64T and AMD64

By default, the cmake build generates Visual Studio project files for
the X86 target only. Take a look at

http://www.llvm.org/docs/CMake.html#llvmvars

for learning how to build other targets.

IIRC, the C target is named CBackend.

Jim Crafton

unread,
Jan 21, 2010, 3:54:53 PM1/21/10
to llv...@cs.uiuc.edu
> By default, the cmake build generates Visual Studio project files for
> the X86 target only. Take a look at
>
> http://www.llvm.org/docs/CMake.html#llvmvars
>
> for learning how to build other targets.

OK thanks, I'll look at that.

In the meantime, is it possible to get the assembly generated by llc
to work wiht ML? That would probably be the ideal solution.

Cheers

Jim

Chris Lattner

unread,
Jan 21, 2010, 4:31:05 PM1/21/10
to Jim Crafton, llv...@cs.uiuc.edu

On Jan 21, 2010, at 12:54 PM, Jim Crafton wrote:

>> By default, the cmake build generates Visual Studio project files for
>> the X86 target only. Take a look at
>>
>> http://www.llvm.org/docs/CMake.html#llvmvars
>>
>> for learning how to build other targets.
>
> OK thanks, I'll look at that.
>
> In the meantime, is it possible to get the assembly generated by llc
> to work wiht ML? That would probably be the ideal solution.

Nope, llvm's .s output is only compatible with GAS and other at&t
syntax assemblers. It turns out that MASM syntax is highly ambiguous
and MASM is not production quality for use by a compiler. This is why
visual studio doesn't go through it. Long term, we'd like LLVM to be
able to write out .o files directly, if you're interested in adding
PECOFF support, that would be very nice :)

-Chris

Jim Crafton

unread,
Jan 21, 2010, 5:01:07 PM1/21/10
to llv...@cs.uiuc.edu
> Nope, llvm's .s output is only compatible with GAS and other at&t syntax
> assemblers.  It turns out that MASM syntax is highly ambiguous and MASM is
> not production quality for use by a compiler.  This is why visual studio
> doesn't go through it.  Long term, we'd like LLVM to be able to write out .o
> files directly, if you're interested in adding PECOFF support, that would be
> very nice :)

Crapola. I was afraid that was going to be the case. This was
originally something to do to have fun playing with Objective C, I'm
not sure PECOFF support would fall under that :) Any idea how nasty
that would be?
Oh well, I guess the idea of doing this on windows isn't going to
happen anytime soon.


Cheers

Jim

Chris Lattner

unread,
Jan 21, 2010, 5:56:52 PM1/21/10
to Jim Crafton, llv...@cs.uiuc.edu

On Jan 21, 2010, at 2:01 PM, Jim Crafton wrote:

>> Nope, llvm's .s output is only compatible with GAS and other at&t
>> syntax
>> assemblers. It turns out that MASM syntax is highly ambiguous and
>> MASM is
>> not production quality for use by a compiler. This is why visual
>> studio
>> doesn't go through it. Long term, we'd like LLVM to be able to
>> write out .o
>> files directly, if you're interested in adding PECOFF support, that
>> would be
>> very nice :)
>
> Crapola. I was afraid that was going to be the case. This was
> originally something to do to have fun playing with Objective C, I'm
> not sure PECOFF support would fall under that :) Any idea how nasty
> that would be?
> Oh well, I guess the idea of doing this on windows isn't going to
> happen anytime soon.

Why not just install the cygwin assembler?

罗勇刚(Yonggang Luo)

unread,
Jan 21, 2010, 10:20:17 PM1/21/10
to Jim Crafton, LLVM Dev
Did pecoff support means we can linkage llvm generated obj files to
msvc's obj files?

2010/1/22, Jim Crafton <jim.c...@gmail.com>:

--
从我的移动设备发送

此致

罗勇刚
Yours
sincerely,
Yonggang Luo

Jim Crafton

unread,
Jan 22, 2010, 9:09:26 AM1/22/10
to llv...@cs.uiuc.edu
It would be nice to be able to use clang/llvm without GNU toolchain
dependencies. Just out of curioisty what does the
--x86-asm-syntax=intel actually mean then? Does this not get used? Is
this a different syntax than the AT&T variety (forgive me if this is
an obvious question)?

I tried downloading FASM last night and it seemed handle some of the
output, the one thing it didn't like was the string variable. It
complained about

mov DWORD PTR [ESP], ($_.str)

something about "$_.str" wasn't kosher.

On Thu, Jan 21, 2010 at 5:56 PM, Chris Lattner <clat...@apple.com> wrote:
>
> On Jan 21, 2010, at 2:01 PM, Jim Crafton wrote:
>
>>> Nope, llvm's .s output is only compatible with GAS and other at&t syntax
>>> assemblers.  It turns out that MASM syntax is highly ambiguous and MASM
>>> is
>>> not production quality for use by a compiler.  This is why visual studio
>>> doesn't go through it.  Long term, we'd like LLVM to be able to write out
>>> .o
>>> files directly, if you're interested in adding PECOFF support, that would
>>> be
>>> very nice :)

Regarding the pecoff support - FASM comes with complete source and
what appears to be a BSD license. It outputs to pecoff. Assuming the
FASM code is readable and reasonably understandable, could this code
be used as a starting point for adding pecoff support? Isn't it the
case that when llvm gets to this phase, all the optimizations have
been done, everything else is complete, the only thing left is just
outputting to assembly or some other format right? Perhaps I'm being
hopelessly optimistic, but if that were the case that doesn't sound
like it would be that hard. Of course what do I know? :)

Cheers

Jim

Jim Crafton

unread,
Jan 22, 2010, 9:34:15 AM1/22/10
to llv...@cs.uiuc.edu
> Regarding the pecoff support - FASM comes with complete source and
> what appears to be a BSD license. It outputs to pecoff. Assuming the
> FASM code is readable and reasonably understandable, could this code
Scratch all that, my mistake, it's all assembly.

Anton Korobeynikov

unread,
Jan 22, 2010, 9:34:04 AM1/22/10
to luoyo...@gmail.com, LLVM Dev
> Did pecoff support means we can linkage llvm generated obj files to
> msvc's obj files?
You can do this right now. Object file format is fully compatible.

--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

Paul Davey

unread,
Feb 5, 2010, 7:36:41 PM2/5/10
to llv...@cs.uiuc.edu
if you dont want GNU deps then perhaps try using yasm, it supposedly supports GAS syntax and should run pretty standalone.
Reply all
Reply to author
Forward
0 new messages