mips/masm/reltab.c

44 lines
796 B
C
Raw Normal View History

2024-09-11 16:06:09 +00:00
#include <elf.h>
#include <stdlib.h>
#include <merror.h>
#include "asm.h"
#define RELTAB_INIT_LEN 8
int reltab_init(struct relocation_table *reltab)
{
reltab->size = RELTAB_INIT_LEN;
reltab->len = 0;
reltab->data = malloc(sizeof(Elf32_Rela) * RELTAB_INIT_LEN);
if (reltab->data == NULL) {
2024-09-22 20:02:42 +00:00
PERROR("cannot alloc");
2024-09-11 16:06:09 +00:00
return M_ERROR;
}
return M_SUCCESS;
}
void reltab_free(struct relocation_table *reltab)
{
free(reltab->data);
}
int reltab_push(struct relocation_table *reltab, const Elf32_Rela rel)
{
if (reltab->len >= reltab->size) {
reltab->size *= 2;
reltab->data = realloc(reltab->data, sizeof(Elf32_Rela)
* reltab->size);
if (reltab->data == NULL) {
2024-09-22 20:02:42 +00:00
PERROR("cannot realloc");
2024-09-11 16:06:09 +00:00
return M_ERROR;
}
}
reltab->data[reltab->len++] = rel;
return M_SUCCESS;
}