Hey, The following code creates a raw binary (no ELF or PE.. just raw): gcc -nostartfiles -c -o hello.o hello.c ld -o hello1 hello.o --oformat binary You can try the following code out with it: void _start() { while(1); } The resulting raw binary is 5 bytes. Now how do you do this in clang/llvm? Apparently llvm-ld doesn't have a "--oformat binary" option. Anybody know how to do this with llvm? -- View this message in context: http://old.nabble.com/Compiling-a-raw-binary-with-llvm-clang-tp26834182p26834182.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On 2009-12-17 22:08, LiteHacker wrote:> Hey, > > The following code creates a raw binary (no ELF or PE.. just raw): > > gcc -nostartfiles -c -o hello.o hello.c > ld -o hello1 hello.o --oformat binary > > You can try the following code out with it: > > void _start() > { > while(1); > } > > The resulting raw binary is 5 bytes. >It is 2.1M here (on x86_64), and 4.3k with -m32 when using gcc 4.4.2. Apparently it includes the dynamic linker inside it.> Now how do you do this in clang/llvm? > Apparently llvm-ld doesn't have a "--oformat binary" option. > Anybody know how to do this with llvm? >Simple, use ld on the .o files, as you would with gcc. An example with clang: $ clang -nostartfiles -c x.c -o x.o $ ld -o x x.o --oformat binary Or to get a 32-bit one: $ /llvm-git/obj/Release/bin/clang -nostartfiles -c x.c -o x.o -m32 $ ld -o x1 x.o --oformat binary -melf_i386 This one is indeed 5 bytes long. Best regards, --Edwin
Indeed ld does link it. The reason I am using llvm-ld, is for its unique functionality. I intend to link to object files together (created by cling), and link them with llvm-ld. The main feature that I am currently interested in is the ability to have "inline functions" between two object files. This was basically impossible with gcc. Is there any way to make the raw binary with llvm? Thank you, Ven Török Edwin wrote:> > > An example with clang: > $ clang -nostartfiles -c x.c -o x.o > $ ld -o x x.o --oformat binary > > Or to get a 32-bit one: > $ /llvm-git/obj/Release/bin/clang -nostartfiles -c x.c -o x.o -m32 > $ ld -o x1 x.o --oformat binary -melf_i386 > > This one is indeed 5 bytes long. > > Best regards, > --Edwin > >-- View this message in context: http://old.nabble.com/Compiling-a-raw-binary-with-llvm-clang-tp26834182p26834869.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Possibly Parallel Threads
- [LLVMdev] Compiling a raw binary with llvm/clang
- [LLVMdev] Compiling a raw binary with llvm/clang
- [LLVMdev] Compiling a raw binary with llvm/clang
- [LLVMdev] Compiling a raw binary with llvm/clang
- [PATCH] builder: handle -v and -x flags like in other tools (RHBZ#1196100)