Avoiding relocation offsets
Jeffrey Lee (213) 6048 posts |
I’m currently working on modifying the shared C library so that when a client registers, if there are multiple versions of a routine available (e.g. software vs. hardware division) the client’s stubs will link directly to the version that’s most appropriate for the machine. Part of this involves modifying the way CLib stores the list of routines that are to be exported to the client (it’s just a list of entries produced using the Entry macro) so that each entry can either be a direct pointer to a function or a pointer to a “variant table” which describes which variants (versions) of a particular routine exist and when to use them. Because each build of CLib is optimised according to the CPU architecture(s) that it targets, it makes sense to only generate variants for the situations where they’ll be needed. But building that selection logic into the Entry macro would be messy – it’s too far away from the location where the actual code is, and the two locations could easily get out of sync. So to solve this I thought I’d try using some pointer hackery – if it’s a regular routine the symbol that the Entry macro generates a reference to will be word aligned. If it’s a variant table then it won’t be word aligned (this also requires the Entry macro to use e.g. To allow Entry to store unaligned addresses I’ve had to change it from using “ This is almost certainly a bug in the toolchain, but before I give up and go with a different approach I was wondering if anyone knew of a way of generating an unaligned address offset which doesn’t trigger a relocation at runtime. I’ve tried |