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 1493 - internalize zapping global constructors
Summary: internalize zapping global constructors
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Interprocedural Optimizations (show other bugs)
Version: 1.9
Hardware: PC Linux
: P normal
Assignee: Chris Lattner
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2007-06-03 14:02 PDT by Maarten ter Huurne
Modified: 2010-02-22 12:47 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
Build and test script (271 bytes, application/x-shellscript)
2007-06-03 14:03 PDT, Maarten ter Huurne
Details
C++ source with the std::map definition (43 bytes, text/x-c++src)
2007-06-03 14:04 PDT, Maarten ter Huurne
Details
C++ source with the main() function (122 bytes, text/x-c++src)
2007-06-03 14:05 PDT, Maarten ter Huurne
Details
Build and test script (235 bytes, application/x-shellscript)
2007-06-03 14:07 PDT, Maarten ter Huurne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maarten ter Huurne 2007-06-03 14:02:07 PDT
See attached sources and build+test script.

The bug occurs only when compiling to bytecode and then linking the bytecode 
into a single executable. When I use llvm-g++ to compile each C++ source to 
native object files and link those, the executable runs fine.

Running the bytecode of the executable in lli also produces a segfault.

The std::map, although unused in the code, is essential for the segfault to 
occur. Also, the segfault only occurs when I use two source files: when I put 
this same code in a single C++ source file, it runs fine.

The std::map being part of the problem looks similar to bug 1491, but not 
exactly the same:
- this bug occurs when running the native executable, no errors while linking
- this bug also occurs without -O2

I'm using LLVM 2.0 and its g++ front-end, compiled from source with GCC 4.1.3.
Comment 1 Maarten ter Huurne 2007-06-03 14:03:09 PDT
Created attachment 995 [details]
Build and test script
Comment 2 Maarten ter Huurne 2007-06-03 14:04:39 PDT
Created attachment 996 [details]
C++ source with the std::map definition
Comment 3 Maarten ter Huurne 2007-06-03 14:05:11 PDT
Created attachment 997 [details]
C++ source with the main() function
Comment 4 Maarten ter Huurne 2007-06-03 14:07:04 PDT
Created attachment 998 [details]
Build and test script
Comment 5 Anton Korobeynikov 2007-06-03 14:14:37 PDT
Maarten, llvm-ld also runs optimizations. It seems, that static ctors/dtors were
deleted by llvm-ld (this can be due to PR1491). Please use llvm-link as a
temporary workaround.
Comment 6 Maarten ter Huurne 2007-06-04 21:23:09 PDT
I just retested after applying the fix for bug 1491 to LLVM and llvm-g++. The 
resulting binary still segfaults, so it seems this is a separate bug.

Using llvm-link as a workaround indeed avoids the problem.
Comment 7 Chris Lattner 2007-06-06 15:10:46 PDT
taking a look
Comment 8 Chris Lattner 2007-06-06 15:53:31 PDT
Fixed, patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070604/050302.html

This was due to some legacy code that was used to support llvm-gcc3.  The easiest thing to do is to zap it 
entirely.  Thanks for the report and the nice reduced testcase!

-Chris