This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Add basic 64-bit SPARC support
ClosedPublic

Authored by kettenis on Jun 26 2017, 7:22 AM.

Details

Summary

Add support for the most common SPARC relocations.
Make DT_PLTGOT point to the PLT on SPARC.
Mark the PLT as executable on SPARC.

This adds a basic test that creates a SPARV9 executable that invokes the exit system call on OpenBSD.

Diff Detail

Repository
rL LLVM

Event Timeline

kettenis created this revision.Jun 26 2017, 7:22 AM
ruiu edited edge metadata.Jun 26 2017, 7:59 AM

Overall looking good. Thank you for doing this!

Can you give me a pointer to the ABI documentation?

lld/ELF/Arch/SPARCV9.cpp
44 ↗(On Diff #103942)

Is SPARC always 8k page?

59 ↗(On Diff #103942)

In lld we try to avoid string comparison as it is slow. If you need to do this, you can add a new member GlobalOffsetTable to ElfSym defined in Symbols.h and compare a given symbol with that.

61 ↗(On Diff #103942)

Use LLVM_FALLTHROUGH.

86 ↗(On Diff #103942)

Is SPARCV9 big-endian only?

lld/ELF/SyntheticSections.cpp
1093 ↗(On Diff #103942)

nit: since there are only three choices, I'd do it with if ~ else if ~ else ~.

1638–1639 ↗(On Diff #103942)

This is interesting. Can you describe why the .plt segment has to be writable on Sparc? I'd like to add a comment here about the background.

ruiu added a comment.Jun 26 2017, 8:11 AM

I added GlobalOffsetTable to ElfSym in r306292 for you.

For 64-bit SPARC (SPARCV9) the relevant document is https://sparc.org/wp-content/uploads/2014/01/SCD.2.4.1.pdf.gz. Older versions and related documents are available at https://sparc.org/technical-documents/specifications/.

kettenis marked 5 inline comments as done.Jun 26 2017, 8:46 AM
kettenis added inline comments.
lld/ELF/Arch/SPARCV9.cpp
44 ↗(On Diff #103942)

Yes, for SPARV9 the minumum page size is 8k. Older (32-bit only) SPARV7 processor supported smaller page sizes. That hardware is now more than 20 years old and pretty much dead. OpenBSD doesn't support 32-bit SPARC anymore, so I didn't write any code for it. But if somebody else is interested in doing that, bits of the SPARCV9 code could be re-used.

59 ↗(On Diff #103942)

Thanks.

61 ↗(On Diff #103942)

Will do.

86 ↗(On Diff #103942)

Instruction access is always big-endian. In theory it is possible to run the processor in a mode where the default data access is little-endian, which could affect some of the relocations listed here. In practice nobody ever supported this. The GNU toolchain only ever supported little-endian 32-bit SPARC using the a.out format.

lld/ELF/SyntheticSections.cpp
1093 ↗(On Diff #103942)

I think the switch here is better. Future support for 32-bit SPARC would straightforward that way.

1638–1639 ↗(On Diff #103942)

I'll add a comment.

emaste added inline comments.Jun 26 2017, 10:02 AM
lld/test/lit.cfg
248–249 ↗(On Diff #103942)

sort these first in a separate commit?

fedor.sergeev added inline comments.Jun 26 2017, 11:37 AM
lld/ELF/Arch/SPARCV9.cpp
44 ↗(On Diff #103942)

Yep, 8K page size is minimum.
As for 32-bit SPARC - we on Solaris will be rather interested in getting V8 code later.
Thanks for doing V9! :)

lld/ELF/SyntheticSections.cpp
1093 ↗(On Diff #103942)

Agreed, please, keep the switch.

jyknight added inline comments.Jun 26 2017, 12:21 PM
lld/ELF/Arch/SPARCV9.cpp
44 ↗(On Diff #103942)

Just to keep the record straight, SparcV8 (via the LEON4 chip and others) is _far_ from dead. It sees quite active use in embedded processors, including ones still being developed and produced today.

Possibly it'll be dead someday, but that day has not yet come.

(Note, I do _not_ mean to imply any objection to this patch supporting only sparcv9 to start with).

86 ↗(On Diff #103942)

Little-endian sparcv8 exists in the wild, and is supported and used in clang upstream.

However, AFAIK, nobody has ever built a little-endian SparcV9 system. (and, I suspect, probably never will).

kettenis marked 5 inline comments as done.Jun 26 2017, 1:40 PM

Was thinking about the older SPARCV7 CPUs used in the sun4 and sun4c machines when I made that remark. But it seems that even the SPARCV8 reference MMU uses a 4K page size. Nevertheless one would probably still use 8K as the "minimum" page size for 32-bit code to allow code to run on SPARCV9 hardware. That is what the GNU toolchain does.

kettenis added inline comments.Jun 27 2017, 2:03 AM
lld/test/lit.cfg
248–249 ↗(On Diff #103942)

If somebody with commit access can do this for me I'll "rebase" the diff.

support for the most common SPARC relocations

I wonder how did you determine "the most common"?
Say, you did implement WDISP19 but skipped WDISP22 and WDISP16.
Just curious...

emaste added inline comments.Jun 27 2017, 5:22 AM
lld/test/lit.cfg
248–249 ↗(On Diff #103942)

Ok, done in rL306403

ruiu added a comment.Jun 27 2017, 8:49 AM

Can you rebase this patch and fix these comments?

lld/ELF/SyntheticSections.cpp
1093 ↗(On Diff #103942)

I have a different taste. I think if ~ else if ~ else is better (and you can convert to switch later), but since it's not important, I'm ok in either way.

support for the most common SPARC relocations

I wonder how did you determine "the most common"?
Say, you did implement WDISP19 but skipped WDISP22 and WDISP16.
Just curious...

I just added the ones I encountered while linking some (simple) programs on OpenBSD/sparc64. Certainly plan to add more as I encounter them in the future. Supporting additional relocations is easy, but not completely trivial and having an actual example makes it easier to verify you got it right ;).

kettenis updated this revision to Diff 104386.Jun 28 2017, 5:31 AM

New diff that addresses the comments raised so far.

kettenis marked an inline comment as done.Jun 28 2017, 5:32 AM
kettenis added inline comments.
lld/test/lit.cfg
248–249 ↗(On Diff #103942)

Thanks!

ruiu accepted this revision.Jun 28 2017, 8:17 AM

LGTM

lld/ELF/SyntheticSections.cpp
1638–1639 ↗(On Diff #103942)
This revision is now accepted and ready to land.Jun 28 2017, 8:17 AM
This revision was automatically updated to reflect the committed changes.