Index: Makefile.inc1 =================================================================== --- Makefile.inc1 +++ Makefile.inc1 @@ -1415,6 +1415,15 @@ # If we're given an XAS, don't build binutils. .if ${XAS:M/*} == "" && ${MK_BINUTILS_BOOTSTRAP} != "no" _binutils= gnu/usr.bin/binutils +.if ${MK_ELFTOOLCHAIN_TOOLS} != "no" +_elftctools= lib/libelftc \ + usr.bin/addr2line \ + usr.bin/elfcopy \ + usr.bin/nm \ + usr.bin/size \ + usr.bin/strings \ + usr.bin/strip +.endif .endif # If an full path to an external cross compiler is given, don't build @@ -1434,6 +1443,7 @@ ${_clang_libs} \ ${_clang} \ ${_binutils} \ + ${_elftctools} \ ${_cc} \ usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \ ${_btxld} \ @@ -1491,6 +1501,7 @@ ${_clang_tblgen} \ usr.bin/ar \ ${_binutils} \ + ${_elftctools} \ ${_cc} \ ${_gcc_tools} \ ${_clang_libs} \ @@ -2045,6 +2056,7 @@ _xb-cross-tools: .for _tool in \ ${_binutils} \ + ${_elftctools} \ usr.bin/ar \ ${_clang_libs} \ ${_clang} \ @@ -2077,6 +2089,7 @@ @echo "_xi-cross-tools" .for _tool in \ ${_binutils} \ + ${_elftctools} \ usr.bin/ar \ ${_clang_libs} \ ${_clang} \ Index: contrib/elftoolchain/elfcopy/archive.c =================================================================== --- contrib/elftoolchain/elfcopy/archive.c +++ contrib/elftoolchain/elfcopy/archive.c @@ -350,12 +350,12 @@ r = -1; if ((a = archive_read_new()) == NULL) return (0); - archive_read_support_compression_none(a); + archive_read_support_filter_none(a); archive_read_support_format_ar(a); if (archive_read_open_fd(a, ifd, 10240) == ARCHIVE_OK) r = archive_read_next_header(a, &entry); archive_read_close(a); - archive_read_finish(a); + archive_read_free(a); return (r == ARCHIVE_OK); } @@ -386,7 +386,7 @@ err(EXIT_FAILURE, "lseek failed"); if ((a = archive_read_new()) == NULL) errx(EXIT_FAILURE, "%s", archive_error_string(a)); - archive_read_support_compression_none(a); + archive_read_support_filter_none(a); archive_read_support_format_ar(a); AC(archive_read_open_fd(a, ifd, 10240)); for(;;) { @@ -435,7 +435,7 @@ } } AC(archive_read_close(a)); - ACV(archive_read_finish(a)); + ACV(archive_read_free(a)); } static void @@ -449,7 +449,7 @@ if ((a = archive_write_new()) == NULL) errx(EXIT_FAILURE, "%s", archive_error_string(a)); archive_write_set_format_ar_svr4(a); - archive_write_set_compression_none(a); + archive_write_add_filter_none(a); AC(archive_write_open_fd(a, ofd)); /* Write the archive symbol table, even if it's empty. */ @@ -491,7 +491,7 @@ } AC(archive_write_close(a)); - ACV(archive_write_finish(a)); + ACV(archive_write_free(a)); } static void Index: contrib/elftoolchain/elfcopy/ascii.c =================================================================== --- contrib/elftoolchain/elfcopy/ascii.c +++ contrib/elftoolchain/elfcopy/ascii.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include Index: contrib/elftoolchain/elfcopy/segments.c =================================================================== --- contrib/elftoolchain/elfcopy/segments.c +++ contrib/elftoolchain/elfcopy/segments.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ struct section *s, *s0; struct segment *seg; struct sec_action *sac; - uint64_t dl, lma, old_vma, start, end; + uint64_t dl, lma, start, end; int found, i; /* @@ -113,8 +114,6 @@ s->lma += ecp->change_addr; if (!s->pseudo) { - old_vma = s->vma; - /* Apply global VMA adjustment. */ if (ecp->change_addr != 0) s->vma += ecp->change_addr; Index: contrib/elftoolchain/elfcopy/symbols.c =================================================================== --- contrib/elftoolchain/elfcopy/symbols.c +++ contrib/elftoolchain/elfcopy/symbols.c @@ -300,7 +300,7 @@ GElf_Sym sym; Elf_Data* id; Elf_Scn *is; - size_t ishstrndx, namelen, ndx, nsyms, sc, symndx; + size_t ishstrndx, namelen, ndx, sc, symndx; int ec, elferr, i; if (elf_getshstrndx(ecp->ein, &ishstrndx) == 0) @@ -320,7 +320,6 @@ st_buf->lcap = 64; st_buf->lsz = 1; /* '\0' at start. */ st_buf->gsz = 0; - nsyms = 0; ecp->symtab->sz = 0; ecp->strtab->sz = 0; Index: contrib/elftoolchain/libelftc/elftc_copyfile.c =================================================================== --- contrib/elftoolchain/libelftc/elftc_copyfile.c +++ contrib/elftoolchain/libelftc/elftc_copyfile.c @@ -79,11 +79,13 @@ * If mmap() is not available, or if the mmap() operation * failed, allocate a buffer, and read in input data. */ - if (buf == NULL) { + if (buf_mmapped == false) { if ((buf = malloc(sb.st_size)) == NULL) return (-1); - if (read(ifd, buf, sb.st_size) != sb.st_size) + if (read(ifd, buf, sb.st_size) != sb.st_size) { + free(buf); return (-1); + } } /* Index: contrib/elftoolchain/libelftc/elftc_demangle.c =================================================================== --- contrib/elftoolchain/libelftc/elftc_demangle.c +++ contrib/elftoolchain/libelftc/elftc_demangle.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include Index: contrib/elftoolchain/libelftc/elftc_version.c =================================================================== --- /dev/null +++ contrib/elftoolchain/libelftc/elftc_version.c @@ -0,0 +1,10 @@ +/* WARNING: Generated by "make-toolchain-version". */ + +#include +#include + +const char * +elftc_version(void) +{ + return "elftoolchain HEAD FreeBSD git:heads/misc-0-g79de7c3"; +} Index: contrib/elftoolchain/libelftc/libelftc.h =================================================================== --- contrib/elftoolchain/libelftc/libelftc.h +++ contrib/elftoolchain/libelftc/libelftc.h @@ -34,6 +34,9 @@ #include +/* + * Types meant to be opaque to the consumers of these APIs. + */ typedef struct _Elftc_Bfd_Target Elftc_Bfd_Target; typedef struct _Elftc_String_Table Elftc_String_Table; Index: contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c =================================================================== --- contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c +++ contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c @@ -156,7 +156,7 @@ static int vector_type_qualifier_push(struct vector_type_qualifier *, enum type_qualifier); -int cpp_demangle_gnu3_push_head; +static int cpp_demangle_gnu3_push_head; /** * @brief Decode the input string by IA-64 C++ ABI style. Index: contrib/elftoolchain/nm/nm.c =================================================================== --- contrib/elftoolchain/nm/nm.c +++ contrib/elftoolchain/nm/nm.c @@ -65,7 +65,7 @@ typedef int (*fn_filter)(char, const GElf_Sym *, const char *); /* output filter list */ -SLIST_HEAD(filter_head, filter_entry) nm_out_filter = +static SLIST_HEAD(filter_head, filter_entry) nm_out_filter = SLIST_HEAD_INITIALIZER(nm_out_filter); struct filter_entry { Index: contrib/elftoolchain/size/size.c =================================================================== --- contrib/elftoolchain/size/size.c +++ contrib/elftoolchain/size/size.c @@ -269,7 +269,7 @@ static pid_t pid; uintptr_t ver; Elf32_Nhdr *nhdr, nhdr_l; - static int reg_pseudo = 0, reg2_pseudo = 0, regxfp_pseudo = 0; + static int reg_pseudo = 0, reg2_pseudo = 0 /*, regxfp_pseudo = 0*/; char buf[BUF_SIZE], *data, *name; if (elf == NULL || elfhdr == NULL || phdr == NULL) @@ -360,6 +360,7 @@ text_size_total += nhdr_l.n_descsz; } break; +#if 0 case NT_AUXV: if (style == STYLE_SYSV) { tbl_append(); @@ -390,6 +391,7 @@ } break; case NT_PSINFO: +#endif case NT_PRPSINFO: { /* FreeBSD 64-bit */ if (nhdr_l.n_descsz == 0x78 && @@ -415,8 +417,10 @@ } break; } +#if 0 case NT_PSTATUS: case NT_LWPSTATUS: +#endif default: break; } Index: contrib/elftoolchain/strings/strings.c =================================================================== --- contrib/elftoolchain/strings/strings.c +++ contrib/elftoolchain/strings/strings.c @@ -75,9 +75,9 @@ (encoding == ENCODING_8BIT && (c) > 127))) -int encoding_size, entire_file, min_len, show_filename, show_loc; -enum encoding_style encoding; -enum radix_style radix; +static int encoding_size, entire_file, min_len, show_filename, show_loc; +static enum encoding_style encoding; +static enum radix_style radix; static struct option strings_longopts[] = { { "all", no_argument, NULL, 'a'}, Index: gnu/usr.bin/binutils/Makefile =================================================================== --- gnu/usr.bin/binutils/Makefile +++ gnu/usr.bin/binutils/Makefile @@ -1,19 +1,29 @@ # $FreeBSD$ +.include + SUBDIR= libiberty \ libbfd \ libopcodes \ libbinutils \ - addr2line \ + ${_addr2line} \ as \ ld \ - nm \ + ${_nm} \ objcopy \ objdump \ readelf \ - size \ - strings \ - strip \ + ${_size} \ + ${_strings} \ + ${_strip} \ doc + +.if ${MK_ELFTOOLCHAIN_TOOLS} == "no" +_addr2line addr2line +_nm= nm +_size= size +_strings= strings +_strip= strip +.endif .include Index: lib/Makefile =================================================================== --- lib/Makefile +++ lib/Makefile @@ -45,6 +45,7 @@ libdpv \ libdwarf \ libedit \ + ${_libelftc} \ ${_libevent} \ libexecinfo \ libexpat \ @@ -190,6 +191,10 @@ _cuse= libcuse .endif +.if ${MK_ELFTOOLCHAIN_TOOLS} != "no" +_libelftc= libelftc +.endif + .if ${MK_GPIB} != "no" _libgpib= libgpib .endif Index: lib/libelftc/Makefile =================================================================== --- /dev/null +++ lib/libelftc/Makefile @@ -0,0 +1,32 @@ +# $FreeBSD$ +.include + +INTERNALLIB= + +ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain + +.PATH: ${ELFTCDIR}/libelftc + +LIB= elftc + +SRCS= elftc_bfdtarget.c \ + elftc_copyfile.c \ + elftc_demangle.c \ + elftc_set_timestamps.c \ + elftc_string_table.c \ + elftc_version.c \ + libelftc_bfdtarget.c \ + libelftc_dem_arm.c \ + libelftc_dem_gnu2.c \ + libelftc_dem_gnu3.c \ + libelftc_hash.c \ + libelftc_vstr.c + +INCS= libelftc.h +CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common + +LDADD+= -lelf + +MAN= + +.include Index: lib/libelftc/elftc_version.c =================================================================== --- /dev/null +++ lib/libelftc/elftc_version.c @@ -0,0 +1,8 @@ +#include +#include + +const char * +elftc_version(void) +{ + return "libelftc r3076"; +} Index: share/mk/src.libnames.mk =================================================================== --- share/mk/src.libnames.mk +++ share/mk/src.libnames.mk @@ -27,6 +27,7 @@ amu \ bsnmptools \ cron \ + elftc \ event \ fifolog \ ipf \ @@ -289,6 +290,10 @@ LIBBSDSTATDIR= ${ROOTOBJDIR}/lib/libbsdstat LIBBSDSTAT?= ${LIBBSDSTATDIR}/libbsdstat.a +LIBELFTCDIR= ${ROOTOBJDIR}/lib/libelftc +LDELFTC?= ${LIBELFTCDIR}/libelftc.a +LIBELFTC?= ${LIBELFTCDIR}/libelftc.a + LIBEVENTDIR= ${ROOTOBJDIR}/lib/libevent LIBEVENT?= ${LIBEVENTDIR}/libevent.a Index: share/mk/src.opts.mk =================================================================== --- share/mk/src.opts.mk +++ share/mk/src.opts.mk @@ -160,6 +160,7 @@ BSD_GREP \ CLANG_EXTRAS \ EISA \ + ELFTOOLCHAIN_TOOLS \ FMAKE \ HESIOD \ LLDB \ Index: tools/build/options/WITH_ELFTOOLCHAIN_TOOLS =================================================================== --- /dev/null +++ tools/build/options/WITH_ELFTOOLCHAIN_TOOLS @@ -0,0 +1,9 @@ +.\" $FreeBSD$ +Set to use +.Xr addr2line 1 , +.Xr nm 1 , +.Xr size 1 , +.Xr strings 1 , +and +.Xr strip 1 +from the elftoolchain project instead of GNU binutils. Index: usr.bin/Makefile =================================================================== --- usr.bin/Makefile +++ usr.bin/Makefile @@ -9,7 +9,8 @@ # Moved to secure: bdes # -SUBDIR= alias \ +SUBDIR= ${_addr2line} \ + alias \ apply \ asa \ awk \ @@ -41,6 +42,7 @@ du \ ee \ elf2aout \ + ${_elfcopy} \ elfdump \ enigma \ env \ @@ -119,6 +121,7 @@ nfsstat \ nice \ nl \ + ${_nm} \ nohup \ opieinfo \ opiekey \ @@ -150,12 +153,14 @@ seq \ shar \ showmount \ + ${_size} \ sockstat \ soeliminate \ sort \ split \ stat \ stdbuf \ + ${_strings} \ su \ systat \ tabs \ @@ -236,6 +241,14 @@ _clang= clang .endif +.if ${MK_ELFTOOLCHAIN_TOOLS} != "no" +_addr2line= addr2line +_elfcopy= elfcopy +_nm= nm +_size= size +_strings= strings +.endif + .if ${MK_FMAKE} != "no" SUBDIR+= make .endif Index: usr.bin/addr2line/Makefile =================================================================== --- /dev/null +++ usr.bin/addr2line/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain +ADDR2LINEDIR= ${ELFTCDIR}/addr2line + +.PATH: ${ADDR2LINEDIR} + +PROG= addr2line + +LIBADD= elftc dwarf elf + +CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common + +NO_SHARED?= yes + +.include Index: usr.bin/elfcopy/Makefile =================================================================== --- /dev/null +++ usr.bin/elfcopy/Makefile @@ -0,0 +1,32 @@ +# $FreeBSD$ + +.include + +ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain +ELFCOPYDIR= ${ELFTCDIR}/elfcopy + +.PATH: ${ELFCOPYDIR} + +PROG= elfcopy + +SRCS= archive.c ascii.c binary.c main.c sections.c segments.c symbols.c + +WARNS?= 5 + +LIBADD= archive elftc elf + +CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common + +MAN= elfcopy.1 mcs.1 bsdstrip.1 + +NO_SHARED?= yes + +LINKS= ${BINDIR}/elfcopy ${BINDIR}/bsdstrip \ + ${BINDIR}/elfcopy ${BINDIR}/mcs + +CLEANFILES+= bsdstrip.1 + +bsdstrip.1: strip.1 + cp -p ${.ALLSRC} ${.TARGET} + +.include Index: usr.bin/nm/Makefile =================================================================== --- /dev/null +++ usr.bin/nm/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain +NMDIR= ${ELFTCDIR}/nm + +.PATH: ${NMDIR} + +PROG= nm + +LIBADD= dwarf elftc elf + +CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common + +NO_SHARED?= yes + +.include Index: usr.bin/size/Makefile =================================================================== --- /dev/null +++ usr.bin/size/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain +SIZEDIR= ${ELFTCDIR}/size + +.PATH: ${SIZEDIR} + +PROG= size + +LIBADD= elftc elf + +CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common + +NO_SHARED?= yes + +.include Index: usr.bin/strings/Makefile =================================================================== --- /dev/null +++ usr.bin/strings/Makefile @@ -0,0 +1,17 @@ +# $FreeBSD$ + +.include + +ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain + +.PATH: ${ELFTCDIR}/strings + +PROG= strings + +LIBADD= elftc elf + +CFLAGS+=-I${ELFTCDIR}/libelftc -I${ELFTCDIR}/common + +NO_SHARED?= yes + +.include