NyuziToolchain icon indicating copy to clipboard operation
NyuziToolchain copied to clipboard

Support PIC relocation model

Open jbush001 opened this issue 7 years ago • 4 comments

Currently backend is hardcoded to use static linking model. Add support to compile as position independent code. This would save allow loading shared libraries in an efficient way.

  • NyuziISelLowering::LowerGlobalAddress should call TargetMachine::getRelocationModel and generate code to access global offset table (GOT).
  • NyuziISelLowering::LowerCall should check relocation model and use procedure linkage table (PLT) if necessary
  • Create GOT and PLT fixup types and relocations. Add code to NyuziElfObjectWriter::getRelocType to handle.
  • In NyuziMCInstLower::LowerSymbolOperand, may need custom code to generate GOT and PLT symbol types
  • In NyuziMCCodeEmitter, add code to generate fixups
  • In tools/lld, add relocation handling for GOT and PLT types.
  • Switch lookup tables need to be made offsets instead of absolute addresses.

jbush001 avatar Apr 22 '17 21:04 jbush001

There isn't a use case for this, since it requires shared libraries and an OS, which don't exist yet.

jbush001 avatar Apr 23 '17 04:04 jbush001

Status: Working:

  • Global addresses are emitted with GOT fixups, the linker can will create the GOT section and relocate indices.

Not working/to do:

  • Relative offsets for switch statements (needs addend)
  • Function prologue code to initialize GP
  • External call support/PLT

jbush001 avatar Jan 07 '18 06:01 jbush001

Switch statements fixed in 37f47d83889d00ae251c3a5ae9450db128874b3d.

jbush001 avatar Jan 08 '18 04:01 jbush001

Call addresses are now in the GOT: 26b78085e557028f8e4d239d84d6ab3afff1313a

jbush001 avatar Jan 10 '18 04:01 jbush001