[all-commits] [llvm/llvm-project] c384ca: [ELF] For relative paths in INPUT() and GROUP(), s...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Apr 22 12:35:02 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: c384ca3c6a49197c3f752b64871379cb673d52b9
      https://github.com/llvm/llvm-project/commit/c384ca3c6a49197c3f752b64871379cb673d52b9
  Author: Fangrui Song <maskray at google.com>
  Date:   2020-04-22 (Wed, 22 Apr 2020)

  Changed paths:
    M lld/ELF/ScriptLexer.h
    M lld/ELF/ScriptParser.cpp
    A lld/test/ELF/linkerscript/input-relative.s

  Log Message:
  -----------
  [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




More information about the All-commits mailing list