Is the option --enable-shared discontinued in 2.7?

When I enabled this option I am getting errors, see below.
Is there any way to fix this? There should be an option to have most of the code in shared library.

Yuri

--- error log using gcc-4.5.0 on 4 cpus with configure options: --enable-assertions --enable-optimized --enable-shared --prefix=/usr/local/llvm ---
llvm[2]: Compiling llc.cpp for Release build
gmake[2]: Entering directory `/tmp/llvm-build/2.7/llvm-objects/tools/llvm-ld'
llvm[2]: Compiling Optimize.cpp for Release build
llvm[2]: Linking Release executable llvm-dis (without symbols)
llvm[2]: Compiling GraphPrinters.cpp for Release build
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0x42): In function `main':
: undefined reference to `llvm::sys::PrintStackTraceOnErrorSignal()'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0x51): In function `main':
: undefined reference to `llvm::PrettyStackTraceEntry::PrettyStackTraceEntry()'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0x57): In function `main':
: undefined reference to `vtable for llvm::PrettyStackTraceProgram'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0x68): In function `main':
: undefined reference to `llvm::getGlobalContext()'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0x7b): In function `main':
: undefined reference to `llvm::cl::ParseCommandLineOptions(int, char**, char const*, bool)'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0xb2): In function `main':
: undefined reference to `llvm::MemoryBuffer::getFileOrSTDIN(llvm::StringRef, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, long long)'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-dis/Release/llvm-dis.o(.text+0xcd): In function `main':
: undefined reference to `llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'

--enable-shared was _created_ in 2.7. If you were passing it in 2.6 or
earlier, it wasn't doing what you expected.

I just tried it again on trunk (not 2.7) on OSX 10.5, and it works.
What platform are you on? Does it work with another version of gcc?

Jeffrey Yasskin wrote:

--enable-shared was _created_ in 2.7. If you were passing it in 2.6 or
earlier, it wasn't doing what you expected.
  

It's description in online documentation appeared long before 2.7 was released, which caused me to believe it that this feature was present in 2.6. But I never tied to use the shared library anyway.

I just tried it again on trunk (not 2.7) on OSX 10.5, and it works.
What platform are you on? Does it work with another version of gcc?
  

I am on FreeBSD-8.0 i386. I tried it with gcc-4.3.1 and it also breaks the build:

<...skipped...>
llvm[2]: Linking Release executable llvm-as (without symbols)
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-ranlib/Release/llvm-ranlib.o(.text+0x1fc): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `vtable for llvm::cl::opt<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, false, llvm::cl::parser<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >'
/tmp/llvm-build/2.7/llvm-objects/tools/llvm-ranlib/Release/llvm-ranlib.o(.text+0x20b): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `vtable for llvm::cl::parser<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >'
<...skipped...>

Yuri

Jeffrey Yasskin wrote:

I just tried it again on trunk (not 2.7) on OSX 10.5, and it works.
What platform are you on? Does it work with another version of gcc?
  
Looks like this is platform dependent. libLLVM-2.7.so created has size only 4145 bytes and all llvm symbols are missing.
It's empty because there are no .o modules included into it, only libraries through -l options were specified in g++ command line.
Libraries normally are specified with -l option to resolve unknown imports, not to be just included into .so library.

All .o files should be listed in the command line instead.

Yuri

Yep, works fine here on Debian 5.0/x86_64 with gcc 4.3.2.

Did you build with make REQUIRES_RTTI=1 which is required
as of LLVM 2.7 to get RTTI for LLVM symbols?

We currently use two different techniques to get whole libraries
included into the .so. On Linux (gnu ld and gold), we pass
--whole-archive, while on OSX we pass -all_load. Which ld does FreeBSD
use? If you can rearrange tools/llvm-shlib/Makefile until it works for
you and send us a patch, we can probably get it working for llvm-2.8.

Pekka Jääskeläinen wrote:

Yeah, REQUIRES_RTTI has nothing to do with this.

Jeffrey Yasskin wrote:

We currently use two different techniques to get whole libraries
included into the .so. On Linux (gnu ld and gold), we pass
--whole-archive, while on OSX we pass -all_load. Which ld does FreeBSD
use? If you can rearrange tools/llvm-shlib/Makefile until it works for
you and send us a patch, we can probably get it working for llvm-2.8.
  
ld on FreeBSD is from binutils. It takes --whole-archive option. But command line needs to be changed: actual archive files should be supplied, not just -lXXX. I believe that will fix the problem.

Yuri

Jeffrey Yasskin wrote:

We currently use two different techniques to get whole libraries
included into the .so. On Linux (gnu ld and gold), we pass
--whole-archive, while on OSX we pass -all_load. Which ld does FreeBSD
use? If you can rearrange tools/llvm-shlib/Makefile until it works for
you and send us a patch, we can probably get it working for llvm-2.8.

ld on FreeBSD is from binutils. It takes --whole-archive option.

Would you try the patch at
http://codereview.appspot.com/download/issue968046_1.diff? It should
make the BSDs fall into the same path as Linux, and since you use gnu
ld, that should work for you.

But command
line needs to be changed: actual archive files should be supplied, not just
-lXXX. I believe that will fix the problem.

This isn't needed on Linux or MacOS.

Thanks,
Jeffrey

Ping?

Jeffrey Yasskin wrote:

Would you try the patch at
http://codereview.appspot.com/download/issue968046_1.diff? It should
make the BSDs fall into the same path as Linux, and since you use gnu
ld, that should work for you.
    
Ping?
  
Sorry for the delay.

Here is what I am getting after applying the patch:
gmake[2]: Leaving directory `/tmp/llvm-build/2.7/llvm-objects/lib/CodeGen'
gmake[1]: Leaving directory `/tmp/llvm-build/2.7/llvm-objects/lib'
gmake[1]: Entering directory `/tmp/llvm-build/2.7/llvm-objects/tools/llvm-shlib'
llvm[1]: Linking Release Shared Library LLVM-2.7.so
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0x135): In function `(anonymous namespace)::ARMAsmParser::ParseDirective(llvm::AsmToken)':
: undefined reference to `__assert'
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0x3e3): In function `(anonymous namespace)::ARMAsmParser::ParseDirective(llvm::AsmToken)':
: undefined reference to `__assert'
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0x5d8): In function `(anonymous namespace)::ARMAsmParser::ParseDirective(llvm::AsmToken)':
: undefined reference to `__assert'
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0xd10): In function `(anonymous namespace)::ARMAsmParser::MatchRegisterName(llvm::StringRef const&)':
: undefined reference to `memcmp'
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0xd45): In function `(anonymous namespace)::ARMAsmParser::MatchRegisterName(llvm::StringRef const&)':
: undefined reference to `memcmp'
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0xd6d): In function `(anonymous namespace)::ARMAsmParser::MatchRegisterName(llvm::StringRef const&)':
: undefined reference to `memcmp'
/tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVMARMAsmParser.a(ARMAsmParser.o)(.text+0xdd5): In function `(anonymous namespace)::ARMAsmParser::MaybeParseRegister((anonymous namespace)::ARMOperand&, bool)':
: undefined reference to `__assert'

Linking command line was:
/usr/local/gcc/4.5.0/bin/g++ -I/tmp/llvm-build/2.7/llvm-objects/include -I/tmp/llvm-build/2.7/llvm-objects/tools/llvm-shlib -I/tmp/llvm-build/2.7/llvm/include -I/tmp/llvm-build/2.7/llvm/tools/llvm-shlib -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -O2 -fno-exceptions -fno-rtti -fPIC -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -O2 -Wl,-R -Wl,/tmp/llvm-build/2.7/llvm-objects/Release/lib -L/tmp/llvm-build/2.7/llvm-objects/Release/lib -L/tmp/llvm-build/2.7/llvm-objects/Release/lib -shared -o /tmp/llvm-build/2.7/llvm-objects/Release/lib/libLLVM-2.7.so -Wl,--whole-archive -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -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 -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 -lm

Adding -lc in the end fixes the errors and produces the full size libLLVM-2.7.so.

Yuri

Jeffrey Yasskin wrote:

Would you try the patch at
http://codereview.appspot.com/download/issue968046_1.diff? It should
make the BSDs fall into the same path as Linux, and since you use gnu
ld, that should work for you.
    
Ping?
  
I also noticed that during the build in llvm-gcc-4.2-objects on sparc machine there is also a step:
llvm[1]: Linking Release Shared Library LLVM-2.7.so
Linking command is the similar (or same) as in llvm-objects.
It fails just like the same command in llvm-objects. And adding -lc in the end saves it.
I guess this is a bug in the Makefile because libLLVM-2.7.so already exists and --enable-llvm= is specified to configure.

Not sure why this didn't fail the same way on i386.

Yuri

That's odd. On Linux, g++ adds -lc to the end of the link line itself.
It must be adding -lstdc++ for you too, or you'd have more missing
symbols. If you run that command with "-v", it'll show you the actual
link line, but given your errors it does seem like -lc is missing. I
don't think it'll hurt anyone else to add that, so I'll try it.

I assume builds without --enable-shared do work for you? If so, I
wonder why g++ would omit -lc for shared links but not executable
links?

Jeffrey

Jeffrey Yasskin wrote:

That's odd. On Linux, g++ adds -lc to the end of the link line itself.
It must be adding -lstdc++ for you too, or you'd have more missing
symbols. If you run that command with "-v", it'll show you the actual
link line, but given your errors it does seem like -lc is missing. I
don't think it'll hurt anyone else to add that, so I'll try it.
  
That looks odd to me too, but somehow this happens. I used the patch to fix this, see attachment.

I assume builds without --enable-shared do work for you? If so, I
wonder why g++ would omit -lc for shared links but not executable
links?
  
Yes, without --enable-shared everything is fine.

Yuri

llvm-patch-so.diff (476 Bytes)

Jeffrey Yasskin wrote:

That's odd. On Linux, g++ adds -lc to the end of the link line itself.
It must be adding -lstdc++ for you too, or you'd have more missing
symbols. If you run that command with "-v", it'll show you the actual
link line, but given your errors it does seem like -lc is missing. I
don't think it'll hurt anyone else to add that, so I'll try it.

I assume builds without --enable-shared do work for you? If so, I
wonder why g++ would omit -lc for shared links but not executable
links?
  
Jeffrey,

There is one more thing:
there is no complete debug info in libLLVM-2.7.so when built with flags: --enable-assertions --enable-shared --enable-libffi --enable-debug-runtime --enable-debug-symbols --disable-optimized, at least not on FreeBSD.

I use, as we discussed before, two attached patches to make shared lib build on FreeBSD.

Resulting library has the size ~22MB. Same size as the Release one.
Debugger refuses to enter functions: no debug info.

libLLVM-2.7.so with the full debug info is ~158MB.

I don't know why this command would loose debug info.

Yuri

--- command that makefile runs to build debug libLLVM-2.7.so ---

/usr/local/gcc/4.5.0/bin/g++ -I/tmp/llvm-build/2.7/llvm-objects/include -I/tmp/llvm-build/2.7/llvm-objects/tools/llvm-shlib -I/tmp/llvm-build/2.7/llvm/include -I/tmp/llvm-build/2.7/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 -L/usr/local/lib -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -g -Wl,-R -Wl,/tmp/llvm-build/2.7/llvm-objects/Debug/lib -L/tmp/llvm-build/2.7/llvm-objects/Debug/lib -L/tmp/llvm-build/2.7/llvm-objects/Debug/lib -shared -lc -o /tmp/llvm-build/2.7/llvm-objects/Debug/lib/libLLVM-2.7.so \
           -Wl,--whole-archive -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -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 -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

llvm-patch-so.diff (476 Bytes)

issue968046_1.diff (847 Bytes)