compiler: Make shared-code linking helpers safe

95deb3c620620120cc43f8a44f9388bdeec352208adcd7931a60008e39f9f4a4
Alexis Sellier committed ago 1 parent 4af3a3b7
lib/std/arch/rv64/shared.rad +3 -3
155 155
        else => throw Error::Symbol,
156 156
    }
157 157
}
158 158
159 159
/// Patch a PC-relative call or function address load.
160 -
unsafe fn relative(e: &mut emit::Emitter, index: u32, base: u64, target: u64, rd: gen::Reg, call: bool)
160 +
fn relative(e: &mut emit::Emitter, index: u32, base: u64, target: u64, rd: gen::Reg, call: bool)
161 161
    throws (Error)
162 162
{
163 163
    let delta = image::displacement(base + index as u64 * 4, target) else {
164 164
        throw Error::Range;
165 165
    };
171 171
        emit::patch(e, index + 1, encode::addi(rd, rd, parts.lo));
172 172
    }
173 173
}
174 174
175 175
/// Link shared code against local definitions and dependency exports.
176 -
unsafe fn link(e: &mut emit::Emitter, base: u64, local: &[Symbol], imports: &[Symbol]) throws (Error) {
176 +
fn link(e: &mut emit::Emitter, base: u64, local: &[Symbol], imports: &[Symbol]) throws (Error) {
177 177
    for i in 0..e.pendingCallsLen {
178 178
        let pending = e.pendingCalls[i];
179 179
        let address = try function(local, imports, pending.target);
180 180
        try relative(e, pending.index, base, address, super::SCRATCH1, true);
181 181
    }
226 226
    /// Private pointer fixup count.
227 227
    relocations: u32,
228 228
}
229 229
230 230
/// Build initialized bytes and compact private pointer fixups.
231 -
unsafe fn template(items: *[il::Data], local: &[Symbol], imports: &[Symbol], bytes: &mut [u8], relocs: &mut [Relocation])
231 +
fn template(items: *[il::Data], local: &[Symbol], imports: &[Symbol], bytes: &mut [u8], relocs: &mut [Relocation])
232 232
    -> TemplateSize throws (Error)
233 233
{
234 234
    let mut initialized: u32 = 0;
235 235
    let mut count: u32 = 0;
236 236
    for item in items {