0

I wanted to upgrade to binutils 2.26 , so i followed the steps here : How to convert default binutils into binutils-2.26? to solve the same "unrecognized relocation" error.

Now my default linker is 2.26

$ ld --version


GNU ld (GNU Binutils for Ubuntu) 2.26.1
Copyright (C) 2015 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.

But "make" still uses the "/usr/bin/x86_64-linux-gnu-ld" (which is 2.24) and still gives the same error.

So how to force "make" to use the default linker ?

AE1
  • 25
  • 5
  • You'll better upgrade your entire distribution. Ubuntu 14 is ancient. So upgrade to the current [Ubuntu 18.04](https://www.ubuntu.com/download/desktop) – Basile Starynkevitch Dec 27 '18 at 09:36
  • @BasileStarynkevitch you are write , But i wanted to understand why is "make" not choosing the default linker – AE1 Dec 27 '18 at 09:53
  • 1
    Because it is not `make` which chooses it. See my answer. – Basile Starynkevitch Dec 27 '18 at 09:54
  • 1
    The very short answer is, make doesn't choose it. Make invokes a shell and tells it to run whatever commands you've provided in the recipe for the rule (indented by TAB characters). It has no idea what those commands do or how they do it... it's _identical_ to you typing that command into a shell prompt and hitting ENTER. Since you haven't shown us what commands those are (make will print them out before it runs them, unless you've suppressed its output), there's little else we can say about it. – MadScientist Dec 27 '18 at 13:06

1 Answers1

0

It depends upon your Makefile (which you could debug with remake -x). Notice that make has a lot of builtin rules. Use make -p to also print them. Notice the rules mentioning LINK.c or LINK.cc etc, and notice that LD is not much used. Notice also that ld is almost never used directly (most of the time, some other program like gcc or g++ runs it).

And it is also a matter of the PATH variable. So try setting it so that your new ld comes before the old one.

Generally, you link with the gcc or g++ program (so it is GCC which matters, not make; read about Invoking GCC and its -fuse-ld=), and that gcc or g++ will run the linker (you might, but I don't recommend to, change its spec file which governs what actual programs are run by gcc or g++ which are only drivers to other programs such as cc1, as, ld, collect2 etc...). To understand what programs gcc or g++ is running, pass it the -v flag.

But "make" still uses the "/usr/bin/x86_64-linux-gnu-ld" (which is 2.24) and still gives the same error.

On my Debian system /usr/bin/x86_64-linux-gnu-ld (it is generally started by gcc, not directly by make) is a symlink. You might (but I don't recommend that) just change that symlink.


BTW, you are using an ancient Ubuntu 14. You'll better upgrade your entire distribution (e.g. to Ubuntu 18.04.1 LTS at end of 2018), because there is not only ld but many other programs which are really old on your system.

Upgrading your distribution will take less time than upgrading, compiling, installing and configuring each individual tool.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • for the PATH variable, I did exactly what said. And noticed the change in the default `ld` , I can delete this linker and then it will use my new default. But i think that is not right. It seems strange that `make` doesn't use the default linker – AE1 Dec 27 '18 at 09:54
  • As I am explaining, it is `gcc` which chooses a linker in practice. Very probably, your `make` *never* runs `ld` directly. – Basile Starynkevitch Dec 27 '18 at 09:55
  • you are right , when i tried `gcc -v` I can see `--with-ld=/usr/bin/x86_64-linux-gnu-ld`. not sure how to change it to chose the default, But I think this answers my question in the most part. – AE1 Dec 27 '18 at 14:43
  • As I answered, if you want to choose that permanently, you'll change or add a `spec` file. But you really should update your entire distribution – Basile Starynkevitch Dec 27 '18 at 14:52