Linlin Cheng
2011-Dec-16 02:08 UTC
[LLVMdev] striping of stdio information in llvm-gcc and clang
Hi, I have the following test code print.c: #include <stdio.h> int main(){ fprintf(stderr, "Error!\n"); return 0; } I did the following on linux to cross-compile it for Sparc architecture: clang -m32 -c print.c -emit-llvm -o print.bc (or llvm-gcc -m32 -c print.c -emit-llvm -o print.bc) llvm-dis < print.bc -o print2.bc llc -march=sparc -mcpu=v8 print2.bc -o print_s.s if I compile it on Sparc using gcc 3.4 gcc print_s.s -o print_linux it gives me the following error: Undefined first referenced symbol in file stderr /var/tmp//ccGa4Zxh.o ld: fatal: Symbol referencing errors. No output written to print_linux collect2: ld returned 1 exit status I compiled the same code on Sparc directly, the .s file is the following without 'stderr' .file "print.c" .section ".rodata" .align 8 .LLC0: .asciz "Error!\n" .section ".text" .align 4 .global main .type main, #function .proc 04 main: !#PROLOGUE# 0 save %sp, -112, %sp !#PROLOGUE# 1 sethi %hi(__iob+32), %g1 or %g1, %lo(__iob+32), %o0 sethi %hi(.LLC0), %g1 or %g1, %lo(.LLC0), %o1 call fprintf, 0 nop mov 0, %g1 mov %g1, %i0 ret restore .size main, .-main .ident "GCC: (GNU) 3.4.6" While the .s file generated by llc gives the following code with 'stderr' as a symbol. .file "print2.bc" .text .globl main .align 4 .type main, at function main: ! @main ! BB#0: save %sp, -104, %sp sethi 0, %i0 sethi %hi(stderr), %l0 st %i0, [%fp+-4] ld [%l0+%lo(stderr)], %o0 sethi %hi(.L.str), %l0 add %l0, %lo(.L.str), %o1 call fprintf nop restore %g0, %g0, %g0 retl nop .Ltmp0: .size main, .Ltmp0-main .type .L.str, at object ! @.str .section .rodata.str1.1,"aMS", at progbits,1 .L.str: .asciz "Error!\n" .size .L.str, 8 Apparently the 'stderr' is not resolved in the linking stage. I tried adding '-lstdio' in the gcc link stage but it does not work. Anyone has any idea about how this problem can be resolved? Thanks, Christine
Eli Friedman
2011-Dec-16 04:43 UTC
[LLVMdev] striping of stdio information in llvm-gcc and clang
On Thu, Dec 15, 2011 at 6:08 PM, Linlin Cheng <linlin at caltech.edu> wrote:> Hi, > > I have the following test code print.c: > > #include <stdio.h> > > int main(){ > fprintf(stderr, "Error!\n"); > return 0; > } > > I did the following on linux to cross-compile it for Sparc architecture: > clang -m32 -c print.c -emit-llvm -o print.bcThis step is encoding platform-specific information into print.bc; you can't just use llc to generate output for an arbitrary architecture and expect it to work. clang's cross-compilation support isn't really mature; you might be able to get away with specifying "-ccc-host-triple sparc-sun-solaris -nostdinc -I /path/to/sparc/headers/". -Eli
Joerg Sonnenberger
2011-Dec-16 06:39 UTC
[LLVMdev] striping of stdio information in llvm-gcc and clang
On Thu, Dec 15, 2011 at 08:43:01PM -0800, Eli Friedman wrote:> clang's cross-compilation support isn't really mature; you might be > able to get away with specifying "-ccc-host-triple sparc-sun-solaris > -nostdinc -I /path/to/sparc/headers/".Please read that as "clang's cross-compilation support is not magical". It's not a question of maturity that different Operation Systems and architectures have incompatible libc ABIs encoded in the system headers. Joerg
Seemingly Similar Threads
- [LLVMdev] striping of stdio information in llvm-gcc and clang
- [LLVMdev] striping of stdio information in llvm-gcc and clang
- [LLVMdev] striping of stdio information in llvm-gcc and clang
- [LLVMdev] striping of stdio information in llvm-gcc and clang
- Build problems: klibc with Linux 3.10.7