[LLVMdev] libstdc++ as bytecode, again

Emil Mikulic emil at cs.rmit.edu.au
Tue Nov 21 04:46:39 PST 2006


Okay, let's try this again.  I've taken all the source and header files
needed to build libstdc++ and libsupc++, and put together a small and
very simple Makefile that automates the process.

Anyone interested can grab the whole thing from here:
	http://goanna.cs.rmit.edu.au/~emil/dietstdcxx.1.tar.bz2 (101KB)

Usage instructions:

1) Run GNU make:
	$ gmake

This will produce dietstdcxx.bc - a bytecode / object file containing all of
stdc++ and supc++ llvm-link'd together.

2) Run:
	$ gmake test

This will build and run the test program.
Example:
	$ gmake test
	llvm-g++  -emit-llvm -c -o test.o test.cpp
	llvm-link -f -o linked.o test.o dietstdcxx.bc
	llvmc -o=reduced linked.o
	llc -f -o=out.c -march=c reduced.bc
	WARNING: this target does not support the llvm.stacksave intrinsic.
	gcc out.c
	./a.out
	hello world
	$

Things I'm doing differently compared to last time:
 - almost sane build infrastructure
 - building dietstdcxx with -fno-exceptions (!)

Without the llvmc step to reduce the bytecode, I get three errors in the
gcc stage:
	$ llc -f -o=out2.c -march=c linked.o 
	WARNING: this target does not support the llvm.stacksave intrinsic.
	$ gcc out2.c 
	/var/tmp//cc79lj1N.o(.text+0xd726d): In function `__cxxabiv1::__pbase_type_info::__do_catch(std::type_info const*, void**, unsigned int) const':
	: undefined reference to `l182___cxa_bad_typeid'
	/var/tmp//cc79lj1N.o(.data+0x19fc): undefined reference to `std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::seekpos(std::fpos<__mbstate_t>, std::_Ios_Openmode)'
	/var/tmp//cc79lj1N.o(.data+0x1a3c): undefined reference to `std::basic_filebuf<char, std::char_traits<char> >::seekpos(std::fpos<__mbstate_t>, std::_Ios_Openmode)'
	$

And again, using llvmc instead of llvm-link produces bad code:

	$ gmake dietstdcxx.bc
	$ llvm-g++  -emit-llvm -c -o test.o test.cpp
	$ llvmc -o=linked test.o dietstdcxx.bc
	$ lli linked.bc
	Segmentation fault (core dumped)
	$

Reid, you asked for a stack trace from a program generated by llvmc.
I tried this:
	$ gmake clean
	$ gmake [with CCFLAGS=-g]
	$ llvm-g++ -g -emit-llvm -c -o test.o test.cpp
	$ llvmc -native -g -o=native test.o dietstdcxx.bc

But there were no debug symbols.  gdb says the problem is in main(),
but doesn't even give a line number.

It also complains about:
	DW_FORM_strp pointing outside of .debug_str section [in module /rest/dietstdcxx/native]

Did you mean something else?

--Emil

(P.S. "diet" turned out to be something of a misnomer.  In the end, I
didn't really strip out any code)



More information about the llvm-dev mailing list