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):
- the directory of the current linker script (GNU ld from Binutils 2.35 onwards; https://sourceware.org/bugzilla/show_bug.cgi?id=25806)
- the current working directory
- 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)
Now that the rules are getting a bit more complicated. It would be good to have a comment like Gold that explains them.