summaryrefslogtreecommitdiffstats
path: root/src/strip.c
diff options
context:
space:
mode:
authorAndreas Schwab <[email protected]>2018-10-02 14:46:51 +0200
committerMark Wielaard <[email protected]>2018-10-13 22:54:51 +0200
commit2876b3b648f665736ac9c879d34de5e3866ba8f9 (patch)
treebe631dee293e01847e3eea43343b0d249a7532c6 /src/strip.c
parent69d6e67eee30c483ba53a8e1da1b3568033e3dde (diff)
Handle ADD/SUB relocations
This adds support for ADD and SUB relocations as seen on RISC-V. Signed-off-by: Andreas Schwab <[email protected]>
Diffstat (limited to 'src/strip.c')
-rw-r--r--src/strip.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/strip.c b/src/strip.c
index 4a3db1b5..1f7b3cab 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -2030,7 +2030,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
return true;
/* We only do simple absolute relocations. */
- Elf_Type type = ebl_reloc_simple_type (ebl, rtype);
+ int addsub = 0;
+ Elf_Type type = ebl_reloc_simple_type (ebl, rtype, &addsub);
if (type == ELF_T_NUM)
return false;
@@ -2109,6 +2110,17 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* For SHT_RELA sections we just take the
given addend and add it to the value. */
value += addend;
+ /* For ADD/SUB relocations we need to fetch the
+ current section contents. */
+ if (addsub != 0)
+ {
+ Elf_Data *d = gelf_xlatetom (debugelf, &tmpdata,
+ &rdata,
+ ehdr->e_ident[EI_DATA]);
+ if (d == NULL)
+ INTERNAL_ERROR (fname);
+ assert (d == &tmpdata);
+ }
}
else
{
@@ -2125,9 +2137,12 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
switch (type)
{
-#define DO_TYPE(NAME, Name) \
- case ELF_T_##NAME: \
- tmpbuf.Name += (GElf_##Name) value; \
+#define DO_TYPE(NAME, Name) \
+ case ELF_T_##NAME: \
+ if (addsub < 0) \
+ tmpbuf.Name -= (GElf_##Name) value; \
+ else \
+ tmpbuf.Name += (GElf_##Name) value; \
break;
TYPES;
#undef DO_TYPE