summaryrefslogtreecommitdiffstats
path: root/src/libr-elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libr-elf.c')
-rw-r--r--src/libr-elf.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/libr-elf.c b/src/libr-elf.c
index be2daae..8e4f4e7 100644
--- a/src/libr-elf.c
+++ b/src/libr-elf.c
@@ -148,7 +148,7 @@ libr_intstatus expand_section(Elf *e, Elf_Scn *scn, size_t size, int reset)
*/
return LIBR_OK;
}
-#endif /* MANUAL_LAYOUT */
+#endif
/*
* Obtain the data from a section using libelf
@@ -185,7 +185,7 @@ libr_intstatus set_data(libr_file *file_handle, libr_section *scn, libr_data *da
RETURN(LIBR_ERROR_UPDATE, "Failed to perform dynamic update: %s.", elf_errmsg(-1));
if(elf_update(file_handle->elf_handle, ELF_C_WRITE) < 0)
RETURN(LIBR_ERROR_UPDATE, "Failed to perform dynamic update: %s.", elf_errmsg(-1));
-#endif /* MANUAL_LAYOUT */
+#endif
RETURN_OK;
}
@@ -230,12 +230,13 @@ libr_intstatus add_section(libr_file *file_handle, char *section, Elf_Scn **rets
{
Elf_Scn *scn = NULL, *strscn = NULL;
Elf *e = file_handle->elf_handle;
-#ifdef MANUAL_LAYOUT
- size_t tblsize = 0;
-#endif /* MANUAL_LAYOUT */
Elf_Data *data;
GElf_Ehdr ehdr;
GElf_Shdr shdr;
+#ifdef MANUAL_LAYOUT
+ GElf_Shdr strshdr;
+ size_t tblsize = 0;
+#endif
if(gelf_getehdr(e, &ehdr) == NULL)
RETURN(LIBR_ERROR_GETEHDR, "Failed to obtain ELF header: %s", elf_errmsg(-1));
@@ -251,13 +252,10 @@ libr_intstatus add_section(libr_file *file_handle, char *section, Elf_Scn **rets
data->d_align = 1;
#ifdef MANUAL_LAYOUT
-{
- GElf_Shdr strshdr;
-
if(gelf_getshdr(strscn, &strshdr) != &strshdr)
RETURN(LIBR_ERROR_GETSHDR, "Failed to obtain ELF section header: %s", elf_errmsg(-1));
data->d_off = strshdr.sh_size;
-#endif /* MANUAL_LAYOUT */
+#endif
data->d_size = (size_t) strlen(section)+1;
data->d_type = ELF_T_BYTE;
@@ -267,12 +265,11 @@ libr_intstatus add_section(libr_file *file_handle, char *section, Elf_Scn **rets
#ifdef MANUAL_LAYOUT
if(expand_section(e, strscn, data->d_size, false) != LIBR_OK)
return false;
-}
#else
/* Update the internal offset information */
if(elf_update(e, ELF_C_NULL) < 0)
RETURN(LIBR_ERROR_UPDATE, "Failed to perform dynamic update: %s.", elf_errmsg(-1));
-#endif /* MANUAL_LAYOUT */
+#endif
/* seek to the end of the section data */
if((scn = elf_newscn(e)) == NULL)
@@ -282,7 +279,7 @@ libr_intstatus add_section(libr_file *file_handle, char *section, Elf_Scn **rets
shdr.sh_addralign = 1;
#ifdef MANUAL_LAYOUT
shdr.sh_offset = file_handle->file_size;
-#endif /* MANUAL_LAYOUT */
+#endif
shdr.sh_size = 0;
shdr.sh_name = data->d_off;
shdr.sh_type = SHT_NOTE; /* TODO: Does "NOTE" type fit best? */
@@ -307,6 +304,9 @@ libr_intstatus remove_section(libr_file *file_handle, libr_section *scn)
Elf_Data *data;
GElf_Ehdr ehdr;
GElf_Shdr shdr;
+#ifdef MANUAL_LAYOUT
+ GElf_Shdr strshdr;
+#endif
if(gelf_getehdr(e, &ehdr) == NULL)
RETURN(LIBR_ERROR_GETEHDR, "Failed to obtain ELF header: %s", elf_errmsg(-1));
@@ -343,16 +343,12 @@ libr_intstatus remove_section(libr_file *file_handle, libr_section *scn)
if(elf_update(e, ELF_C_NULL) < 0)
RETURN(LIBR_ERROR_UPDATE, "Failed to perform dynamic update: %s.", elf_errmsg(-1));
#ifdef MANUAL_LAYOUT
-{
- GElf_Shdr strshdr;
-
if(gelf_getshdr(strscn, &strshdr) != &strshdr)
RETURN(LIBR_ERROR_GETSHDR, "Failed to obtain ELF section header: %s", elf_errmsg(-1));
strshdr.sh_size -= str_size;
if(gelf_update_shdr(strscn, &strshdr) < 0)
RETURN(LIBR_ERROR_UPDATE, "Failed to perform dynamic update: %s.", elf_errmsg(-1));
-}
-#endif /* MANUAL_LAYOUT */
+#endif
/* Clear the section itself and update the offsets */
if(elfx_remscn(e, scn) == 0)