Created attachment 15274 [details] minimal reproduction of problem I am observing that the sections of an archive file explicitly mentioned in an input section of a linker script within the /DISCARD/ output section does not get discarded if the -T option on an ld invocation is given after mentioning a .o file that has an undefined symbol which is found in a section of an object file within said archive. It was not clear to me in the documentation what the expected behavior is. Attached is a Makefile and sources reproduction on an x86_64 Ubuntu machine. When I run `make`, I get an error like so: undefined reference to `libfoo_getmsg'/ When I run `make clean && make SCRIPT_LAST=1`, it works. It seems that indeed the position of the linker script is a key factor. Furthermore, if one changes the linker script from `libfoo.a (*)` to `foo.o (*)`, the `make` command succeeds regardless of the position of the linker script argument. I suspect that all of this has some complex explanation involving wildcard matches, but I couldn't figure it out.
Another interesting note, a `.o` file mentioned on the command line is only searched for the current directory, but a `.o` file mentioned in an input section description gets searched for in the current directory and in the library search path. Perhaps this distinction should be mentioned in the manual?
Oh one more note, `gold` discards the section no matter what.