Missing symbols when loading opt plugins

Hi all,

I am having some problems when loading plugins using opt -load=xxx, due to missing symbols. I am using a statically linked version of LLVM under Mac OS X 10.7, and I have pinpointed the problems to two separate causes:

1) opt should not be stripped during installation. When installing Release versions, opt is stripped, removing symbols which might get needed by the plugins. In my case, symbol '__ZN4llvm10ModulePass17assignPassManagerERNS_7PMStackENS_15PassManagerTypeE' is present in built opt:

nm Release+Asserts/bin/opt | grep __ZN4llvm10ModulePass17assignPassManagerERNS_7PMStackENS_15PassManagerTypeE
00000001003a9220 T __ZN4llvm10ModulePass17assignPassManagerERNS_7PMStackENS_15PassManagerTypeE

but removed during installation. This can be fixed by adding "KEEP_SYMBOLS := 1" to tools/opt/Makefile.

2) if LLVM is built using Lion system clang (Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)), external template instantiations do not get external visibility. In my case this is notices because my plugin uses cl::opt<bool> to parse command line, and loading fails cause symbol '__ZN4llvm2cl3optIbLb0ENS0_6parserIbEEE4doneEv' is missing. Inspection with nm shows:

#nm opt | grep __ZN4llvm2cl3optIbLb0ENS0_6parserIbEEE4doneEv
00000001003ebe00 t __ZN4llvm2cl3optIbLb0ENS0_6parserIbEEE4doneEv

However, this can be solved by bootstrapping (compiling llvm-3.1+clang-3.1 and rebuilding llvm-3.1 with the just built clang). In that case:

#nm opt | grep __ZN4llvm2cl3optIbLb0ENS0_6parserIbEEE4doneEv
00000001003cf250 T __ZN4llvm2cl3optIbLb0ENS0_6parserIbEEE4doneEv

and symbol is external (capital T).

I understand this second one is not strictly an LLVM problem, but I report it as it can save time for someone facing similar problems. Could it be that external template instantiations were failing in clang prior to 3.1?

BR

Carlos