LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1434 - Assertion failed in llvm-ld when linking a library
Summary: Assertion failed in llvm-ld when linking a library
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Bitcode Reader (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail, regression
Depends on:
Blocks:
 
Reported: 2007-05-17 14:14 PDT by Zhiru Zhang
Modified: 2010-03-06 13:59 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments
test files (1.03 KB, application/octet-stream)
2007-05-17 14:17 PDT, Zhiru Zhang
Details
foo.c (43 bytes, text/plain)
2007-05-17 14:20 PDT, Zhiru Zhang
Details
libfoo.c (37 bytes, text/plain)
2007-05-17 14:21 PDT, Zhiru Zhang
Details
libfoo.a (634 bytes, application/octet-stream)
2007-05-17 14:22 PDT, Zhiru Zhang
Details
foo.bc (524 bytes, application/octet-stream)
2007-05-17 14:23 PDT, Zhiru Zhang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zhiru Zhang 2007-05-17 14:14:20 PDT
My llvm-ld crashed (assertion failure) when I tried to link a bc library.
Will attached the test files later. 

What I did is:

llvm-gcc -c -O0 -emit-llvm libfoo.c -o libfoo.bc
llvm-ar cru libfoo.a libfoo.bc
llvm-ranlib libfoo.a
llvm-gcc -c -O0 -emit-llvm foo.c -o foo.bc

llvm-ld foo.bc libfoo.a -o all.bc 
(and llvm-ld foo.bc -lfoo -o all.bc)

Both produce the following error:

==========================================================================
llvm-ld: /home/llvm/lib/VMCore/Value.cpp:57: virtual llvm::Value::~Value(): 
Assertion `use_begin() == use_end() && "Uses remain when a value is 
destroyed!"' failed.
llvm-ld((anonymous namespace)::PrintStackTrace()+0x1a)[0x84e61b6]
llvm-ld((anonymous namespace)::SignalHandler(int)+0x110)[0x84e64de]
/lib/tls/libc.so.6[0x683898]
/lib/tls/libc.so.6(abort+0xe9)[0x685209]
/lib/tls/libc.so.6(__assert_fail+0x101)[0x67cd91]
llvm-ld(llvm::Value::~Value()+0x1c4)[0x84a2dd6]
llvm-ld(llvm::User::~User()+0x1b)[0x82ee97f]
llvm-ld(llvm::Constant::~Constant()+0x1b)[0x82eeab7]
llvm-ld(llvm::GlobalValue::~GlobalValue()+0x34)[0x845921e]
llvm-ld(llvm::Function::~Function()+0x9d)[0x8454cdb]
llvm-ld(llvm::iplist<llvm::Function, llvm::ilist_traits<llvm::Function> 
>::erase(llvm::ilist_iterator<llvm::Function>)+0x33)[0x8367a15]
llvm-ld(llvm::iplist<llvm::Function, llvm::ilist_traits<llvm::Function> 
>::erase(llvm::ilist_iterator<llvm::Function>, 
llvm::ilist_iterator<llvm::Function>)+0x21)[0x8479465]
llvm-ld(llvm::iplist<llvm::Function, llvm::ilist_traits<llvm::Function> 
>::clear()+0x53)[0x84794e7]
llvm-ld(llvm::Module::~Module()+0x2a)[0x84785ea]
llvm-ld(std::auto_ptr<llvm::Module>::~auto_ptr()+0x1f)[0x82af817]
llvm-ld(llvm::Linker::LinkInArchive(llvm::sys::Path const&, 
bool&)+0x618)[0x82de55a]
llvm-ld(llvm::Linker::LinkInLibrary(std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&, bool&)+0x239)[0x82d09b3]
llvm-ld(llvm::Linker::LinkInItems(std::vector<std::pair<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, bool>, 
std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, 
std::allocator<char> >, bool> > > const&, 
std::vector<std::pair<std::basic_string<char, std::char_traits<char>, 
std::allocator<char> >, bool>, std::allocator<std::pair<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, bool> > >&)+0x87)[0x82d0c51]
llvm-ld(main+0x5e2)[0x82ac518]
/lib/tls/libc.so.6(__libc_start_main+0xd3)[0x670de3]
llvm-ld(__gxx_personality_v0+0x149)[0x82a4041]
Aborted
Comment 1 Zhiru Zhang 2007-05-17 14:17:47 PDT
Created attachment 857 [details]
test files
Comment 2 Zhiru Zhang 2007-05-17 14:20:40 PDT
Created attachment 858 [details]
foo.c
Comment 3 Zhiru Zhang 2007-05-17 14:21:10 PDT
Created attachment 859 [details]
libfoo.c
Comment 4 Zhiru Zhang 2007-05-17 14:22:35 PDT
Created attachment 860 [details]
libfoo.a
Comment 5 Zhiru Zhang 2007-05-17 14:23:35 PDT
Created attachment 861 [details]
foo.bc
Comment 6 Reid Spencer 2007-05-17 14:33:58 PDT
This is confirmed. I can replicate the behavior.
Comment 7 Reid Spencer 2007-05-17 15:18:42 PDT
The debugger is not being friendly on this one. There is a use of a linked
function remaining that causes the assertion. It is supposed to print out
details about that, but doesn't. Furthermore, I can't get the debugger to break
in there so it is really hard to figure out where the dangling use is coming from. 
Comment 8 Reid Spencer 2007-05-17 18:08:50 PDT
This is also a problem on the release 2.0 branch so its been around for at least
a week.
Comment 9 Zhiru Zhang 2007-05-17 18:15:57 PDT
This build is OK: "2007-05-04 7:00". 
Comment 10 Reid Spencer 2007-05-17 18:22:57 PDT
Thanks Zhiru, that helps. Perhaps I can find it by comparing changes since then.
Comment 11 Reid Spencer 2007-05-17 20:52:08 PDT
I've tracked it down to being just a problem with archives. The only difference
since May 4th is that it was changed to work with BitCode. As I suspected, I
think there's some interaction between ModuleProvider and BitCode that is
causing the Module to be created incorrectly.
Comment 13 Chris Lattner 2007-05-17 23:04:06 PDT
This is a serious regression from 2.0.

Fixed, patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070514/049805.html

Testcase here: test/Linker/link-archive.ll

Many thanks to Reid for helping put the pieces together and create the testcase.

-Chris