Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Gordon Keiser <gkeiser <at> arxan.com>
Subject: Re: How can I get llvm-as for Ubuntu?
Newsgroups: gmane.comp.compilers.llvm.devel
Date: Thursday 6th February 2014 06:11:17 UTC (over 3 years ago)
> Andrew Pennebaker wrote:
> > I used to be able to `apt-get install llvm` to install `llvm-as`, an
> > LLVM assembler. I think some tools/packages have moved around since
> then.
> >
> > What can I use to compile `.ll` assembler files into executables?
> 
> You'll have to ask your distributor about how llvm is packaged, but I can
> answer about what the tools are.
> 
> llvm-as converts .ll to .bc. The formats are equivalent except that the
former
> is human readable and the latter is machine readable. They are both LLVM
IR
> (llvm's assembly format) not native machine code.
> 
> llc converts .ll or .bc to .s (native assembly) or .o files (native
object file).
> These are what you commonly get out of a compiler, and must be linked to
> form an executable.
> 
> llvm-mc converts between .s and .o. It is a native assembler and
> disassembler.
> 
> Given a set of .o files, you need to (native) link them to form an
executable.
> LLVM proper does not include a native linker. (llvm-link is not one, it
> combines multiple .bc files into a single .bc file. You'll still need a
native
> linker.) There is the lld.llvm.org project which you can use to link, if
you want
> to use llvm parts.
> 
> So I think the answer you want is "llc foo.ll -filetype=obj -o foo.o"
> and then you link foo.o with "ld" on your system.
> 
> Nick

You don't really need to go to that much effort, possibly unless you're
cross-compiling or doing something else weird.   Clang will happily accept
any mixture of regular object files and bitcode (in either .bc or .ll
format) and drive the process to completion.   With the default Ubuntu
12.04 clang package (3.0 I think?)

-------- file world.c --------------
#include 

void world(const char* message)
{
  printf("ARGV[0] is: %s \n", message);
  
}

------------ file hello.c ---------------


extern void world(const char* message);

int main(int argc, char** argv)
{
  world(argv[0]);

  return 0; 
}

--------------------------------------- 
Run the following:

~$ clang -c -emit-llvm -S hello.c -o hello.ll
~$ clang -c world.c -o world.o
~$ clang hello.ll world.o -o hello
~$ ./hello
ARGV[0] is: ./hello


If you're just wanting to go from textual IR to binary IR as llvm-as does:

~$ clang -c -emit-llvm hello.ll -o hello.bc

Saves a lot of messing around with the various command line tools and such.
 :-)

Cheers,
Gordon Keiser
Software Development Engineer
Arxan Technologies www.arxan.com 
Protecting the App EconomyT 
 
CD: 4ms