Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Dec 2012 22:00:41 +0100
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r244600 - head/contrib/binutils/bfd
Message-ID:  <50D61F79.3070705@FreeBSD.org>
In-Reply-To: <201212222046.qBMKkkcJ049291@svn.freebsd.org>
References:  <201212222046.qBMKkkcJ049291@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2012-12-22 21:46, Dimitry Andric wrote:
> Author: dim
> Date: Sat Dec 22 20:46:46 2012
> New Revision: 244600
> URL: http://svnweb.freebsd.org/changeset/base/244600
>
> Log:
>    Fix a bug in ld --gc-sections: it strips out .note sections, while it
>    should never do so.  This can cause global constructors and destructors
>    to not be executed at run-time, resulting in crashes and other strange
>    behaviour.

Sample program:

   #include <iostream>

   class Foo {
   public:
     Foo() { std::cout << "Foo::Foo()" << std::endl; }
     ~Foo() { std::cout << "Foo::~Foo()" << std::endl; }
   };

   Foo foo;

   int main(void)
   {
     std::cout << "main()" << std::endl;
     return 0;
   }

Compiling this normally is fine:

   $ c++ gctest.cpp -o gctest
   $ ./gctest
   Foo::Foo()
   main()
   Foo::~Foo()
   $ readelf -n gctest

   Notes at offset 0x0000014c with length 0x00000030:
     Owner                 Data size       Description
     FreeBSD              0x00000004       NT_VERSION (version)
     FreeBSD              0x00000004       NT_ARCH (architecture)

Linking with --gc-sections makes it crash:

   $ c++ gctest.cpp -o gctest -Wl,--gc-sections
   $ ./gctest
   Segmentation fault (core dumped)
   $ readelf -n gctest
   [...no output...]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50D61F79.3070705>