Skip to content

Missing symbols in libLLVM.so when built with clang-4.0 #32508

Closed
@tstellar

Description

Bugzilla Link 33161
Version trunk
OS Linux
Attachments Test Program, Makefile for testcase
CC @chandlerc,@DougGregor,@zygoloid,@jwakely

Extended Description

There are some symbols missing from libLLVM.so when built with clang-4.0. I can reproduce this when building libLLVM.so from trunk (r303802) and libLLVM.so from the llvm 4.0 source. I cannot reproduce this when libLLVM.so is built with gcc-4.8.5.

I think the issue has something to do with the use of 'extern template class AnalysisManager<Loop, LoopStandardAnalysisResults &>;' in LoopAnalysisManager.h, but I'm not sure if it is a bug in the LLVM source code that just happens to work when compiled by gcc, or if it is a miscompile by clang.

I was looking at the difference between the clang built and llvm built shared objects and I see:

$ nm --demangle libLLVM-4.0.so.clang4.0 \
| grep 'llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)'

00000000013af5f0 W llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)
00000000013af5f0 W llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)

$ nm --demangle check-for-broken-symbol.sh libLLVM-4.0.so.gcc4.8.5
| grep 'llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)'

00000000013f12d0 W llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)
00000000013f12d0 W llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)
00000000013f12d0 t llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)
00000000013f12d0 t llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)

Attached is a simple program to demonstrate the issue. Make sure to set LLVM_LIB_PATH and LLVM_INCLUDE_PATH in the Makefile to the correct paths for your system, and make sure that libLLVM.so has been built by clang.

To reproduce:

$ make gcc-main
gcc -D__STDC_CONSTANT_MACROS -std=c++11 -o gcc-main.o -c main.cpp -I /home/tstellar/llvm-project/llvm-install/include/
gcc -o gcc-main -L /home/tstellar/llvm-project/llvm-install/lib -lLLVM-4.0 -lstdc++ gcc-main.o
gcc-main.o: In function main': main.cpp:(.text+0x1c): undefined reference to llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)'

I also noticed that if I build main.cpp with clang, then the program links correctly:

$ make clang-main
clang -D__STDC_CONSTANT_MACROS -std=c++11 -o clang-main.o -c main.cpp -I /usr/include/
gcc -o clang-main -L /usr/lib -lLLVM -lstdc++ clang-main.o

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillabuild-probleminvalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions