Implemented a bunch of relocations found in binaries with medium/large code model and the Local-Exec TLS model. The binaries link and run fine in Qemu.
In addition, the emulation elf64_sparc is now recognized.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
My immediate reaction is "isn't Sparc an abandoned architecture?" See https://en.wikipedia.org/wiki/SPARC and https://lists.freebsd.org/pipermail/freebsd-sparc64/2020-January/010192.html
Though, no objection. You may still need some basic tests, similar to test/ELF/ppc32-* I tried hard to keep the number of tests small yet complete. Does sparc64 use TLS variant 2?
Just as a note for things that are still missing:
- GD/LD/IE TLS (you mentioned IE TLS, but this only does *LE*)
- The HIX22/LOX10 (and others) family for GOTDATA that replaces R_SPARC_GOT22/10
- R_SPARC_REGISTER, needed to mark how each of the %g[2367] (could have the exact numbers wrong, they're from deep in my memory) are being used by the object files to as to ensure they don't conflict. It's a very unusual relocation (refers to magic STT_SPARC_REGISTER symbols) that should have designed using something other than a relocation...
There may be others, but as one of the SPARC porters in Debian that's what I can think of off the top of my head.
For FreeBSD, yes, and mostly within LLVM (certainly nobody really uses LLD). The non-release Debian architecture is still going strong though. SPARC (32-bit and 64-bit) is basically the same as IA-32 (although not with the weird calling convention and triple leading underscores), and one of the architectures described in Drepper's original TLS white paper, so yes, variant II.
If the intention is improve Sparc, the integrated assembler issues (rL254199) should be addressed.
https://lists.llvm.org/pipermail/llvm-dev/2017-June/114437.html mentioned a plan to revive the support but I believe the situation has not been improved... The codegen maintainer has moved on (left) since 2014..
Improving SPARC support is fine as long as we don't need to do something special for the ISA. But since no active maintainers have a SPARC machine, it is hard to find bugs in SPARC. Can you add tests for the new relocations?
For what it's worth, I have access to various SPARC machines, so can test things as needed. Also, the GCC compile farm (https://cfarm.tetaneutral.net/machines/list/) has multiple SPARC machines; in particular, gcc202 is managed by us Debian sparc64 porters, and has a beefy 64 cores and 64 GiB on a T5 (which, unlike some of the earlier UltraSparcs, has decent single-threaded performance too), so it should be easy for maintainers to test things if they're interested enough. The compile farm is a great resource in general that is really easy to sign up for and most don't know about.
If the SPARC community is interested in lld, it shouldn't be too hard to make lld usable for SPARC, so it is up to the community.
I've added a few tests that cover the newly-added relocations plus a few more, R_SPARC_LM22 is not yet tested because LLVM as doesn't recognize it but I already have a patch ready for that.
My immediate reaction is "isn't Sparc an abandoned architecture?"
Well somebody asked if Zig could target sparc64/linux so I guess there's at least a small group of users interested in it. Since we exclusively use lld I decided to fix this roadblock, this patch isn't meant to be exhaustive but focuses on the missing relocations I've found in the binaries produced by Zig.
Does sparc64 use TLS variant 2?
AFAIR it's one of the few non-x86 arches to use it
you mentioned IE TLS, but this only does *LE*
Typo, the relocations also have "LE" in the name :)
For FreeBSD that is the case. FreeBSD/sparc64 always seemed to be on life support. Unlike FreeBSD / NetBSD, OpenBSD's sparc64 port is fully supported and supports the latest and greatest with regard to sparc64.
We're very close to switching to Clang as the system compiler on sparc64.
Can you refer me to the sparc psABI so that I can verify the implementation?
lld/test/ELF/sparcv9-reloc.s | ||
---|---|---|
6 | objdump -s does not need --no-show-raw-insn. |
lld/ELF/Driver.cpp | ||
---|---|---|
152 | Add a test similar to emulation-arm.s The other emulation-* have verbose llvm-readobj output. Don't copy them. |
lld/test/ELF/emulation-sparc.s | ||
---|---|---|
3 | You can drop -unknown-linux. FreeBSD/OpenBSD's triples don't have the OS part. Without the OS part, it usually means the generic ELF behavior. For an object file, it is usually better to use %t.o or similar. For an executable, %t usually suffices. When there are more than one, Use %t1 %t2 ... (I know that some existing tests don't follow the convention.) And the existing emulation-* do not follow the best practice. | |
9 | Add -T before a linker script (you may name it %t.lds, shorter than %t.script) GNU ld warns without -T | |
11 | If there are no other prefixes, just use the FileCheck default CHECK. You can omit --check-prefix as well. |
Can you (or anyone) commit this on my behalf? I don't have commit access.
lld/test/ELF/emulation-sparc.s | ||
---|---|---|
11 | I've picked the V9 prefix as LLD may want to support the 32bit variants some day |
Add a test similar to emulation-arm.s
The other emulation-* have verbose llvm-readobj output. Don't copy them.