This is an archive of the discontinued LLVM Phabricator instance.

[ELF][MIPS] N32 ABI support
ClosedPublic

Authored by atanasyan on Nov 4 2016, 2:41 AM.

Details

Summary

In short the patch introduces support for linking object file conform MIPS N32 ABI [1]. This ABI is similar to N64 ABI but uses 32-bit pointer size.

The most non-trivial requirement of this ABI is one more relocation packing format. N64 ABI puts multiple relocation type into the single relocation record. The N32 ABI uses series of successive relocations with the same offset for this purpose. In this patch, new function mergeMipsN32RelTypes handle this case and "convert" N32 relocation to the N64 relocation so the rest of the code keep unchanged.

For now, linker does not support series of relocations applied to sections without SHF_ALLOC bit. Probably later I will add the support or insert some sort of assert into the relocateNonAlloc routine to catch this case.

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan updated this revision to Diff 76915.Nov 4 2016, 2:41 AM
atanasyan retitled this revision from to [ELF][MIPS] N32 ABI support.
atanasyan updated this object.
atanasyan added a reviewer: ruiu.
atanasyan set the repository for this revision to rL LLVM.
atanasyan added a project: lld.
atanasyan added a subscriber: llvm-commits.
ruiu edited edge metadata.Nov 4 2016, 11:46 AM

Overall looking good.

ELF/Driver.cpp
686 ↗(On Diff #76915)

Can you move this to isCompatible in SymbolTable.cpp?

ELF/Relocations.cpp
589 ↗(On Diff #76915)

Could you return a pair of number of processed symbols and a merged type, so that this function becomes a pure function?

590 ↗(On Diff #76915)

I think Elf_Addr is always 32 bit, so I'd replace with uint32_t.

645 ↗(On Diff #76915)

std::next(I) -> I + 1

atanasyan updated this revision to Diff 76967.Nov 5 2016, 3:27 AM
atanasyan edited edge metadata.
  • mergeMipsN32RelTypes is pure function now
  • Elf_Addr is replaced by uint32_t in the mergeMipsN32RelTypes arguments
  • std::next(I) -> I + 1

Now the linker recognizes N32 ABI emulation flags in the parseEmulation. If a user does not provide -m flag, the linker deduces ABI in the inferMachineType function. Compatibility checking is moved to the isCompatible routine.

ruiu accepted this revision.Nov 5 2016, 10:00 AM
ruiu edited edge metadata.

LGTM

ELF/Mips.cpp
351 ↗(On Diff #76967)

Can you return true/false instead of a flag and then rename this isMipsN32Abi?

This revision is now accepted and ready to land.Nov 5 2016, 10:00 AM
This revision was automatically updated to reflect the committed changes.