r142 - trunk
Petter Reinholdtsen
pere at moszumanska.debian.org
Sun Nov 24 07:32:55 UTC 2013
Author: pere
Date: 2013-11-24 07:32:55 +0000 (Sun, 24 Nov 2013)
New Revision: 142
Modified:
trunk/NEWS
trunk/chrpath.c
trunk/elf.c
trunk/protos.h
Log:
Added byteswap fix found in Ubuntu, credited Jeremy Kerr and Matthias Klose.
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2013-11-24 07:20:50 UTC (rev 141)
+++ trunk/NEWS 2013-11-24 07:32:55 UTC (rev 142)
@@ -2,6 +2,8 @@
* Updated config.sub and config.guess from the GNU project to work with
newer architectures. Thanks to isha vishnoi for the heads up.
* Updated README with current URLs.
+ * Added byteswap fix found in Ubuntu, credited Jeremy Kerr and
+ Matthias Klose.
New in 0.14 released 2011-09-27:
* Updated debian build rules from the current Debian package.
Modified: trunk/chrpath.c
===================================================================
--- trunk/chrpath.c 2013-11-24 07:20:50 UTC (rev 141)
+++ trunk/chrpath.c 2013-11-24 07:32:55 UTC (rev 142)
@@ -124,14 +124,14 @@
return 2;
}
- if (lseek(fd, EHDRU(e_shoff), SEEK_SET) == -1)
+ if (lseek(fd, EHDRWU(e_shoff), SEEK_SET) == -1)
{
perror ("positioning for sections");
free(dyns);
return 1;
}
- for (i = 0; i < EHDRS(e_shnum); i++)
+ for (i = 0; i < EHDRHU(e_shnum); i++)
{
const size_t sz_shdr = is_e32() ? sizeof(Elf32_Shdr) : sizeof(Elf64_Shdr);
if (read(fd, &shdr, sz_shdr) != (ssize_t)sz_shdr)
@@ -140,32 +140,32 @@
free(dyns);
return 1;
}
- if (SHDR(sh_type) == SHT_STRTAB)
+ if (SHDR_W(sh_type) == SHT_STRTAB)
break;
}
- if (i == EHDRS(e_shnum))
+ if (i == EHDRHU(e_shnum))
{
fprintf (stderr, "No string table found.\n");
free(dyns);
return 2;
}
- strtab = (char *)malloc(SHDR(sh_size));
+ strtab = (char *)malloc(SHDR_O(sh_size));
if (strtab == NULL)
{
perror ("allocating memory for string table");
free(dyns);
return 1;
}
- memset(strtab, 0, SHDR(sh_size));
+ memset(strtab, 0, SHDR_O(sh_size));
- if (lseek(fd, SHDR(sh_offset), SEEK_SET) == -1)
+ if (lseek(fd, SHDR_O(sh_offset), SEEK_SET) == -1)
{
perror ("positioning for string table");
free(strtab);
free(dyns);
return 1;
}
- if (read(fd, strtab, SHDR(sh_size)) != (int)SHDR(sh_size))
+ if (read(fd, strtab, SHDR_O(sh_size)) != (int)SHDR_O(sh_size))
{
perror ("reading string table");
free(strtab);
@@ -173,7 +173,7 @@
return 1;
}
- if ((int)SHDR(sh_size) < rpathoff)
+ if ((int)SHDR_O(sh_size) < rpathoff)
{
fprintf(stderr, "%s string offset not contained in string table",
elf_tagname(DYNSS(rpath_dyns_index, d_tag)));
@@ -218,7 +218,7 @@
* Calculate the maximum rpath length (will be equal to rpathlen unless
* we have previously truncated it).
*/
- for ( i = rpathoff + rpathlen ; (i < (int)SHDR(sh_size)
+ for ( i = rpathoff + rpathlen ; (i < (int)SHDR_O(sh_size)
&& strtab[i] == '\0') ; i++ )
;
i--;
@@ -238,7 +238,7 @@
memset(rpath, 0, rpathlen);
strcpy(rpath, newpath);
- if (lseek(fd, SHDR(sh_offset)+rpathoff, SEEK_SET) == -1)
+ if (lseek(fd, SHDR_O(sh_offset)+rpathoff, SEEK_SET) == -1)
{
perror ("positioning for RPATH");
free(dyns);
Modified: trunk/elf.c
===================================================================
--- trunk/elf.c 2013-11-24 07:20:50 UTC (rev 141)
+++ trunk/elf.c 2013-11-24 07:32:55 UTC (rev 142)
@@ -16,10 +16,13 @@
#include <fcntl.h>
#include "protos.h"
-#define EHDR_PS(x) (is_e32() ? DO_SWAPS32(ehdr->e32.x) : DO_SWAPS64(ehdr->e64.x))
-#define PHDR_PS(x) (is_e32() ? DO_SWAPS32(phdr->e32.x) : DO_SWAPS64(phdr->e64.x))
-#define EHDR_PU(x) (is_e32() ? DO_SWAPU32(ehdr->e32.x) : DO_SWAPU64(ehdr->e64.x))
-#define PHDR_PU(x) (is_e32() ? DO_SWAPU32(phdr->e32.x) : DO_SWAPU64(phdr->e64.x))
+#define EHDR_PWS(x) (is_e32() ? DO_SWAPS32(ehdr->e32.x) : DO_SWAPS64(ehdr->e64.x))
+#define EHDR_PHS(x) (is_e32() ? DO_SWAPS16(ehdr->e32.x) : DO_SWAPS16(ehdr->e64.x))
+#define PHDR_PWS(x) (is_e32() ? DO_SWAPS32(phdr->e32.x) : DO_SWAPS64(phdr->e64.x))
+#define EHDR_PWU(x) (is_e32() ? DO_SWAPU32(ehdr->e32.x) : DO_SWAPU64(ehdr->e64.x))
+#define EHDR_PHU(x) (is_e32() ? DO_SWAPU16(ehdr->e32.x) : DO_SWAPU16(ehdr->e64.x))
+#define PHDR_PWU(x) (is_e32() ? DO_SWAPU32(phdr->e32.x) : DO_SWAPU32(phdr->e64.x))
+#define PHDR_POU(x) (is_e32() ? DO_SWAPU32(phdr->e32.x) : DO_SWAPU64(phdr->e64.x))
static int is_e32_flag;
static int swap_bytes_flag;
@@ -83,10 +86,10 @@
}
sz_phdr = is_e32() ? sizeof(Elf32_Phdr) : sizeof(Elf64_Phdr);
- if (EHDR_PS(e_phentsize) != sz_phdr)
+ if (EHDR_PHS(e_phentsize) != sz_phdr)
{
fprintf(stderr, "section size was read as %d, not %d!\n",
- (int)EHDR_PS(e_phentsize), (int)sz_phdr);
+ (int)EHDR_PHS(e_phentsize), (int)sz_phdr);
close(fd);
return -1;
}
@@ -97,13 +100,13 @@
elf_find_dynamic_section(int fd, Elf_Ehdr *ehdr, Elf_Phdr *phdr)
{
int i;
- if (lseek(fd, EHDR_PU(e_phoff), SEEK_SET) == -1)
+ if (lseek(fd, EHDR_PWU(e_phoff), SEEK_SET) == -1)
{
perror ("positioning for sections");
return 1;
}
- for (i = 0; i < EHDR_PS(e_phnum); i++)
+ for (i = 0; i < EHDR_PHS(e_phnum); i++)
{
const size_t sz_phdr = is_e32() ? sizeof(Elf32_Phdr) : sizeof(Elf64_Phdr);
if (read(fd, phdr, sz_phdr) != (ssize_t)sz_phdr)
@@ -111,16 +114,16 @@
perror ("reading section header");
return 1;
}
- if (PHDR_PU(p_type) == PT_DYNAMIC)
+ if (PHDR_PWU(p_type) == PT_DYNAMIC)
break;
}
- if (i == EHDR_PS(e_phnum))
+ if (i == EHDR_PHS(e_phnum))
{
fprintf (stderr, "No dynamic section found.\n");
return 2;
}
- if (0 == PHDR_PU(p_filesz))
+ if (0 == PHDR_POU(p_filesz))
{
fprintf (stderr, "Length of dynamic section is zero.\n");
return 3;
Modified: trunk/protos.h
===================================================================
--- trunk/protos.h 2013-11-24 07:20:50 UTC (rev 141)
+++ trunk/protos.h 2013-11-24 07:32:55 UTC (rev 142)
@@ -33,15 +33,20 @@
int is_e32(void);
int swap_bytes(void);
+#define DO_SWAPU16(x) ( !swap_bytes() ? x : (uint16_t)bswap_16(x) )
#define DO_SWAPU32(x) ( !swap_bytes() ? x : (uint32_t)bswap_32(x) )
#define DO_SWAPU64(x) ( !swap_bytes() ? x : (uint64_t)bswap_64(x) )
+#define DO_SWAPS16(x) ( !swap_bytes() ? x : (int16_t)bswap_16(x) )
#define DO_SWAPS32(x) ( !swap_bytes() ? x : (int32_t)bswap_32(x) )
#define DO_SWAPS64(x) ( !swap_bytes() ? x : (int64_t)bswap_64(x) )
-#define EHDRS(x) (is_e32() ? DO_SWAPS32(ehdr.e32.x) : DO_SWAPS64(ehdr.e64.x))
-#define EHDRU(x) (is_e32() ? DO_SWAPU32(ehdr.e32.x) : DO_SWAPU64(ehdr.e64.x))
+#define EHDRWS(x) (is_e32() ? DO_SWAPS32(ehdr.e32.x) : DO_SWAPS64(ehdr.e64.x))
+#define EHDRHS(x) (is_e32() ? DO_SWAPS16(ehdr.e32.x) : DO_SWAPS16(ehdr.e64.x))
+#define EHDRWU(x) (is_e32() ? DO_SWAPU32(ehdr.e32.x) : DO_SWAPU64(ehdr.e64.x))
+#define EHDRHU(x) (is_e32() ? DO_SWAPU16(ehdr.e32.x) : DO_SWAPU16(ehdr.e64.x))
#define PHDR(x) (is_e32() ? DO_SWAPU32(phdr.e32.x) : DO_SWAPU64(phdr.e64.x))
-#define SHDR(x) (is_e32() ? DO_SWAPU32(shdr.e32.x) : DO_SWAPU64(shdr.e64.x))
+#define SHDR_W(x) (is_e32() ? DO_SWAPU32(shdr.e32.x) : DO_SWAPU32(shdr.e64.x))
+#define SHDR_O(x) (is_e32() ? DO_SWAPU32(shdr.e32.x) : DO_SWAPU64(shdr.e64.x))
#define DYNSU(i,x) (is_e32() ? DO_SWAPU32(((Elf32_Dyn *)dyns)[i].x) \
: DO_SWAPU64(((Elf64_Dyn *)dyns)[i].x))
#define DYNSS(i,x) (is_e32() ? DO_SWAPS32(((Elf32_Dyn *)dyns)[i].x) \
More information about the Chrpath-commits
mailing list