help with link problems

First, thanks to those who have responded to my earlier pleas for
help. You have either directly or indirectly helped me find the
answers I needed. I'm slowly getting up to speed with LLVM. Now I
have 2 more questions.

1) I'm using LLVM 1.8a with llvm-gcc3. I'm trying to compile firefox
(with regular gcc and make) while using LLVM to automatically
instrument one source file (specifically, nsCacheService.cpp in the
netwerk/cache module). I've written an LLVM pass to add a fprintf()
timestamp at every function exit. So I go through the steps as
outlined in the FAQ to turn C++ code into C: 1) llvm-g++ on the source
file to produce LLVM bytecode; 2) run my pass on bytecode; 3) use llc
to produce C code; 4) run regular compilation via make.

The regular compilation process creates .o files, combines them into
an archive, then links several module archives together into a shared
object file. At this last step, I get several error messages about
undefined references; snippet shown below. Don't know if this is
relevant, but the makefile's ld command uses -Bsymbolic.

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x123e): In function `nsCacheEntryDescriptor::MarkValid()':
: undefined reference to `nsCacheService::ServiceLock()'

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x1278): In function `nsCacheEntryDescriptor::MarkValid()':
: undefined reference to `nsCacheService::ValidateEntry(nsCacheEntry*)'

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x12ad): In function `nsCacheEntryDescriptor::Close()':
: undefined reference to `nsCacheService::ServiceLock()'

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x12e4): In function `nsCacheEntryDescriptor::Close()':
: undefined reference to `nsCacheService::CloseDescriptor(nsCacheEntryDescriptor*)'

2) On a whim, I wanted to try using llvm-gcc4. However, when I invoke
it, I get a relocation error.

prompt% llvm-gcc --version
llvm-gcc: relocation error: /home/jhom/LLVM/1.8/llvm-gcc4-1.8-x86-linux/lib/libstdc++.so.6: undefined symbol: _ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEi

Any suggestions are greatly appreciated!

Jerry Hom wrote:

I haven't seen anyone answer this question yet, so I'll take a crack at it:

First, thanks to those who have responded to my earlier pleas for
help. You have either directly or indirectly helped me find the
answers I needed. I'm slowly getting up to speed with LLVM. Now I
have 2 more questions.

1) I'm using LLVM 1.8a with llvm-gcc3. I'm trying to compile firefox
(with regular gcc and make) while using LLVM to automatically
instrument one source file (specifically, nsCacheService.cpp in the
netwerk/cache module). I've written an LLVM pass to add a fprintf()
timestamp at every function exit. So I go through the steps as
outlined in the FAQ to turn C++ code into C: 1) llvm-g++ on the source
file to produce LLVM bytecode; 2) run my pass on bytecode; 3) use llc
to produce C code; 4) run regular compilation via make.
  

I am not sure what is happening below, but my best guess is that Firefox is using symbols found in native code libraries (e.g. system libraries not compiled to LLVM bytecode). If that is the case, you have two options:

1) Compile the library into LLVM bytecode (only works if you have the source).

2) Link the native code library into the object files when you compile the output of llc with gcc.

The regular compilation process creates .o files, combines them into
an archive, then links several module archives together into a shared
object file. At this last step, I get several error messages about
undefined references; snippet shown below. Don't know if this is
relevant, but the makefile's ld command uses -Bsymbolic.

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x123e): In function `nsCacheEntryDescriptor::MarkValid()':
: undefined reference to `nsCacheService::ServiceLock()'

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x1278): In function `nsCacheEntryDescriptor::MarkValid()':
: undefined reference to `nsCacheService::ValidateEntry(nsCacheEntry*)'

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x12ad): In function `nsCacheEntryDescriptor::Close()':
: undefined reference to `nsCacheService::ServiceLock()'

../../dist/lib/libnkcache_s.a(nsCacheEntryDescriptor.o)(.text+0x12e4): In function `nsCacheEntryDescriptor::Close()':
: undefined reference to `nsCacheService::CloseDescriptor(nsCacheEntryDescriptor*)'

2) On a whim, I wanted to try using llvm-gcc4. However, when I invoke
it, I get a relocation error.

prompt% llvm-gcc --version
llvm-gcc: relocation error: /home/jhom/LLVM/1.8/llvm-gcc4-1.8-x86-linux/lib/libstdc++.so.6: undefined symbol: _ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEi
  

Did you compile llvm-gcc4, or did you download a precompiled version from somewhere?

Most likely, the problem is that llvm-gcc4 was built against a different version of libstdc++ (or, the version of libstdc++ used is not in your LD_LIBRARY_PATH). You'll either need to recompile llvm-gcc4 or set your LD_LIBRARY_PATH accordingly.

If the llvm-gcc4 is a pre-compiled version from the LLVM web site, please email the llvmdev list. If it's a problem for you, it might be a problem for a number of people.

-- John T.

I've seen this. The solution here was to not include the llvm-
gcc4's /lib directory in your LD_LIBRARY_PATH. Apparently the binary is
built against the system libstdc++ and is slightly different than the
one llvm-gcc4 builds.

Andrew