NyuziToolchain
NyuziToolchain copied to clipboard
Support PIC relocation model
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.
There isn't a use case for this, since it requires shared libraries and an OS, which don't exist yet.
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
Switch statements fixed in 37f47d83889d00ae251c3a5ae9450db128874b3d.
Call addresses are now in the GOT: 26b78085e557028f8e4d239d84d6ab3afff1313a