[cfe-commits] Patch to clang -emit-llvm-bc on Linux

Daniel Dunbar daniel at zuster.org
Wed Apr 29 19:24:11 PDT 2009


Hi Colin,

I would definitely like to improve this, but I also think that the llvm-gcc
behavior (which clang is just copying) was chosen by design. Poor design,
perhaps, but I believe the intent was that -emit-llvm simply changes the
output format, not the functionality. Thus -S -emit-llvm is output in LLVM
IR, -c -emit-llvm is output in LLVM bitcode, -emit-llvm alone is an
executable, but having been compiled with LLVM tools. The problem, of
course, is when the linker doesn't have LLVM support.

I'd rather not break "compatibility" with llvm-gcc... is there a specific
reason you wante to change this (why not use "-c"?). If it just comes down
to eliminating the current bad user experience, we could augment the tool
chain to understand whether the system supports LLVM inputs and avoid trying
to pass them to the linker and give an error instead.

 - Daniel

On Wed, Apr 29, 2009 at 3:54 PM, Collin Winter <collinwinter at google.com>wrote:

> Hi all,
>
> Currently on Linux, clang -emit-llvm and -emit-llvm-bc will attempt to
> run the generated LLVM file through gcc, resulting in errors like
> those below. The attached patch tells clang to stop at compilation for
> -emit-llvm and -emit-llvm-bc, rather than attempting to pass them to
> ld. The patch also includes tests for this behavior.
>
> The patch is against r70419. I've tested this on Darwin and Linux with
> clang's make test.
>
> Thanks,
> Collin Winter
>
>
>
> $ ../../llvm/Debug/bin/clang -ccc-echo -O3 -emit-llvm-bc  -I.
> -IInclude -I../trunk -I../trunk/Include   -DPy_BUILD_CORE
> ../trunk/Python/llvm_inline_functions.c -o
> Python/llvm_inline_functions.bc
>  "/usr/local/google/collinwinter/llvm/Debug/bin/clang-cc" -triple
> i386-unknown-linux-gnu -S -disable-free -main-file-name
> llvm_inline_functions.c --relocation-model static --disable-fp-elim
> --unwind-tables=0 --fmath-errno=1 -DPy_BUILD_CORE -I. -IInclude
> -I../trunk -I../trunk/Include -O3 -fdiagnostics-show-option -o
> /tmp/cc-4HJUGl.s -x c ../trunk/Python/llvm_inline_functions.c
>  "/usr/bin/gcc" -O3 -emit-llvm-bc -I. -IInclude -I../trunk
> -I../trunk/Include -DPy_BUILD_CORE -c -o /tmp/cc-fL4PGn.o -x assembler
> /tmp/cc-4HJUGl.s
>  "/usr/bin/gcc" -O3 -emit-llvm-bc -I. -IInclude -I../trunk
> -I../trunk/Include -DPy_BUILD_CORE -o Python/llvm_inline_functions.bc
> /tmp/cc-fL4PGn.o
> /usr/bin/ld: warning: cannot find entry symbol mit-llvm-bc; defaulting
> to 0000000008048f50
> /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../lib/crt1.o: In function
> `_start':
>
> /tmp/glibc.iZwOIW/glibc-2.3.6-0ubuntu20/build-tree/glibc-2.3.6/csu/../sysdeps/i386/elf/start.S:115:
> undefined reference to `main'
> /tmp/cc-fL4PGn.o: In function `_PyLlvm_WrapDealloc':
> ../trunk/Python/llvm_inline_functions.c:(.text+0x9ed): undefined
> reference to `_Py_Dealloc'
> /tmp/cc-fL4PGn.o: In function `_PyLlvm_WrapIsExceptionOrString':
> ../trunk/Python/llvm_inline_functions.c:(.text+0xa0a): undefined
> reference to `PyClass_Type'
> /tmp/cc-fL4PGn.o: In function `_PyLlvm_WrapEnterExceptOrFinally':
> ../trunk/Python/llvm_inline_functions.c:(.text+0xa3a): undefined
> reference to `PyThreadState_Get'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xa56): undefined
> reference to `PyErr_Fetch'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xa65): undefined
> reference to `_Py_NoneStruct'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xa6b): undefined
> reference to `_Py_RefTotal'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xa85): undefined
> reference to `PyErr_NormalizeException'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xaa4): undefined
> reference to `_PyEval_SetExcInfo'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xaaf): undefined
> reference to `_Py_RefTotal'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xab5): undefined
> reference to `_Py_NoneStruct'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xabb): undefined
> reference to `_Py_NoneStruct'
> ../trunk/Python/llvm_inline_functions.c:(.text+0xac0): undefined
> reference to `PyErr_Clear'
> collect2: ld returned 1 exit status
> $
>
>
> $ ../../llvm/Debug/bin/clang -ccc-echo -O3 -emit-llvm  -I. -IInclude
> -I../trunk -I../trunk/Include   -DPy_BUILD_CORE
> ../trunk/Python/llvm_inline_functions.c -o
> Python/llvm_inline_functions.ir
>  "/usr/local/google/collinwinter/llvm/Debug/bin/clang-cc" -triple
> i386-unknown-linux-gnu -emit-llvm-bc -disable-free -main-file-name
> llvm_inline_functions.c --relocation-model static --disable-fp-elim
> --unwind-tables=0 --fmath-errno=1 -DPy_BUILD_CORE -I. -IInclude
> -I../trunk -I../trunk/Include -O3 -fdiagnostics-show-option -o
> /tmp/cc-zFrEU8.o -x c ../trunk/Python/llvm_inline_functions.c
>  "/usr/bin/gcc" -O3 -emit-llvm -I. -IInclude -I../trunk
> -I../trunk/Include -DPy_BUILD_CORE -o Python/llvm_inline_functions.ir
> /tmp/cc-zFrEU8.o
> /tmp/cc-zFrEU8.o: file not recognized: File format not recognized
> collect2: ld returned 1 exit status
> collinwinter at lagos:/usr/local/google/collinwinter/us/obj$
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090429/e03aa92d/attachment.html>


More information about the cfe-commits mailing list