Design: relocation link parameters should be structs and enums
m4b opened this issue · 0 comments
Terminology:
- link - a relocation declaration for some symbol to another symbol
E.g., we do link
and link_import
as current api.
Name subject to change if its confusing.
Purpose
This will remove the extremely unfriendly and bad API ambiguity of to/from
(which is which) in the parameters, and allow easier extensions to the kind of relocation link it is.
For example, will need to eventually add GOT loads.
How to express this?
Well, a GOT load is actually loading data exposed by a shared library, so technically it is an import.
Consequently, we should make link_import
have something like the following signature:
type Offset = usize;
struct Link<'a> {
to: &'a str,
from: &'a str,
at: Offset
}
enum ImportKind {
Call(local: bool),
Data,
}
fn link_import(link: Link, kind: ImportKind);
When this is a Call
we generate the appropriate JMP_REL
or BRANCH
relocation (with the local boolean indicating if it is local to this object or not); when it when it is Data
, we generate a GOT load (TODO: need to check what this looks like on ELF exactly).