[LLVMdev] Compiling FreeType 2.1.9 with LLVM 1.4

Jeff Cohen jeffc at jolt-lang.org
Sun Dec 19 21:01:13 PST 2004


LLVM developers intent on world domination?  Now that you've uncovered 
their secret, they'll have to eliminate you, you know :-)

I don't have a working LLVM system right now (in the middle of building 
a new FreeBSD system), but I did take a look at the code.  The heavy use 
of macros makes it hard to tell exactly what the compiler is seeing.  
Could you capture the output of the C preprocessor?

It looks like the front end is having a problem with the expansion of 
these macros:

 #define FT_FIELD_SIZE( f ) \
          (FT_Byte)sizeof ( ((FT_STRUCTURE*)0)->f )

#define FT_FIELD_OFFSET( f ) \
          (FT_UShort)( offsetof( FT_STRUCTURE, f ) )
 
where "f" is an array element like "xyz[0]".  Problem is, LLVM's front 
end *is* gcc and it works for you when using gcc.  But then, you're 
using gcc 3.3.5 and LLVM uses 3.4.  But then (again), I just built 
Freetype 2.1.7 on FreeBSD using gcc 3.4.2 without problems.

Adam Warner wrote:

>Hi all,
>
>I learned of LLVM a couple of days ago:
><http://groups.google.co.nz/groups?selm=pan.2004.12.18.11.29.33.33249%40consulting.net.nz>
><http://groups.google.co.nz/groups?th=608e6e38e496f09d>
>(I posted a tail call followup which is missing from the archive)
>
>Jestingly, LLVM developers appear intent upon nothing short of world
>domination. Not only have you done an end run around exposing the back end
>of the GNU Compiler Collection but you are positioning yourselves to
>dominate popular virtual machines architectures (such as the JVM from Sun
>and the CLR from Microsoft) by translating their classes to LLVM bytecode.
>Suffice to say you know what you're doing and it's currently a well kept
>secret ;-)
>
>I suspect GCC may be entering a period of twilight that cannot be solved
>by forking (unlike occurred in 1997 with EGCS). The world is waking up to
>what Lisp developers have been doing for decades: run time code generation
>and compilation. The potentially onerous legal restrictions upon using GCC
>as a run time and/or JIT compiler can not be solved by forking. GCC may
>remain a static compiler and may increasingly become a legacy component of
>build systems.
>
>Putting these long term predictions aside, I have modest goals. I'm
>learning C and I want to build portable libraries. LLVM's modification of
>GCC so it outputs portable LLVM bytecode is ideal. I'd like to build
>FreeType 2 as an LLVM library instead of an ordinary shared object (then
>I can link my bytecode and the FreeType 2 library together).
>
>I've built llvm-1.4.tar.gz using the cfrontend-1.4.i686-redhat-linux-gnu.tar.gz
>binaries. As I didn't appreciate the registration front end I just googled for
>the file names.
>
>My new environment is:
>
>export LLVM_LIB_SEARCH_PATH=/home/adam/t/llvm/cfrontend/x86/llvm-gcc/bytecode-libs
>export PATH=/home/adam/t/llvm/Release/bin/:/home/adam/t/llvm/cfrontend/x86/llvm-gcc/bin/:$PATH
>export CC=/home/adam/t/llvm/cfrontend/x86/llvm-gcc/bin/gcc
>export CCC=/home/adam/t/llvm/cfrontend/x86/llvm-gcc/bin/g++
>
>Here's what occurs when building FreeType 2 with LLVM:
>
>1. Download FreeType 2.1.9:
><http://sourceforge.net/project/showfiles.php?group_id=3157>
>2. Open Bash shell and set environment variables above. gcc -v is now:
>
>Reading specs from /home/adam/t/llvm/cfrontend/x86/llvm-gcc/bin/../lib/gcc/i686-pc-linux-gnu/3.4-llvm/specs
>Configured with: /home/vadve/criswell/release/llvm-gcc/configure
>--prefix=/mounts/choi/disks/0/localhome/criswell/rel14/cfrontend/x86/llvm-gcc
>--disable-threads --disable-nls --disable-shared --enable-languages=c,c++
>Thread model: single
>gcc version 3.4-llvm 20030924 (experimental)
>
>3. tar -jxvf freetype-2.1.9.tar.bz2
>4. cd freetype-2.1.9
>5. edit builds/unix/configure to match GCC's build flags:
>
>if test "x$CC" = xgcc; then
>  XX_CFLAGS="-Wall"
>  XX_ANSIFLAGS="-pedantic -ansi"
>else
>  case "$host" in
>  *-dec-osf*)
>    CFLAGS=
>    XX_CFLAGS="-std1 -g3"
>    XX_ANSIFLAGS=
>    ;;
>  *)
>    XX_CFLAGS=
>    XX_ANSIFLAGS=
>    ;;
>  esac
>fi
>
>becomes:
>
>  XX_CFLAGS="-Wall"
>  XX_ANSIFLAGS="-pedantic -ansi"
>
>5. ./configure
>6. make
>
>Building dies part way through with these messages:
>
> /home/adam/t/llvm/cfrontend/x86/llvm-gcc/bin/gcc -pedantic -ansi -I/home/adam/t/freetype-2.1.9/objs -I./builds/unix -I/home/adam/t/freetype-2.1.9/include -c -Wall -g -O2 -DFT_CONFIG_OPTION_SYSTEM_ZLIB -DDARWIN_NO_CARBON "-DFT_CONFIG_CONFIG_H=<ftconfig.h>" -I/home/adam/t/freetype-2.1.9/src/sfnt /home/adam/t/freetype-2.1.9/src/sfnt/sfnt.c -o /home/adam/t/freetype-2.1.9/objs/sfnt.o
>In file included from /home/adam/t/freetype-2.1.9/src/sfnt/sfnt.c:22:
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c: In function `tt_face_load_generic_header':
>
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:597: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:597: error: (near initialization for `header_fields[7].offset')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:597: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:597: error: (near initialization for `header_fields[7]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:598: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:598: error: (near initialization for `header_fields[8].offset')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:598: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:598: error: (near initialization for `header_fields[8]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:599: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:599: error: (near initialization for `header_fields[9].offset')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:599: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:599: error: (near initialization for `header_fields[9]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:600: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:600: error: (near initialization for `header_fields[10].offset')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:600: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:600: error: (near initialization for `header_fields[10]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:601: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:601: error: (near initialization for `header_fields[11]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:602: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:602: error: (near initialization for `header_fields[12]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:603: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:603: error: (near initialization for `header_fields[13]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:604: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:604: error: (near initialization for `header_fields[14]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:605: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:605: error: (near initialization for `header_fields[15]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:606: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:606: error: (near initialization for `header_fields[16]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:607: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:607: error: (near initialization for `header_fields[17]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:608: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:608: error: (near initialization for `header_fields[18]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:609: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:609: error: (near initialization for `header_fields[19]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:610: error: initializer element is not constant
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:610: error: (near initialization for `header_fields[20]')
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c: In function `tt_face_load_metrics_header':
>
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:986: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:986: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:987: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:987: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:988: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:988: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:989: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:989: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c: In function `tt_face_load_os2':
>
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1319: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1319: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1320: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1320: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1321: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1321: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1322: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1322: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1323: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1323: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1324: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1324: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1325: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1325: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1326: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1326: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1327: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1327: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1328: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1328: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1333: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1333: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1334: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1334: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1335: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1335: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1336: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttload.c:1336: warning: initializer element is not computable at load time
>In file included from /home/adam/t/freetype-2.1.9/src/sfnt/sfnt.c:28:
>/home/adam/t/freetype-2.1.9/src/sfnt/ttsbit.c: In function `tt_face_load_sbit_strikes':
>
>/home/adam/t/freetype-2.1.9/src/sfnt/ttsbit.c:421: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttsbit.c:421: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttsbit.c:422: warning: initializer element is not computable at load time
>/home/adam/t/freetype-2.1.9/src/sfnt/ttsbit.c:422: warning: initializer element is not computable at load time
>make: *** [/home/adam/t/freetype-2.1.9/objs/sfnt.lo] Error 1
>
>
>Note that when using standard GCC FreeType builds fine:
>
>Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs
>Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,
>objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
>--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
>--enable-nls --without-included-gettext --enable-__cxa_atexit
>--enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib
>--enable-objc-gc i486-linux
>Thread model: posix
>gcc version 3.3.5 (Debian 1:3.3.5-4)
>
>Many thanks for any build tips. My operating system is Debian GNU/Linux sid/unstable.
>
>If this is too experimental to be expected to work I'll learn how LLVM bc can be
>linked with C shared objects instead. I'm currently to the point where I can execute
>my own bytecode via lli (or compile it via llc) and produce this output:
>
>$ lli a.out.bc
>ERROR: Program used external function 'FT_Init_FreeType' which could not be resolved!
>lli((anonymous namespace)::PrintStackTrace()+0x1f)[0x835875f]
>/lib/tls/libc.so.6(abort+0x1d2)[0x40135f12]
>lli[0x810666b]
>Aborted
>
>[This is expected, of course, as I'm attempting to get to the point of linking]
>
>Many thanks,
>Adam
>
>_______________________________________________
>LLVM Developers mailing list
>LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>  
>




More information about the llvm-dev mailing list