Implement --just-symbols.
Details
Diff Detail
- Repository
- rLLD LLVM Linker
Event Timeline
This doesn't implement the -R switch name, which is the traditional interface from time immemorial. I can use --just-symbols, but you really should handle -R too.
Just copying symbol values will suffice for my case, but it's not really the right semantics. The rest of the ElfNN_Sym fields matter too.
This crashes on my case. I don't know what a trivial test case that would make it crash might look like, but I'll send you my actual case separately.
lld/ELF/Driver.cpp | ||
---|---|---|
1065 ↗ | (On Diff #120497) | --just-symbols (double dash), better known in traditional Unix as -R. |
1068 ↗ | (On Diff #120497) | s/programs/program/ |
lld/ELF/InputFiles.cpp | ||
1053 ↗ | (On Diff #120497) | --just-symbols (double dash) |
1055 ↗ | (On Diff #120497) | The canonical semantics are to copy all the other fields as well, not just st_value. |
lld/ELF/InputFiles.h | ||
62 ↗ | (On Diff #120497) | --just-symbols |
lld/ELF/Options.td | ||
150 ↗ | (On Diff #120497) | --just-symbols is the GNU long option for this, but -R is the original switch. |
lld/ELF/SymbolTable.cpp | ||
---|---|---|
145 ↗ | (On Diff #120497) | Stray debugging output. |
lld/ELF/InputFiles.cpp | ||
---|---|---|
1055 ↗ | (On Diff #120497) | Yeah that's true, but I wonder if real programs depend on it. |
If the only input file is specified as the argument of --just-symbol, lld will error out (ld.bfd accepts this):
$ riscv64-unknown-linux-gnu-ld.lld -r --just-symbols foo.o -o bar.o riscv64-unknown-linux-gnu-ld.lld: error: no input files riscv64-unknown-linux-gnu-ld.lld: error: target emulation unknown: -m or at least one .o file required
I'd suggest adding a separate kind of InputFile whose symbols only gets added to the symbol table as absolute (but don't add its sections). I have a patch that implements this if you'd like to review it.
It can be used to produce an object file containing the offset of symbols in vdso:
https://github.com/riscv/riscv-linux/blob/ae64f9bd1d3621b5e60d7363bc20afb46aede215/arch/riscv/kernel/vdso/Makefile#L41
Works for me. D41277 works just as well. I don't know how you plan to reconcile the two.
I tried to create file objects for --just-symbols so that the linker command that just specifies --just-symbols without any real object file works fine.
https://reviews.llvm.org/D42025
But I really like this one over that one. The other one isn't necessarily bad, but it looks like it is a bit too complicated for a use case that I doubt is realistic. So my preference is to submit this one.