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.
|1065 ↗||(On Diff #120497)|
--just-symbols (double dash), better known in traditional Unix as -R.
|1068 ↗||(On Diff #120497)|
|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.
|62 ↗||(On Diff #120497)|
|150 ↗||(On Diff #120497)|
--just-symbols is the GNU long option for this, but -R is the original switch.
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:
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.
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.