http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46097

--- Comment #23 from Jeffrey Walton <noloader at gmail dot com> 2010-10-21 
19:52:12 UTC ---
Hi Jonathan,

[Sorry about the top post].

I'm going to wrap up my request, and hope you and the GCC team will find that
-Wglobal-variable would be useful under some circumstances.

When you and the team examine the merits of the request, remember that we [the
dumb users] probably did not know about the finer details of the interactions
between shared objects, global objects with destructors (is this c++
specific?), multiple processes, RTLD_GLOBAL, the ABI, and ODR. If we were
aware, we probably would not have made the mistake in the first place.

====

The GCC team is probably tired of seeing questions about this issue. So a
warning to reduce list chatter might be warranted.

====

Your points about when the warning should be issued are valid. But the warning
would be incredibly useful when a "perfect storm" rises (interactions between
shared objects, global objects with destructors, multiple processes,
RTLD_GLOBAL, the ABI, and ODR.).

I feel history has shown that users and distribution packagers have gotten it
wrong too often and too easily.

====

RTFM is great, but I can't help but feel, "what manual should I read" since
searching for "shared object crash" and "SO crash" returned the phone book with
no real useful information.

Once you pointed out the missing references and pieces, everything fell into
place (and I will never make the mistakes again).

====

Wei Dai only provided a static archive of Crypto++. The library was being
packaged as a shared object by distributions because of a rule somewhere that
that required a system provided library.

The first sign of an issue for Crypto++ was a mailing list post titled, "Errors
with multiple loading cryptopp as shared lib on Linux". So Crypto++ was
actually collateral damage.

====

The next project to get pinged was Tahoe Least-Authoritative File System (Tahoe
LAFS), which used Crypto++. Zooko Wilcox-O'Hearn, one of the project's leads,
build bot alerted him of the issue. So Tahoe LAFS was also collateral damage.

===

Finally, crashes due to this issue degrade the user experience, so the user is
the ultimate loser (and not just collateral damage).

Jeffrey Walton
Baltimore, MD, US

==============================

(In reply to comment #0)
> Feature reqeust only. Not a bug.
> 
> C++ shared objects are an interesting beast under certain circumstances (many
> times, the shared object acts like a generic C module). Interesting includes:
> * C++ module
> * Shared object
> * Shared object throws an exception which will cross module boundaries
> * Shared object opened with RTLD_GLOBAL
> * Shared object has global objects with destructors
> 
> Lots have been said about C++ exceptions, RTTI, type equality for the
> 'catch(const Exception&)', and RTLD_GLOBAL (versus RTLD_LOCAL) [1,2,3,4,5].
> 
> When a module meets the above compile and runtime requirements, a crash can
> occur in global objects with destructors when more than one process loads and
> subsequently unloads a shared object.
> 
> A switch to warn of global variables in a compilation unit would be very
> helpful for those who are aware of the issue (and the circumstances to
> encounter the issue). It appears that GCC does not supply such a switch [6].
> 
> The switch would be useful for module writers since its not always feasible to
> 'hand audit' all project files. And a warning would be exetremely useful for
> package maintainers who don't write the module - they simply fixup the code 
> and
> package it for a distribution.
> 
> Perhaps -Wglobal-variable?
> 
> Jeffrey Walton
> Baltimore, MD, US
> 
> [1] Minimal GCC/Linux shared lib + EH bug example,
> http://gcc.gnu.org/ml/gcc/2002-05/msg00866.html
> [2] dlopen and placing exception body in .cpp file,
> http://gcc.gnu.org/ml/gcc-help/2010-08/msg00290.html
> [3] Comparing types across SOs (sic),
> http://groups.google.com/group/cryptopp-users/browse_thread/thread/eb815f228db50380
> [4] Errors with multiple loading cryptopp as shared lib on Linux,
> http://groups.google.com/group/cryptopp-users/browse_thread/thread/68fbc22e8c6e2f48
> [5] RTLD_GLOBAL and libcryptopp.so crash,
> http://groups.google.com/group/cryptopp-users/browse_thread/thread/7eae009a4e02e726
> [6] Audit Use of Global Variables in C++ Shared Object (GCC Warning?), 
> GCC-Help
> mailing list, October, 2010 [not yet indexed].

Reply via email to