OSDN Git Service

[ELF] For relative paths in INPUT() and GROUP(), search the directory of the current...
authorFangrui Song <maskray@google.com>
Thu, 9 Apr 2020 04:45:21 +0000 (21:45 -0700)
committerFangrui Song <maskray@google.com>
Wed, 22 Apr 2020 19:34:20 +0000 (12:34 -0700)
commitc384ca3c6a49197c3f752b64871379cb673d52b9
treeaef8bed4d727b168595695d82ba87a25e072c84d
parentcd66970b371240d90e163d2020c1a42bb2b7e1b9
[ELF] For relative paths in INPUT() and GROUP(), search the directory of the current linker script before searching other paths

For a relative path in INPUT() or GROUP(), this patch changes the search order by adding the directory of the current linker script.
The new search order (consistent with GNU ld >= 2.35 regarding the new test `test/ELF/input-relative.s`):

1. the directory of the current linker script (GNU ld from Binutils 2.35 onwards; https://sourceware.org/bugzilla/show_bug.cgi?id=25806)
2. the current working directory
3. library paths (-L)

This behavior makes it convenient to replace a .so or .a with a linker script with additional input. For example, glibc

```
% cat /usr/lib/x86_64-linux-gnu/libm.a
/* GNU ld script
*/
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /usr/lib/x86_64-linux-gnu/libm-2.29.a /usr/lib/x86_64-linux-gnu/libmvec.a )
```

could be simplified as `GROUP(libm-2.29.a libmvec.a)`.

Another example is to make libc++.a a linker script:
```
INPUT(libc++.a.1 libc++abi.a)
```

Note, -l is not affected.

Reviewed By: psmith

Differential Revision: https://reviews.llvm.org/D77779
lld/ELF/ScriptLexer.h
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/input-relative.s [new file with mode: 0644]