PERFORCE change 104119 for review
John Birrell
jb at FreeBSD.org
Tue Aug 15 20:38:47 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=104119
Change 104119 by jb at jb_freebsd2 on 2006/08/15 20:38:00
IFlibbsdelf
Affected files ...
.. //depot/projects/dtrace/src/lib/libelf/Makefile#6 integrate
.. //depot/projects/dtrace/src/lib/libelf/elf_getarhdr.3#1 branch
.. //depot/projects/dtrace/src/lib/libelf/elf_getarsym.3#1 branch
.. //depot/projects/dtrace/src/lib/libelf/elf_next.c#5 integrate
.. //depot/projects/dtrace/src/lib/libelf/libelf_convert.m4#5 integrate
Differences ...
==== //depot/projects/dtrace/src/lib/libelf/Makefile#6 (text+ko) ====
@@ -59,6 +59,8 @@
elf_end.3 elf_errmsg.3 \
elf_fill.3 \
elf_flagdata.3 \
+ elf_getarhdr.3 \
+ elf_getarsym.3 \
elf_getbase.3 \
elf_getident.3 \
elf_hash.3 \
@@ -104,8 +106,6 @@
elf_flagdata.3 elf_flagphdr.3 \
elf_flagdata.3 elf_flagscn.3 \
elf_flagdata.3 elf_flagshdr.3 \
- elf.3 elf_getarhdr.3 \
- elf.3 elf_getarsym.3 \
elf.3 elf_getdata.3 \
elf.3 elf_getscn.3 \
elf.3 elf_ndxscn.3 \
==== //depot/projects/dtrace/src/lib/libelf/elf_next.c#5 (text+ko) ====
==== //depot/projects/dtrace/src/lib/libelf/libelf_convert.m4#5 (text+ko) ====
@@ -152,7 +152,7 @@
(X) = _t; \
} while (0)
#define READ_WORD(P,X) do { \
- uint32_t _t; \
+ uint16_t _t; \
unsigned char *const _q = (unsigned char *) &_t; \
const unsigned char *const _p = \
(const unsigned char *) (P); \
@@ -167,7 +167,7 @@
#define READ_OFF32(P,X) READ_WORD(P,X)
#define READ_SWORD(P,X) READ_WORD(P,X)
#define READ_WORD64(P,X) do { \
- uint64_t _t; \
+ uint16_t _t; \
unsigned char *const _q = (unsigned char *) &_t; \
const unsigned char *const _p = \
(const unsigned char *) (P); \
@@ -188,7 +188,6 @@
#define READ_XWORD(P,X) READ_WORD64(P,X)
#define READ_IDENT(P,X) do { \
(void) memcpy((X), (P), sizeof((X))); \
- (P) = (P) + sizeof((X)); \
} while (0)
divert(-1)
@@ -202,9 +201,16 @@
* casting to work as expected. On the other hand the `file'
* representation of an ELF data structure could be packed tighter
* than its `in-memory' representation, and could be of a differing
- * byte order. An additinal complication is that `ar' only pads data
+ * byte order. An additional complication is that `ar' only pads data
* to even addresses and so ELF archive member data being read from
* inside an `ar' archive could end up at misaligned memory addresses.
+ *
+ * Consequently, casting the `char *' pointers that point to memory
+ * representations (i.e., source pointers for the *_tof() functions
+ * and the destination pointers for the *_tom() functions), is safe,
+ * as these pointers should be correctly aligned for the memory type
+ * already. However, pointers to file representations have to be
+ * treated as being potentially unaligned and no casting can be done.
*/
include(SRCDIR`/elf_types.m4')
@@ -251,20 +257,19 @@
static void
libelf_cvt_$1$3_tof(char *dst, char *src, int count, int byteswap)
{
- Elf64_$2 t;
+ Elf64_$2 t, *s = (Elf64_$2 *) (uintptr_t) src;
int c;
if (dst == src && !byteswap)
return;
if (!byteswap) {
- (void) memcpy(dst, src, count * sizeof(t));
+ (void) memcpy(dst, src, count * sizeof(*s));
return;
}
for (c = 0; c < count; c++) {
- memcpy(&t, src, sizeof(t));
- src += sizeof(t);
+ t = *s++;
SWAP_$1$3(t);
WRITE_$1$3(dst,t);
}
@@ -275,22 +280,21 @@
static void
libelf_cvt_$1$3_tom(char *dst, char *src, int count, int byteswap)
{
- Elf64_$2 t;
+ Elf64_$2 t, *d = (Elf64_$2 *) (uintptr_t) dst;
int c;
if (dst == src && !byteswap)
return;
if (!byteswap) {
- (void) memcpy(dst, src, count * sizeof(t));
+ (void) memcpy(dst, src, count * sizeof(*d));
return;
}
for (c = 0; c < count; c++) {
READ_$1$3(src,t);
SWAP_$1$3(t);
- memcpy(dst, &t, sizeof(t));
- dst += sizeof(t);
+ *d++ = t;
}
}
')
@@ -366,12 +370,12 @@
static void
libelf_cvt$3_$1_tof(char *dst, char *src, int count, int byteswap)
{
- Elf$3_$2 t;
+ Elf$3_$2 t, *s;
int c;
+ s = (Elf$3_$2 *) (uintptr_t) src;
for (c = 0; c < count; c++) {
- memcpy(&t, src, sizeof(t));
- src += sizeof(t);
+ t = *s++;
if (byteswap) {
SWAP_STRUCT($2,$3)
}
@@ -385,22 +389,21 @@
static void
libelf_cvt$3_$1_tom(char *dst, char *src, int count, int byteswap)
{
- Elf$3_$2 t;
- unsigned char *s;
- int i;
+ Elf$3_$2 t, *d;
+ unsigned char *s,*s0;
size_t fsz;
fsz = elf$3_fsize(ELF_T_$1, 1, EV_CURRENT);
+ d = ((Elf$3_$2 *) (uintptr_t) dst) + (count - 1);
+ s0 = (unsigned char *) src + (count - 1) * fsz;
- for (i = 0; i < count; i++) {
- s = (unsigned char *) src;
+ while (count--) {
+ s = s0;
READ_STRUCT($2,$3)
if (byteswap) {
SWAP_STRUCT($2,$3)
}
- memcpy(dst, &t, sizeof(t));
- dst += sizeof(t);
- src += fsz;
+ *d-- = t; s0 -= fsz;
}
}
')')
More information about the p4-projects
mailing list