From 58eb4eb2a1f6de2f39cfa02526945469e41fd4bc Mon Sep 17 00:00:00 2001 From: gonzo Date: Sat, 24 Mar 2012 01:47:33 +0000 Subject: Maintain target's byte order for multi-byte fields in CTF structures. CTF format is not cross-platform by design, e.g. it is not guaranteed that data generated by ctfconvert/ctfmerge on one architecture will be successfuly read on another. CTF structures are saved/restored using naive approach. Roughly it looks like: write(fd, &ctf_struct, sizeof(ctf_struct)) read(fd, &ctf_struct, sizeof(ctf_struct)) By sheer luck memory layout of all type-related CTF structures is the same on amd64/i386/mips32/mips64. It's different on ARM though. sparc, ia64, powerpc, and powerpc64 were not tested. So in order to get file compatible with dtrace on ARM it should be compiled on ARM. Alternative solution would be to have "signatures" for every platform and ctfmerge should convert host's reperesentation of CTF structure to target's one using "signature" as template. This patch checks byte order of ELF files used for generating CTF record and makes sure that byte order of data written to resulting files is the same as target's byte order. --- cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c') diff --git a/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c b/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c index 105112d..3e030c7 100644 --- a/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c +++ b/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c @@ -620,7 +620,7 @@ copy_ctf_data(char *srcfile, char *destfile, int keep_stabs) terminate("No CTF data found in source file %s\n", srcfile); tmpname = mktmpname(destfile, ".ctf"); - write_ctf(srctd, destfile, tmpname, CTF_COMPRESS | keep_stabs); + write_ctf(srctd, destfile, tmpname, CTF_COMPRESS | CTF_SWAP_BYTES | keep_stabs); if (rename(tmpname, destfile) != 0) { terminate("Couldn't rename temp file %s to %s", tmpname, destfile); @@ -1015,7 +1015,7 @@ main(int argc, char **argv) tmpname = mktmpname(outfile, ".ctf"); write_ctf(savetd, outfile, tmpname, - CTF_COMPRESS | write_fuzzy_match | dynsym | keep_stabs); + CTF_COMPRESS | CTF_SWAP_BYTES | write_fuzzy_match | dynsym | keep_stabs); if (rename(tmpname, outfile) != 0) terminate("Couldn't rename output temp file %s", tmpname); free(tmpname); -- cgit v1.1