Feeds

Binary interfaces in component development

A template class with static data - how can that possibly go wrong?

Choosing a cloud hosting partner with confidence

Part 2 In the first part of this series we looked at how problems emerge when we make the transformation from source code to binary code, and we saw that even when the code is correct errors can be introduced by using dynamic libraries instead of a monolithic binary.

With some simple examples, we’re starting to see problems, using a logically correct C++ program for which we cannot construct a physical representation using dynamic libraries because of platform constraints.

In software security, the industry experts speak of security exposures that occur in the interactions between systems. I think we’re now seeing a similar issue with the interaction of the abstract C++ system and the physical portable executable format system; but instead of a security problem, we get bugs.

Our example comes from real life code, and a large development team that has lived with consequent problems in its Windows environment for a long time, which have cost a lot of money. The issue comes from the interaction of two C++ language features that behave unexpectedly when combined with dynamic linking. We’ll see how on Windows that code packaged in dynamic libraries doesn’t behave in accordance with the C++ language, and we’ll see how to use tools to investigate and resolve the problem. The code we’ll use to expose this insidious problem is shown in the following generic implementation of the Singleton pattern. As we’ll see, this code works fine provided it is not used with dynamic libraries:

// GenericSingleton.hpp
template <typename T>
class GenericSingleton
{
public:
   T &getInstance();

private:
   static T m_instance;
};

template <typename T>
T & GenericSingleton<T>::getInstance()
{
    return m_instance;
}

template <typename T>
T GenericSingleton<T>::m_instance; 

There’s a template class with all of its definitions in the header file. This organisation of a class template is common, perhaps because placing the template definitions in the header file avoids lots of annoying linker warnings. However, as we’ll see, this practice leads to problems once the transition is made from a small monolithic binary program to a modular software system composed of interacting dynamic libraries.

Firstly, why is this code problematic in conjunction with dynamic libraries? There are issues here on Windows and on Linux, but the manifestations of the problems are different.

Beginner's guide to SSL certificates

More from The Register

next story
PEAK APPLE: iOS 8 is least popular Cupertino mobile OS in all of HUMAN HISTORY
'Nerd release' finally staggers past 50 per cent adoption
Microsoft to bake Skype into IE, without plugins
Redmond thinks the Object Real-Time Communications API for WebRTC is ready to roll
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
Mozilla: Spidermonkey ATE Apple's JavaScriptCore, THRASHED Google V8
Moz man claims the win on rivals' own benchmarks
FTDI yanks chip-bricking driver from Windows Update, vows to fight on
Next driver to battle fake chips with 'non-invasive' methods
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
Ubuntu 14.10 tries pulling a Steve Ballmer on cloudy offerings
Oi, Windows, centOS and openSUSE – behave, we're all friends here
Was ist das? Eine neue Suse Linux Enterprise? Ausgezeichnet!
Version 12 first major-number Suse release since 2009
prev story

Whitepapers

Cloud and hybrid-cloud data protection for VMware
Learn how quick and easy it is to configure backups and perform restores for VMware environments.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
Protecting against web application threats using SSL
SSL encryption can protect server‐to‐server communications, client devices, cloud resources, and other endpoints in order to help prevent the risk of data loss and losing customer trust.