Building libLLVM-2.8svn.so fails to link on FreeBSD

I am getting this error on FreeBSD-8.1 (amd64):

llvm[1]: Linking Debug+Asserts Shared Library libLLVM-2.8svn.so
/tmp/llvm-svn/llvm-objects/Debug+Asserts/lib/libLLVMSystem.a(Program.o)(.text+0xa2b): In function `llvm::sys::Program::Execute(llvm::sys::Path const&, char const**, char const**, llvm::sys::Path const**, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
/tmp/llvm-svn/llvm/lib/System/Unix/Program.inc:209: undefined reference to `environ'

I found that the error disappears when -Wl,--no-undefined is removed from the linker command line (below).
Also in an unrelated observation I noticed that both -Wl,--whole-archive and -Wl,--no-whole-archive are specified which is probably wrong.

Yuri

--- linker command line ---
g++ -I/tmp/llvm-svn/llvm-objects/include -I/tmp/llvm-svn/llvm-objects/tools/llvm-shlib -I/tmp/llvm-svn/llvm/include -I/tmp/llvm-svn/llvm/tools/llvm-shlib -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -g -fno-exceptions -fno-rtti -fPIC -Woverloaded-virtual -Wcast-qual -L/usr/local/lib -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -g -Wl,-R -Wl,'$ORIGIN' -L/tmp/llvm-svn/llvm-objects/Debug+Asserts/lib -L/tmp/llvm-svn/llvm-objects/Debug+Asserts/lib -shared -lc -o /tmp/llvm-svn/llvm-objects/Debug+Asserts/lib/libLLVM-2.8svn.so \
            -Wl,--whole-archive -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -lLLVMARMDisassembler -lLLVMARMInfo -lLLVMAlphaAsmPrinter -lLLVMAlphaCodeGen -lLLVMAlphaInfo -lLLVMAnalysis -lLLVMArchive -lLLVMAsmParser -lLLVMAsmPrinter -lLLVMBitReader -lLLVMBitWriter -lLLVMBlackfinAsmPrinter -lLLVMBlackfinCodeGen -lLLVMBlackfinInfo -lLLVMCBackend -lLLVMCBackendInfo -lLLVMCellSPUAsmPrinter -lLLVMCellSPUCodeGen -lLLVMCellSPUInfo -lLLVMCodeGen -lLLVMCore -lLLVMCppBackend -lLLVMCppBackendInfo -lLLVMExecutionEngine -lLLVMInstCombine -lLLVMInstrumentation -lLLVMInterpreter -lLLVMJIT -lLLVMLinker -lLLVMMBlazeAsmPrinter -lLLVMMBlazeCodeGen -lLLVMMBlazeInfo -lLLVMMC -lLLVMMCDisassembler -lLLVMMCParser -lLLVMMSIL -lLLVMMSILInfo -lLLVMMSP430AsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Info -lLLVMMipsAsmPrinter -lLLVMMipsCodeGen -lLLVMMipsInfo -lLLVMPIC16AsmPrinter -lLLVMPIC16CodeGen -lLLVMPIC16Info -lLLVMPowerPCAsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCInfo -lLLVMScalarOpts -lLLVMSelectionDAG -lLLVMSparcAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcInfo -lLLVMSupport -lLLVMSystem -lLLVMSystemZAsmPrinter -lLLVMSystemZCodeGen -lLLVMSystemZInfo -lLLVMTarget -lLLVMTransformUtils -lLLVMX86AsmParser -lLLVMX86AsmPrinter -lLLVMX86CodeGen -lLLVMX86Disassembler -lLLVMX86Info -lLLVMXCoreAsmPrinter -lLLVMXCoreCodeGen -lLLVMXCoreInfo -lLLVMipa -lLLVMipo -lLLVMpic16passes -Wl,--no-whole-archive -Wl,--no-undefined -lpthread -lffi -lm

Please check in the attached patch: it fixes the problem on FreeBSD.
Before I used the patch from someone (don't remember). It just had an else clause on HOST_OS in the Makefile with the same options in 'else' clause as for Linux.

Thank you,
Yuri

fbsd-shlib.patch (515 Bytes)