Bug linking using ld 2.19?

Dave Gittins dave.gittins@gmail.com
Tue Apr 15 10:57:00 GMT 2014


Hi

Sorry if this is a known issue or a stupid question, but I couldn't
figure it out.

> cat foo.cpp
#include <string>
int main(int argc, const char** argv)
{
    std::string A = "blah";
    std::string B = "bluh";
    return A==B;
}

> g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> ld --version
GNU ld version 2.20.51.0.2-5.36.el6 20100205
Copyright 2009 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

> g++ -o foo foo.cpp && ./foo

...all good.


But if I redirect to binutils 2.19 the result is a bit broken:

> /somewhere/else/bin/ld --version
GNU ld (GNU Binutils) 2.19.1
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

> g++ -o foo foo.cpp -B /somewhere/else/bin && ./foo
Segmentation fault (core dumped)


gdb shows the seg fault when trying to call memcmp:

Program terminated with signal 11, Segmentation fault.
#0  0x0000000000600ef0 in memcmp@@GLIBC_2.2.5 ()

That offset, 600ef0, is in totally the wrong place - nowhere near
where pmap reports libc being loaded. The working code has a much
larger offset for memcmp.


If I build with gcc 4.4.0 instead of 4.4.7, I get exactly the same
result - linking with ld 2.19.1 is broken and linking with ld 2.20.51
is fine.

Obviously, all my woes go away as soon as I use more recent versions
of binutils etc, but this is causing some issues right now and I would
like to understand what's going on here anyway. Is this a bug in ld,
or is there some other reason why this doesn't work?

Any help appreciated
D



More information about the Gcc-help mailing list