def gen_relocation_data(offsets):
    """
    Given a list of offsets (offsets are in multiples of pointer length),
    output bytes to put in the relocation section's data.
    """
    
    last_offset = 0
    out = b''
    for o in offsets:
        distance = o - last_offset
        
        if distance > 0x3ff:
            b = distance.to_bytes(4, byteorder='big')
            b = bytes([b[0] | 0xc0]) + b[1:]
        elif distance > 0x3f:
            b = distance.to_bytes(2, byteorder='big')
            b = bytes([b[0] | 0x80]) + b[1:]
        else:
            b = distance.to_bytes(1, byteorder='big')
            b = bytes([b[0] | 0x40]) + b[1:]
        
        out += b
        last_offset = o
    
    out_size = len(out) + 4
    out = out_size.to_bytes(4, byteorder='little', signed=False) + out # prepend length
    
    # pad to 16 bytes
    while len(out) % 16:
        out += b'\x00'
    
    return out