PERFORCE change 104167 for review
John Birrell
jb at FreeBSD.org
Wed Aug 16 01:31:19 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=104167
Change 104167 by jb at jb_freebsd2 on 2006/08/16 01:30:34
Revert back to using my memcpy version of this file which works on
sun4v. Revision 5 certainly stopped the compiler warnings about
alignment, but the compiler was doing the right thing. Adding another
cast to avoid the warning just masked the problem.
Affected files ...
.. //depot/projects/dtrace/src/lib/libelf/libelf_convert.m4#6 edit
Differences ...
==== //depot/projects/dtrace/src/lib/libelf/libelf_convert.m4#6 (text+ko) ====
@@ -1,3 +1,4 @@
+//depot/projects/dtrace/src/lib/libelf/libelf_convert.m4#4 - edit change 103978 (text+ko)
/*-
* Copyright (c) 2006 Joseph Koshy
* All rights reserved.
@@ -152,7 +153,7 @@
(X) = _t; \
} while (0)
#define READ_WORD(P,X) do { \
- uint16_t _t; \
+ uint32_t _t; \
unsigned char *const _q = (unsigned char *) &_t; \
const unsigned char *const _p = \
(const unsigned char *) (P); \
@@ -167,7 +168,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 { \
- uint16_t _t; \
+ uint64_t _t; \
unsigned char *const _q = (unsigned char *) &_t; \
const unsigned char *const _p = \
(const unsigned char *) (P); \
@@ -188,6 +189,7 @@
#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)
@@ -201,16 +203,9 @@
* 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 additional complication is that `ar' only pads data
+ * byte order. An additinal 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')
@@ -257,19 +252,20 @@
static void
libelf_cvt_$1$3_tof(char *dst, char *src, int count, int byteswap)
{
- Elf64_$2 t, *s = (Elf64_$2 *) (uintptr_t) src;
+ Elf64_$2 t;
int c;
if (dst == src && !byteswap)
return;
if (!byteswap) {
- (void) memcpy(dst, src, count * sizeof(*s));
+ (void) memcpy(dst, src, count * sizeof(t));
return;
}
for (c = 0; c < count; c++) {
- t = *s++;
+ memcpy(&t, src, sizeof(t));
+ src += sizeof(t);
SWAP_$1$3(t);
WRITE_$1$3(dst,t);
}
@@ -280,21 +276,22 @@
static void
libelf_cvt_$1$3_tom(char *dst, char *src, int count, int byteswap)
{
- Elf64_$2 t, *d = (Elf64_$2 *) (uintptr_t) dst;
+ Elf64_$2 t;
int c;
if (dst == src && !byteswap)
return;
if (!byteswap) {
- (void) memcpy(dst, src, count * sizeof(*d));
+ (void) memcpy(dst, src, count * sizeof(t));
return;
}
for (c = 0; c < count; c++) {
READ_$1$3(src,t);
SWAP_$1$3(t);
- *d++ = t;
+ memcpy(dst, &t, sizeof(t));
+ dst += sizeof(t);
}
}
')
@@ -370,12 +367,12 @@
static void
libelf_cvt$3_$1_tof(char *dst, char *src, int count, int byteswap)
{
- Elf$3_$2 t, *s;
+ Elf$3_$2 t;
int c;
- s = (Elf$3_$2 *) (uintptr_t) src;
for (c = 0; c < count; c++) {
- t = *s++;
+ memcpy(&t, src, sizeof(t));
+ src += sizeof(t);
if (byteswap) {
SWAP_STRUCT($2,$3)
}
@@ -389,21 +386,22 @@
static void
libelf_cvt$3_$1_tom(char *dst, char *src, int count, int byteswap)
{
- Elf$3_$2 t, *d;
- unsigned char *s,*s0;
+ Elf$3_$2 t;
+ unsigned char *s;
+ int i;
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;
- while (count--) {
- s = s0;
+ for (i = 0; i < count; i++) {
+ s = (unsigned char *) src;
READ_STRUCT($2,$3)
if (byteswap) {
SWAP_STRUCT($2,$3)
}
- *d-- = t; s0 -= fsz;
+ memcpy(dst, &t, sizeof(t));
+ dst += sizeof(t);
+ src += fsz;
}
}
')')
More information about the p4-projects
mailing list