11

My build fails with the following linker error message:

FAILED: : && /usr/bin/g++ -Wall -Wextra -Werror -g -fsanitize=undefined,address -Wno-unused-parameter -fsanitize=undefined,address -rdynamic *.o -o SCE -Wl,-rpath,/opt/qt59/lib /opt/qt59/lib/libQt5Widgets.so.5.9.1 /usr/local/lib/libprotobuf.a -lpthread -lutil -lgrpc++ /opt/qt59/lib/libQt5Gui.so.5.9.1 /opt/qt59/lib/libQt5Core.so.5.9.1 && :
/usr/bin/x86_64-linux-gnu-ld: unrecognized option '--push-state--no-as-needed'

You can see the full build log here. The error is in line 2211 and versions are printed in lines 2104ff.

Which tool causes the error?

  • Is gcc 7.3.0 using an incorrect linker flag? The ld documentation indicates that --push-state and --no-as-needed are separate commands.
  • Is ld 2.28 too old to understand the linker flag? The change log doesn't list anything that seems related.
  • The command && /usr/bin/g++ looks odd, it should be /usr/bin/g++. Using make instead of ninja shows the same linking error.

It builds correctly on Debian testing which is using gcc 7.3.0 as well and ld 2.30, but there doesn't seem to be a working binutils-2.30 ppa for Ubuntu Trusty.

How do I successfully build my project on Travis?

nwp
  • 9,623
  • 5
  • 38
  • 68
  • 2
    I can confirm this with Gcc7 on Ubuntu 16.04 using CMake (make and ninja). Gcc6 and Clang 4-6 work fine; Gcc7 also works fine locally (Arch). – ollo Apr 25 '18 at 17:24
  • 1
    Turning of the undefined-behavior sanitizer seems to "solve" the problem. Most likely a bug in g++. – levzettelin Apr 25 '18 at 20:46
  • Probably this: https://launchpad.net/ubuntu/+source/gcc-7/7.3.0-16ubuntu2 – levzettelin Apr 25 '18 at 21:08
  • Oddly, I'm having the problem with GCC 5, 6 and 7. No such problem on Debian Stretch with hand-rolled 7.3.0. Turning off the sanitizer also fixes it for me, thanks. I notified Travis support about 14h ago and will update them. – John McFarlane Apr 26 '18 at 05:55
  • 8
    The simple fix is to use gold linker by passing `-fuse-ld=gold` option to gcc – makerj Apr 27 '18 at 15:43
  • 1
    @makerj That actually works. Consider making that an answer. – nwp May 01 '18 at 15:11
  • 3
    If you're only using `-fsanitize=undefined`, another workaround that seems to help: you don't need to link against the sanitizer if you tell the compiler to trap at run time: `-fsanitize-undefined-trap-on-error`. – John McFarlane May 31 '18 at 15:30

2 Answers2

11

GCC 7 is fixed with 7.3.0-16ubuntu3 (tested on Ubuntu 18.04). This version is available though the Ubuntu Toolchain Test PPA (for 16.04.1 and 14.04).

Tested with Make only, but it should work with Ninja too. Both Sanitizer, ASan and UBsan, enabled.

There's not much related to this problem in the changelog though:

gcc-7 (7.3.0-16ubuntu3) bionic; urgency=medium

  • Update to SVN 20180415 (r259389) from the gcc-7-branch.
    • Fix PR libstdc++/85222.
  • Remove our own PR libstdc++/85222 backport.

Update:

GCC 7 (7.3.0-16ubuntu3) is still broken on Ubuntu 16.04 and earlier.

What you can do to workaround this:

A. Update to Ubuntu 18.04

The problem is fixed on Ubuntu 18.04 (LTS)'s Gcc7.


B. Dockerize and update to Ubuntu 18.04

If an update is not possible, eg. running on a CI system, it's still an option to use Docker and an up-to-date Ubuntu.


C. Disable UB Sanitizer

The Problem occurs only when using GCC7 with UB Sanitizer enabled. As tobias-brüll noted in the comments: Turning the UB Sanitizer off prevents the error.


D. Use Gold Linker

Another workaround posted by makerj: Using the Gold Linker doesn't cause the problem.

Eg. on CMake pass it through the CMAKE_EXE_LINKER_FLAGS:

cmake -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold ..
ollo
  • 24,797
  • 14
  • 106
  • 155
  • What is going wrong [here](https://travis-ci.org/Toeger/SCE/jobs/379386713#L487)? It looks like it is using the ppa you linked, yet the error persists. – nwp May 15 '18 at 20:23
  • Seems it's fixed only on Ubuntu 18.04. That's really bad. I've updated my answer accordingly. – ollo May 18 '18 at 15:35
1

If option D (from ollo's answer) is not working for you try next commands:

sudo add-apt-repository ppa:jonathonf/binutils --yes
sudo apt-get update -qq --yes
sudo apt-get install -qq --yes --force-yes binutils

This is from: https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/travis/before_install.x86_64-asan.sh

And the issue was discribed here: https://github.com/Project-OSRM/osrm-backend/issues/3216

pr3sto
  • 71
  • 1
  • 8