LWN.net Logo

Bundled == old

Bundled == old

Posted Apr 8, 2012 19:47 UTC (Sun) by cmccabe (guest, #60281)
In reply to: Bundled == old by epa
Parent article: Wheeler: Insecure open source software libraries?

The Matrix library doesn't have to have knowledge of type Foo. Matrix<Foo> will be instantiated when the application is built. All of that works fine-- yes, even with dynamically linked libraries. Let's not forget, libstdc++ is a dynamically linked library itself, and it's stuffed full of templates.

The problems start when you try to deal with versioning. Basically, templates make creating any kind of backwards-compatible API much harder. This is one reason why the libstdc++ std::string still uses a reference-counted implementation, despite the fact that it's known to be slow on modern multi-threaded machines. Changing std::string (otherwise known as std::basic_string <char, traits, alloc>) would just break too many things.

There are other problems with handling versioning in C++. The KDE guys made a good writeup describing how to make backwards-compatible changes to C++ libraries here: http://techbase.kde.org/Policies/Binary_Compatibility_Iss...


(Log in to post comments)

Bundled == old

Posted Apr 9, 2012 14:02 UTC (Mon) by HelloWorld (guest, #56129) [Link]

> The Matrix library doesn't have to have knowledge of type Foo. Matrix<Foo> will be instantiated when the application is built. All of that works fine-- yes, even with dynamically linked libraries. Let's not forget, libstdc++ is a dynamically linked library itself, and it's stuffed full of templates.
The template stuff isn't linked dynamically (except maybe for a few explicitly instanciated templates). In fact, many template libraries, such as boost spirit, boost xpressive or Eigen consist solely of headers.

Bundled == old

Posted Apr 9, 2012 16:41 UTC (Mon) by cmccabe (guest, #60281) [Link]

Templates may or may not have external linkage. It depends on how they were instantiated. It's perfectly possible, for example, for the shared library to use explicit instantiation to create Matrix<Foo>, Matrix<Bar>, and Matrix<Baz>. On the other hand, since a lot of the benefit of this kind of templating comes from inlining, this would probably not be the style used in a matrix multiplication library.

It's also possible for templates declared in a header file and instantiated in library client code (inline) to call functions from a shared library. This is where most of the version skew problems come from, since when the library client is linked against another version of the shared library, he will not update his inlined templates, but will be using different versions of those functions.

Bundled == old

Posted Apr 10, 2012 9:19 UTC (Tue) by epa (subscriber, #39769) [Link]

I'm not sure I understand you rightly, but I always thought that it was impossible for a library to provide Matrix<Foo> unless the author of the library already knew about the Foo type. If Foo is a type specific to your application, it's not going to be something your matrix library knows about. Is that no longer the case with today's C++ toolchains?

Bundled == old

Posted Apr 10, 2012 15:22 UTC (Tue) by cmccabe (guest, #60281) [Link]

No, you can't instantiate Matrix<Foo> without knowing about type Foo. I'm just saying that there are a lot of templates out there that aren't inlined.

My biggest point, if I have one, is that mixing the inlined and non-inlined stuff is what creates the versioning problems.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds