diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-11 12:06:09 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-11 12:06:09 -0400 |
commit | e3d2e31377030e84066bed4bbc04bf6c56206305 (patch) | |
tree | d5e7428212606a0f64d5b2e628b3f507948b8e2f /masm/reltab.c | |
parent | joe (diff) | |
download | mips-e3d2e31377030e84066bed4bbc04bf6c56206305.tar.gz mips-e3d2e31377030e84066bed4bbc04bf6c56206305.tar.bz2 mips-e3d2e31377030e84066bed4bbc04bf6c56206305.zip |
refactor
Diffstat (limited to 'masm/reltab.c')
-rw-r--r-- | masm/reltab.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/masm/reltab.c b/masm/reltab.c new file mode 100644 index 0000000..482ed44 --- /dev/null +++ b/masm/reltab.c @@ -0,0 +1,43 @@ +#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) { + ERROR("cannot alloc"); + 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) { + ERROR("cannot realloc"); + return M_ERROR; + } + } + + reltab->data[reltab->len++] = rel; + return M_SUCCESS; +} |