Date: Sun, 13 Jan 2008 04:20:45 GMT From: John Birrell <jb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 133159 for review Message-ID: <200801130420.m0D4KjFN046660@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=133159 Change 133159 by jb@jb_freebsd1 on 2008/01/13 04:19:46 Port to FreeBSD. (dtrace -G) Affected files ... .. //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_link.c#13 edit Differences ... ==== //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_link.c#13 (text) ==== @@ -518,19 +518,18 @@ #else elf_file.ehdr.e_ident[EI_DATA] = ELFDATA2LSB; #endif +#if defined(__FreeBSD__) + elf_file.ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; +#endif elf_file.ehdr.e_type = ET_REL; #if defined(__arm__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_ARM; #elif defined(__ia64__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_IA_64; #elif defined(__mips__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_MIPS; #elif defined(__powerpc__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_PPC; #elif defined(__sparc) elf_file.ehdr.e_machine = EM_SPARC; #elif defined(__i386) || defined(__amd64) @@ -667,19 +666,18 @@ #else elf_file.ehdr.e_ident[EI_DATA] = ELFDATA2LSB; #endif +#if defined(__FreeBSD__) + elf_file.ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; +#endif elf_file.ehdr.e_type = ET_REL; #if defined(__arm__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_ARM; #elif defined(__ia64__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_IA_64; #elif defined(__mips__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_MIPS; #elif defined(__powerpc__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + elf_file.ehdr.e_machine = EM_PPC; #elif defined(__sparc) elf_file.ehdr.e_machine = EM_SPARCV9; #elif defined(__i386) || defined(__amd64) @@ -1127,18 +1125,12 @@ if (dtp->dt_oflags & DTRACE_O_LP64) { eclass = ELFCLASS64; -#if defined(__arm__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); -#elif defined(__ia64__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); +#if defined(__ia64__) + emachine1 = emachine2 = EM_IA_64; #elif defined(__mips__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + emachine1 = emachine2 = EM_MIPS; #elif defined(__powerpc__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + emachine1 = emachine2 = EM_PPC64; #elif defined(__sparc) emachine1 = emachine2 = EM_SPARCV9; #elif defined(__i386) || defined(__amd64) @@ -1148,21 +1140,15 @@ } else { eclass = ELFCLASS32; #if defined(__arm__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); -#elif defined(__ia64__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + emachine1 = emachine2 = EM_ARM; #elif defined(__mips__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + emachine1 = emachine2 = EM_MIPS; #elif defined(__powerpc__) -/* XXX */ -printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); + emachine1 = emachine2 = EM_PPC; #elif defined(__sparc) emachine1 = EM_SPARC; emachine2 = EM_SPARC32PLUS; -#elif defined(__i386) || defined(__amd64) +#elif defined(__i386) || defined(__amd64) || defined(__ia64__) emachine1 = emachine2 = EM_386; #endif symsize = sizeof (Elf32_Sym); @@ -1492,7 +1478,6 @@ s++; } -printf("%s:%s(%d) call dt_provider_lookup\n",__FUNCTION__,__FILE__,__LINE__); if ((pvp = dt_provider_lookup(dtp, pname)) == NULL) { return (dt_link_error(dtp, elf, fd, bufs, "no such provider %s", pname)); @@ -1560,6 +1545,9 @@ dtrace_program_link(dtrace_hdl_t *dtp, dtrace_prog_t *pgp, uint_t dflags, const char *file, int objc, char *const objv[]) { +#if !defined(sun) + char tfile[PATH_MAX]; +#endif char drti[PATH_MAX]; dof_hdr_t *dof; int fd, status, i, cur; @@ -1567,6 +1555,11 @@ size_t len; int eprobes = 0, ret = 0; +#if !defined(sun) + /* XXX Should get a temp file name here. */ + snprintf(tfile, sizeof(tfile), "%s.tmp", file); +#endif + /* * A NULL program indicates a special use in which we just link * together a bunch of object files specified in objv and then @@ -1628,6 +1621,7 @@ if ((dof = dtrace_dof_create(dtp, pgp, dflags)) == NULL) return (-1); /* errno is set for us */ +#if defined(sun) /* * Create a temporary file and then unlink it if we're going to * combine it with drti.o later. We can still refer to it in child @@ -1637,6 +1631,11 @@ return (dt_link_error(dtp, NULL, -1, NULL, "failed to open %s: %s", file, strerror(errno))); } +#else + if ((fd = open(tfile, O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) + return (dt_link_error(dtp, NULL, -1, NULL, + "failed to open %s: %s", tfile, strerror(errno))); +#endif /* * If -xlinktype=DOF has been selected, just write out the DOF. @@ -1666,8 +1665,10 @@ } +#if defined(sun) if (!dtp->dt_lazyload) (void) unlink(file); +#endif if (dtp->dt_oflags & DTRACE_O_LP64) status = dump_elf64(dtp, dof, fd); @@ -1680,6 +1681,7 @@ } if (!dtp->dt_lazyload) { +#if defined(sun) const char *fmt = "%s -o %s -r -Blocal -Breduce /dev/fd/%d %s"; if (dtp->dt_oflags & DTRACE_O_LP64) { @@ -1696,7 +1698,34 @@ cmd = alloca(len); (void) snprintf(cmd, len, fmt, dtp->dt_ld_path, file, fd, drti); +#else + const char *fmt = "%s -o %s -r %s %s"; +#if defined(__amd64__) + /* + * Arches which default to 64-bit need to explicitly use + * the 32-bit library path. + */ + int use_32 = !(dtp->dt_oflags & DTRACE_O_LP64); +#else + /* + * Arches which are 32-bit only just use the normal + * library path. + */ + int use_32 = 0; +#endif + + (void) snprintf(drti, sizeof (drti), "/usr/lib%s/dtrace/drti.o", + use_32 ? "":"32"); + + len = snprintf(&tmp, 1, fmt, dtp->dt_ld_path, file, tfile, + drti) + 1; + + cmd = alloca(len); + + (void) snprintf(cmd, len, fmt, dtp->dt_ld_path, file, tfile, drti); +#endif + if ((status = system(cmd)) == -1) { ret = dt_link_error(dtp, NULL, -1, NULL, "failed to run %s: %s", dtp->dt_ld_path, @@ -1725,5 +1754,9 @@ done: dtrace_dof_destroy(dtp, dof); + +#if !defined(sun) + unlink(tfile); +#endif return (ret); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801130420.m0D4KjFN046660>