[Kde-pim] Using gold linker as default

Andreas Hartmetz ahartmetz at gmail.com
Fri Jun 25 02:05:03 BST 2010


On Thursday 24 June 2010 17:07:54 Harald Sitter wrote:
> [snip]
> Now what you can do is manually change the link to point to what you want
> OR, which is the better idea (because of the way it is packaged) you
> should just define the appropriate linker manually via cmake argument foo.
> I would recommend to have a shell alias here - ldcmake or goldcmake or
> something.
> [snip]

That doesn't work. The linker is invoked via gcc, and gcc's search path can be 
changed via the environment variable GCC_EXEC_PREFIX. But it probably expects 
other things in there besides ld, making things a bit more difficult. Changing 
the linker in CMake doesn't do anything AFAIK because it is never invoked 
explicitly.
I'm using a neat trick to switch the linker with very little effort: I have a 
stub executable the execs either bfd-ld or gold depending on the value of an 
environment variable. It's only a few lines, you might want to copy it.
Modify to suit your local environment...

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    const char *ld_env_var = getenv("USE_GOLD_LINKER"); // "USE_GOLD_LINKER" 
kids, mmmkay?
    const char *linker_name = 0;
    if (ld_env_var && ld_env_var[0] != '\0' ) {
        // OK, the environment variable exists and it has nonzero length...
        argv[0] = "/usr/bin/ld.gold";
        linker_name = "gold";
    } else {
        argv[0] = "/usr/bin/ld.bfd";
        linker_name = "BFD ld";
    }

    if (execvp(*argv, argv) < 0) {
        fprintf(stderr, "** exec failed. Probably the %s executable %s was not 
found.\n", linker_name, argv[0]);
        return -1;
    }

    //unreachable
    fprintf(stderr, "Cosmic ray registered.\n");
    return -1;
}

Cheers,
Andreas
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list