On Thu, 12 Aug 2010 10:24:43 +1200
John Huttley <[email protected]> wrote:
> I've been reading Flameeye's blog.
> He's been happy that  "--as-needed" is now the default.
> 
> I have no idea what its all about.
> Could you let us know if that affects us?

Paludis uses the same profiles as Portage, so yes, it affects you.

As for what --as-needed does: it tells the linker to ignore specific
requests from package developers to link against a particular library,
and instead makes the linker link against some arbitrary subset of
those libraries.

This is held to be a good idea by certain people because if liba uses
libb, and pkg links against liba, and if libtool is involved, then pkg
will end up linked against both liba and libb. This means that if libb
breaks, pkg breaks.

There are two problems with that argument, though. The first is that
the whole thing is libtool's fault, not the linker's fault, and the
solution should be to fix libtool to only emit direct dependencies on
platforms where that is supported. The second is that Gentoo doesn't
slot certain libraries when it should, so breakages happen far more
often than necessary.

On top of that, --as-needed's "ignore what the developer says"
behaviour breaks perfectly correct code, often in ways that won't be
caught at build time. For example:

ciar...@snowcone tmp 0 0.00 $ cat plugin.hh 
#include <string>

void register_plugin(const std::string &);

ciar...@snowcone tmp 0 0.00 $ cat app.cc 
#include "plugin.hh"
#include <list>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <cstdlib>

struct Plugins
{
    static Plugins * get_instance()
    {
        static Plugins instance;
        return &instance;
    }

    std::list<std::string> list;
};

void register_plugin(const std::string & s)
{
    Plugins::get_instance()->list.push_back(s);
}

int main(int, char *[])
{
    if (Plugins::get_instance()->list.empty())
    {
        std::cerr << "I have no plugins!" << std::endl;
        return EXIT_FAILURE;
    }
    else
    {
        std::copy(
                Plugins::get_instance()->list.begin(),
                Plugins::get_instance()->list.end(),
                std::ostream_iterator<std::string>(std::cout, "\n"));
        return EXIT_SUCCESS;
    }
}

ciar...@snowcone tmp 0 0.00 $ g++ -W -Wall -o app.o -c app.cc 
ciar...@snowcone tmp 0 0.00 $ cat cowplugin.cc 
#include "plugin.hh"

struct RegisterPlugin
{
    RegisterPlugin()
    {
        register_plugin("a big smelly cow");
    }
} register_cowplugin;

ciar...@snowcone tmp 0 0.08 $ g++ -W -Wall -fPIC -shared -o libcowplugin.so 
cowplugin.cc 
ciar...@snowcone tmp 0 0.02 $ g++ -L . -l cowplugin -o app app.o
ciar...@snowcone tmp 0 0.02 $ LD_LIBRARY_PATH=./ ./app 
a big smelly cow
ciar...@snowcone tmp 0 0.02 $ g++ -Wl,--as-needed -L . -l cowplugin -o app app.o
ciar...@snowcone tmp 0 0.02 $ LD_LIBRARY_PATH=./ ./app 
I have no plugins!
ciar...@snowcone tmp 1 0.02 $ 

-- 
Ciaran McCreesh

Attachment: signature.asc
Description: PGP signature

_______________________________________________
paludis-user mailing list
[email protected]
http://lists.pioto.org/mailman/listinfo/paludis-user

Reply via email to