title: How to resolve '__tls_get_addr@@GLIBC_2.3' error on compiling GCC itself?
body: <p><strong>The Background:</strong> A client has a set of legacy SuSE servers which require glibc updating to patch the 'Ghost' vulnerability. These machines have never been updated and are running old versions of gcc and glibc from about 2005. Attempting to compile current glibc gives errors that a more up to date gcc is required, so I am attempting to upgrade gcc.</p>
  
  <p><strong>The problem:</strong>  A very long way through the make for gcc, it fails with the following error (short version - longer version further down post):</p>
  
  <pre><code>undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'
  /lib64/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p><strong>Research and investigations already tried:</strong></p>
  
  <p>From Googling I know this is a linker issue.  The gcc infrastructure systems, including ld, have all been upgraded successfully to binutils-2.25</p>
  
  <p>I've tried changing <code>LDFLAGS =</code> to <code>LDFLAGS = -lz</code> in the Makefile, which is suggested as a fix for similar problems affecting Oracle installs, but this makes no difference.</p>
  
  <p>I've tried installing a slightly older gcc (4.8 instead of 4.92), gives the same error at the same place.</p>
  
  <p>Unfortunately trying to search for issues relating to compiling gcc itself tends to produce lots of results about using gcc to compile other things, making searches difficult.</p>
  
  <p><strong>Detailed background and error message:</strong></p>
  
  <p>Installing gcc has many prerequisites, before I could get this install under way I had to upgrade gmp, mpfr, and mpc. Gmp and mpfr installed successfully, but it was only possible to get mpc to compile by adding <code>--disable-shared</code> to the ./configure command.</p>
  
  <p>A full list of what has been installed:</p>
  
  <pre><code>binutils-2.25, gmp-4.3.2, mpfr-2.4.2, mpc-0.8.1
  </code></pre>
  
  <p>Configuration command (running from an adjacent build directory as recommended by the gcc team):</p>
  
  <pre><code>../gcc-4.9.2/configure --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local
  </code></pre>
  
  <p>The full error message:</p>
  
  <blockquote>
    <p>make[3]: Entering directory <code>/usr/local/src/gcc-4.9.2-build/gcc'
    /usr/local/src/gcc-4.9.2-build/./prev-gcc/xg++
    -B/usr/local/src/gcc-4.9.2-build/./prev-gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -nostdinc++ -B/usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs
    -B/usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs  -I/usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu
    -I/usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/include
    -I/usr/local/src/gcc-4.9.2/libstdc++-v3/libsupc++ -L/usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs
    -L/usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs   -g -O2 -gtoggle -DIN_GCC    -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc  -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o
    c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o
    c/c-array-notation.o c-family/c-common.o c-family/c-cppbuiltin.o
    c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o
    c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o
    c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o
    c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-cilkplus.o
    c-family/array-notation-common.o c-family/cilk.o c-family/c-ubsan.o
    i386-c.o glibc-c.o \   cc1-checksum.o libbackend.a main.o 
    libcommon-target.a libcommon.a ../libcpp/libcpp.a
    ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a<br>
    ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a
    ../libdecnumber/libdecnumber.a   -L/usr/local/lib -L/usr/local/lib
    -L/usr/local/lib -lmpc -lmpfr -lgmp -rdynamic -ldl  -L../zlib -lz /usr/local/x86_64-unknown-linux-gnu/bin/ld:
    /usr/local/src/gcc-4.9.2-build/prev-x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.a(eh_globals.o):
    undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'
    /lib64/ld-linux-x86-64.so.2: error adding symbols: DSO missing from
    command line collect2: error: ld returned 1 exit status make[3]: ***
    [cc1] Error 1 make[3]: Leaving directory
    </code>/usr/local/src/gcc-4.9.2-build/gcc' make[2]: <strong>* [all-stage2-gcc]
    Error 2 make[2]: Leaving directory <code>/usr/local/src/gcc-4.9.2-build'
    make[1]: *** [stage2-bubble] Error 2 make[1]: Leaving directory
    </code>/usr/local/src/gcc-4.9.2-build' make: *</strong> [all] Error 2</p>
  </blockquote>