summaryrefslogtreecommitdiff
path: root/src/modelops
diff options
context:
space:
mode:
Diffstat (limited to 'src/modelops')
-rw-r--r--src/modelops/dump.c50
-rw-r--r--src/modelops/fromFile.c19
-rw-r--r--src/modelops/layout.c12
-rw-r--r--src/modelops/reladd.c19
-rw-r--r--src/modelops/relocate.c9
-rw-r--r--src/modelops/section.c11
-rw-r--r--src/modelops/symtab.c4
-rw-r--r--src/modelops/toFile.c4
8 files changed, 70 insertions, 58 deletions
diff --git a/src/modelops/dump.c b/src/modelops/dump.c
index 27556f9..b2e172e 100644
--- a/src/modelops/dump.c
+++ b/src/modelops/dump.c
@@ -99,25 +99,25 @@ void elfu_mDumpPhdr(ElfuElf *me, ElfuPhdr *mp)
assert(me);
assert(mp);
- ELFU_INFO("%12s %8jx %8jx %8jx %8jx %8jx %8jx %8jx %8jx\n",
+ ELFU_INFO("%12s %8x %8x %8x %8x %8x %8x %8x %8x\n",
segmentTypeStr(mp->phdr.p_type),
- (uintmax_t) mp->phdr.p_type,
- (uintmax_t) mp->phdr.p_offset,
- (uintmax_t) mp->phdr.p_vaddr,
- (uintmax_t) mp->phdr.p_paddr,
- (uintmax_t) mp->phdr.p_filesz,
- (uintmax_t) mp->phdr.p_memsz,
- (uintmax_t) mp->phdr.p_flags,
- (uintmax_t) mp->phdr.p_align);
+ (unsigned)mp->phdr.p_type,
+ (unsigned)mp->phdr.p_offset,
+ (unsigned)mp->phdr.p_vaddr,
+ (unsigned)mp->phdr.p_paddr,
+ (unsigned)mp->phdr.p_filesz,
+ (unsigned)mp->phdr.p_memsz,
+ (unsigned)mp->phdr.p_flags,
+ (unsigned)mp->phdr.p_align);
if (!CIRCLEQ_EMPTY(&mp->childPhdrList)) {
ElfuPhdr *mpc;
ELFU_INFO(" -> Child PHDRs:\n");
CIRCLEQ_FOREACH(mpc, &mp->childPhdrList, elemChildPhdr) {
- ELFU_INFO(" * %-8s @ %8jx\n",
+ ELFU_INFO(" * %-8s @ %8x\n",
segmentTypeStr(mpc->phdr.p_type),
- mpc->phdr.p_vaddr);
+ (unsigned)mpc->phdr.p_vaddr);
}
}
@@ -126,9 +126,9 @@ void elfu_mDumpPhdr(ElfuElf *me, ElfuPhdr *mp)
ELFU_INFO(" -> Child sections:\n");
CIRCLEQ_FOREACH(msc, &mp->childScnList, elemChildScn) {
- ELFU_INFO(" * %-17s @ %8jx\n",
+ ELFU_INFO(" * %-17s @ %8x\n",
elfu_mScnName(me, msc),
- msc->shdr.sh_addr);
+ (unsigned)msc->shdr.sh_addr);
}
}
}
@@ -146,15 +146,15 @@ void elfu_mDumpScn(ElfuElf *me, ElfuScn *ms)
linkstr = ms->linkptr ? elfu_mScnName(me, ms->linkptr) : "";
infostr = ms->infoptr ? elfu_mScnName(me, ms->infoptr) : "";
- ELFU_INFO("%-17s %-15s %8jx %9jx %8jx %2jx %2jx %2jd %-17s %-17s\n",
+ ELFU_INFO("%-17s %-15s %8x %9x %8x %2x %2x %2d %-17s %-17s\n",
namestr,
typestr,
- ms->shdr.sh_addr,
- ms->shdr.sh_offset,
- ms->shdr.sh_size,
- ms->shdr.sh_entsize,
- ms->shdr.sh_flags,
- ms->shdr.sh_addralign,
+ (unsigned)ms->shdr.sh_addr,
+ (unsigned)ms->shdr.sh_offset,
+ (unsigned)ms->shdr.sh_size,
+ (unsigned)ms->shdr.sh_entsize,
+ (unsigned)ms->shdr.sh_flags,
+ (unsigned)ms->shdr.sh_addralign,
linkstr,
infostr);
}
@@ -172,9 +172,9 @@ void elfu_mDumpEhdr(ElfuElf *me)
ELFU_INFO(" e_type %8x\n", me->ehdr.e_type);
ELFU_INFO(" e_machine %8x\n", me->ehdr.e_machine);
ELFU_INFO(" e_version %8x\n", me->ehdr.e_version);
- ELFU_INFO(" e_entry %8jx\n", me->ehdr.e_entry);
- ELFU_INFO(" e_phoff %8jx\n", me->ehdr.e_phoff);
- ELFU_INFO(" e_shoff %8jx\n", me->ehdr.e_shoff);
+ ELFU_INFO(" e_entry %8x\n", (unsigned)me->ehdr.e_entry);
+ ELFU_INFO(" e_phoff %8x\n", (unsigned)me->ehdr.e_phoff);
+ ELFU_INFO(" e_shoff %8x\n", (unsigned)me->ehdr.e_shoff);
ELFU_INFO(" e_flags %8x\n", me->ehdr.e_flags);
ELFU_INFO(" e_ehsize %8x\n", me->ehdr.e_ehsize);
ELFU_INFO(" e_phentsize %8x\n", me->ehdr.e_phentsize);
@@ -224,9 +224,9 @@ void elfu_mDumpElf(ElfuElf *me)
ELFU_INFO("Orphaned sections:\n");
CIRCLEQ_FOREACH(ms, &me->orphanScnList, elemChildScn) {
- ELFU_INFO(" * %-17s @ %8jx\n",
+ ELFU_INFO(" * %-17s @ %8x\n",
elfu_mScnName(me, ms),
- ms->shdr.sh_addr);
+ (unsigned)ms->shdr.sh_addr);
}
ELFU_INFO("\n");
diff --git a/src/modelops/fromFile.c b/src/modelops/fromFile.c
index bc089bf..dd8b462 100644
--- a/src/modelops/fromFile.c
+++ b/src/modelops/fromFile.c
@@ -52,7 +52,7 @@ static void parseSymtab(ElfuElf *me, ElfuScn *ms, ElfuScn**origScnArr)
CIRCLEQ_INSERT_TAIL(&ms->symtab.syms, newsym, elem);
}
} else {
- // Unknown elfclass
+ /* Unknown elfclass */
assert(0);
}
@@ -126,11 +126,14 @@ static void parseRelatab64(ElfuScn *ms)
static int cmpScnOffs(const void *ms1, const void *ms2)
{
+ ElfuScn *s1 = *(ElfuScn**)ms1;
+ ElfuScn *s2 = *(ElfuScn**)ms2;
+
assert(ms1);
assert(ms2);
- ElfuScn *s1 = *(ElfuScn**)ms1;
- ElfuScn *s2 = *(ElfuScn**)ms2;
+ s1 = *(ElfuScn**)ms1;
+ s2 = *(ElfuScn**)ms2;
assert(s1);
assert(s2);
@@ -230,7 +233,7 @@ static ElfuScn* modelFromSection(Elf_Scn *scn)
ms->data.d_buf = malloc(ms->shdr.sh_size);
if (!ms->data.d_buf) {
- ELFU_WARN("modelFromSection: malloc() failed for data buffer (%jx bytes).\n", ms->shdr.sh_size);
+ ELFU_WARN("modelFromSection: malloc() failed for data buffer (%x bytes).\n", (unsigned)ms->shdr.sh_size);
goto ERROR;
}
@@ -246,7 +249,7 @@ static ElfuScn* modelFromSection(Elf_Scn *scn)
if (data->d_off + data->d_size > ms->shdr.sh_size) {
ELFU_WARN("modelFromSection: libelf delivered a bogus data blob. Skipping\n");
} else {
- memcpy(ms->data.d_buf + data->d_off, data->d_buf, data->d_size);
+ memcpy((char*)ms->data.d_buf + data->d_off, data->d_buf, data->d_size);
}
data = elf_rawdata(scn, data);
@@ -427,12 +430,14 @@ ElfuElf* elfu_mFromElf(Elf *e)
if (me->elfclass == ELFCLASS32) {
parseReltab32(ms);
} else if (me->elfclass == ELFCLASS64) {
- // Not used on x86-64
+ /* Not used on x86-64 */
+ assert(0);
}
break;
case SHT_RELA:
if (me->elfclass == ELFCLASS32) {
- // TODO
+ /* Not used on x86-32 */
+ assert(0);
} else if (me->elfclass == ELFCLASS64) {
parseRelatab64(ms);
}
diff --git a/src/modelops/layout.c b/src/modelops/layout.c
index e4b3fb1..8abc766 100644
--- a/src/modelops/layout.c
+++ b/src/modelops/layout.c
@@ -115,7 +115,7 @@ GElf_Addr elfu_mLayoutGetSpaceInPhdr(ElfuElf *me, GElf_Word size,
GElf_Off endAddr = OFFS_END(last->phdr.p_vaddr, last->phdr.p_filesz);
ElfuScn *ms;
- ELFU_INFO("Expanding NOBITS at address 0x%jx...\n", endAddr);
+ ELFU_INFO("Expanding NOBITS at address 0x%x...\n", (unsigned)endAddr);
CIRCLEQ_FOREACH(ms, &last->childScnList, elemChildScn) {
if (ms->shdr.sh_offset == endOff) {
@@ -124,7 +124,8 @@ GElf_Addr elfu_mLayoutGetSpaceInPhdr(ElfuElf *me, GElf_Word size,
ms->data.d_buf = malloc(ms->shdr.sh_size);
memset(ms->data.d_buf, '\0', ms->shdr.sh_size);
if (!ms->data.d_buf) {
- ELFU_WARN("mExpandNobits: Could not allocate %jd bytes for NOBITS expansion. Data may be inconsistent.\n", ms->shdr.sh_size);
+ ELFU_WARN("mExpandNobits: Could not allocate %u bytes for NOBITS expansion. Data may be inconsistent.\n",
+ (unsigned)ms->shdr.sh_size);
assert(0);
goto ERROR;
}
@@ -227,11 +228,14 @@ GElf_Addr elfu_mLayoutGetSpaceInPhdr(ElfuElf *me, GElf_Word size,
static int cmpPhdrOffs(const void *mp1, const void *mp2)
{
+ ElfuPhdr *p1;
+ ElfuPhdr *p2;
+
assert(mp1);
assert(mp2);
- ElfuPhdr *p1 = *(ElfuPhdr**)mp1;
- ElfuPhdr *p2 = *(ElfuPhdr**)mp2;
+ p1 = *(ElfuPhdr**)mp1;
+ p2 = *(ElfuPhdr**)mp2;
assert(p1);
assert(p2);
diff --git a/src/modelops/reladd.c b/src/modelops/reladd.c
index fa8ffff..bc909e4 100644
--- a/src/modelops/reladd.c
+++ b/src/modelops/reladd.c
@@ -7,7 +7,7 @@
static int appendData(ElfuScn *ms, void *buf, size_t len)
{
- void *newbuf;
+ char *newbuf;
assert(ms);
assert(ms->shdr.sh_type != SHT_NOBITS);
@@ -67,9 +67,9 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn)
goto ERROR;
}
- ELFU_INFO("Inserting %s at address 0x%jx...\n",
+ ELFU_INFO("Inserting %s at address 0x%x...\n",
elfu_mScnName(mrel, oldscn),
- injAddr);
+ (unsigned)injAddr);
injOffset = injAddr - injPhdr->phdr.p_vaddr + injPhdr->phdr.p_offset;
@@ -120,10 +120,10 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn)
return newscn;
} else {
- ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %jd).\n",
+ ELFU_WARN("insertSection: Skipping non-memory section %s (type %d flags %u).\n",
elfu_mScnName(mrel, oldscn),
oldscn->shdr.sh_type,
- oldscn->shdr.sh_flags);
+ (unsigned)oldscn->shdr.sh_flags);
goto ERROR;
}
@@ -137,10 +137,10 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *oldscn)
static void* subScnAdd1(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2)
{
- (void)aux2;
+ ElfuScn *newscn;
ElfuElf *me = (ElfuElf*)aux1;
+ (void)aux2;
- ElfuScn *newscn;
switch(ms->shdr.sh_type) {
case SHT_PROGBITS: /* 1 */
@@ -166,9 +166,8 @@ static void* subScnAdd1(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2)
static void* subScnAdd2(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2)
{
- (void)aux2;
ElfuElf *me = (ElfuElf*)aux1;
- (void)me;
+ (void)aux2;
switch(ms->shdr.sh_type) {
case SHT_NULL: /* 0 */
@@ -217,7 +216,7 @@ static void* subScnAdd2(ElfuElf *mrel, ElfuScn *ms, void *aux1, void *aux2)
static void insertSymClone(ElfuElf *me, const ElfuScn *oldmsst, const ElfuSym *oldsym)
{
GElf_Xword newsize;
- void *newbuf;
+ char *newbuf;
ElfuScn *newscn = NULL;
ElfuSym *newsym;
char *oldsymname;
diff --git a/src/modelops/relocate.c b/src/modelops/relocate.c
index 90a319b..eefed02 100644
--- a/src/modelops/relocate.c
+++ b/src/modelops/relocate.c
@@ -13,9 +13,9 @@ void elfu_mRelocate(ElfuElf *metarget, ElfuScn *mstarget, ElfuScn *msrt)
assert(mstarget);
assert(msrt);
- ELFU_DEBUG("Relocating in section of type %d size %jx\n",
+ ELFU_DEBUG("Relocating in section of type %u size %x\n",
mstarget->shdr.sh_type,
- mstarget->shdr.sh_size);
+ (unsigned)mstarget->shdr.sh_size);
CIRCLEQ_FOREACH(rel, &msrt->reltab.rels, elem) {
Elf32_Word *dest32 = (Elf32_Word*)(((char*)(mstarget->data.d_buf)) + rel->offset);
@@ -41,12 +41,13 @@ void elfu_mRelocate(ElfuElf *metarget, ElfuScn *mstarget, ElfuScn *msrt)
ELFU_DEBUG("Skipping relocation: Unknown type %d\n", rel->type);
}
} else if (metarget->elfclass == ELFCLASS64) {
- /* x86-64 only uses RELA with explicit addend. */
- assert(rel->addendUsed);
Elf64_Word a64 = rel->addend;
Elf64_Addr p64 = mstarget->shdr.sh_addr + rel->offset;
Elf64_Addr s64 = elfu_mSymtabLookupVal(metarget, msrt->linkptr, rel->sym);
+ /* x86-64 only uses RELA with explicit addend. */
+ assert(rel->addendUsed);
+
switch(rel->type) {
case R_X86_64_NONE:
ELFU_DEBUG("Skipping relocation: R_386_NONE\n");
diff --git a/src/modelops/section.c b/src/modelops/section.c
index a96377c..2675126 100644
--- a/src/modelops/section.c
+++ b/src/modelops/section.c
@@ -146,11 +146,14 @@ static void* subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
static int cmpScnOffs(const void *ms1, const void *ms2)
{
+ ElfuScn *s1;
+ ElfuScn *s2;
+
assert(ms1);
assert(ms2);
- ElfuScn *s1 = *(ElfuScn**)ms1;
- ElfuScn *s2 = *(ElfuScn**)ms2;
+ s1 = *(ElfuScn**)ms1;
+ s2 = *(ElfuScn**)ms2;
assert(s1);
assert(s2);
@@ -167,12 +170,12 @@ static int cmpScnOffs(const void *ms1, const void *ms2)
ElfuScn** elfu_mScnSortedByOffset(ElfuElf *me, size_t *count)
{
- assert(me);
-
size_t numSecs;
ElfuScn **sortedSecs;
size_t i;
+ assert(me);
+
/* Sort sections by offset in file */
numSecs = elfu_mScnCount(me);
sortedSecs = malloc(numSecs * sizeof(*sortedSecs));
diff --git a/src/modelops/symtab.c b/src/modelops/symtab.c
index a7c1485..e62871f 100644
--- a/src/modelops/symtab.c
+++ b/src/modelops/symtab.c
@@ -76,7 +76,7 @@ static GElf_Word pltLookupVal(ElfuElf *me, char *name)
* from the start of the PLT, where j is the PLT entry and 16 is
* the number of bytes the machine code in a PLT entry take. */
GElf_Addr addr = plt->shdr.sh_addr + (16 * j);
- ELFU_DEBUG("dynsymLookupVal: Guessing symbol '%s' is in destination memory at %jx (PLT entry #%d).\n", name, addr, j);
+ ELFU_DEBUG("dynsymLookupVal: Guessing symbol '%s' is in destination memory at %x (PLT entry #%u).\n", name, (unsigned)addr, j);
return addr;
}
}
@@ -215,7 +215,7 @@ void elfu_mSymtabFlatten(ElfuElf *me)
i++;
}
} else {
- // Unknown elfclass
+ /* Unknown elfclass */
assert(0);
}
diff --git a/src/modelops/toFile.c b/src/modelops/toFile.c
index 1fec8b0..368f12a 100644
--- a/src/modelops/toFile.c
+++ b/src/modelops/toFile.c
@@ -34,10 +34,10 @@ static void modelToPhdrs(ElfuElf *me, Elf *e)
static void* modelToSection(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
{
+ Elf_Scn *scnOut;
+ Elf *e = (Elf*)aux1;
(void) me;
(void) aux2;
- Elf *e = (Elf*)aux1;
- Elf_Scn *scnOut;
scnOut = elf_newscn(e);
if (!scnOut) {