Mercurial > illumos > git > illumos-omnios
changeset 21411:31c8c83cb060
10942 want nm option to not sort symbols
10943 nm should be smatch and CERRWARN clean
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Gergő Doma <domag02@gmail.com>
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Reviewed by: C Fraire <cfraire@me.com>
Approved by: Dan McDonald <danmcd@joyent.com>
author | Robert Mustacchi <rm@joyent.com> |
---|---|
date | Fri, 08 Mar 2019 02:13:14 +0000 |
parents | 6fec3e496bcb |
children | 14d89c27b917 |
files | usr/src/cmd/sgs/nm/amd64/Makefile usr/src/cmd/sgs/nm/common/nm.c usr/src/cmd/sgs/nm/i386/Makefile usr/src/cmd/sgs/nm/sparc/Makefile usr/src/cmd/sgs/nm/sparcv9/Makefile usr/src/man/man1/nm.1 |
diffstat | 6 files changed, 238 insertions(+), 199 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/sgs/nm/amd64/Makefile Tue Dec 19 00:40:27 2017 +0000 +++ b/usr/src/cmd/sgs/nm/amd64/Makefile Fri Mar 08 02:13:14 2019 +0000 @@ -22,7 +22,7 @@ # Copyright 2010 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# Copyright (c) 2018, Joyent, Inc. +# Copyright (c) 2019, Joyent, Inc. # Copyright 2019 OmniOS Community Edition (OmniOSce) Association. # @@ -44,10 +44,6 @@ -I$(SRCBASE)/uts/$(ARCH)/sys CPPFLAGS= $(INCLIST) $(DEFLIST) $(CPPFLAGS.master) -I$(ELFCAP) -CERRWARN += -_gcc=-Wno-uninitialized - -SMOFF += precedence,indenting - LDLIBS += $(CONVLIBDIR64) $(CONV_LIB) $(ELFLIBDIR) -lelf %.o: ../common/%.c
--- a/usr/src/cmd/sgs/nm/common/nm.c Tue Dec 19 00:40:27 2017 +0000 +++ b/usr/src/cmd/sgs/nm/common/nm.c Fri Mar 08 02:13:14 2019 +0000 @@ -26,6 +26,7 @@ * * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2018 Jason King + * Copyright 2019, Joyent, Inc. */ #include <stdio.h> @@ -76,7 +77,7 @@ #define REG_WEAK "R*" #define REG_LOCL "r" -#define OPTSTR ":APDoxhvnursplLCVefgRTt:" /* option string for getopt() */ +#define OPTSTR ":APDoxhvniursplLCVefgRTt:" /* option string for getopt() */ #define DATESIZE 60 @@ -116,6 +117,7 @@ h_flag = 0, /* suppress printing of headings */ v_flag = 0, /* sort external symbols by value */ n_flag = 0, /* sort external symbols by name */ + i_flag = 0, /* don't sort symbols */ u_flag = 0, /* print only undefined symbols */ r_flag = 0, /* prepend object file or archive name */ /* to each symbol name */ @@ -210,141 +212,185 @@ while ((optchar = getopt(argc, argv, optstr)) != -1) { switch (optchar) { - case 'o': if (COMPAT_FMT_FLAG(FMT_T_OCT)) - fmt_flag = FMT_T_OCT; - else - (void) fprintf(stderr, gettext( - "%s: -x or -t set, -o ignored\n"), - prog_name); - break; - case 'x': if (COMPAT_FMT_FLAG(FMT_T_HEX)) - fmt_flag = FMT_T_HEX; - else - (void) fprintf(stderr, gettext( - "%s: -o or -t set, -x ignored\n"), - prog_name); - break; - case 'h': h_flag = 1; - break; - case 'v': if (!n_flag) - v_flag = 1; - else - (void) fprintf(stderr, gettext( - "%s: -n set, -v ignored\n"), - prog_name); - break; - case 'n': if (!v_flag) - n_flag = 1; - else - (void) fprintf(stderr, gettext( - "%s: -v set, -n ignored\n"), - prog_name); - break; - case 'u': if (!e_flag && !g_flag) - u_flag = 1; - else - (void) fprintf(stderr, gettext( - "%s: -e or -g set, -u ignored\n"), - prog_name); - break; - case 'e': if (!u_flag && !g_flag) - e_flag = 1; - else - (void) fprintf(stderr, gettext( - "%s: -u or -g set, -e ignored\n"), - prog_name); - break; - case 'g': if (!u_flag && !e_flag) - g_flag = 1; - else - (void) fprintf(stderr, gettext( - "%s: -u or -e set, -g ignored\n"), - prog_name); - break; - case 'r': if (R_flag) { - R_flag = 0; - (void) fprintf(stderr, gettext( - "%s: -r set, -R ignored\n"), - prog_name); - } - r_flag = 1; - break; - case 's': s_flag = 1; - break; - case 'p': if (P_flag == 1) { - (void) fprintf(stderr, gettext( - "nm: -P set. -p ignored\n")); - } else - p_flag = 1; - break; - case 'P': if (p_flag == 1) { - (void) fprintf(stderr, gettext( - "nm: -p set. -P ignored\n")); - } else - P_flag = 1; - break; - case 'l': l_flag = 1; - break; - case 'L': if (D_flag == 1) { - (void) fprintf(stderr, gettext( - "nm: -D set. -L ignored\n")); - } else - L_flag = 1; - break; - case 'D': if (L_flag == 1) { - (void) fprintf(stderr, gettext( - "nm: -L set. -D ignored\n")); - } else - D_flag = 1; - break; + case 'o': + if (COMPAT_FMT_FLAG(FMT_T_OCT)) { + fmt_flag = FMT_T_OCT; + } else { + (void) fprintf(stderr, gettext( + "%s: -x or -t set, -o ignored\n"), + prog_name); + } + break; + case 'x': + if (COMPAT_FMT_FLAG(FMT_T_HEX)) { + fmt_flag = FMT_T_HEX; + } else { + (void) fprintf(stderr, gettext( + "%s: -o or -t set, -x ignored\n"), + prog_name); + } + break; + case 'h': + h_flag = 1; + break; + case 'v': + if (!n_flag && !i_flag) { + v_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -n or -i set, -v ignored\n"), + prog_name); + } + break; + case 'n': + if (!v_flag && !i_flag) { + n_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -v or -i set, -n ignored\n"), + prog_name); + } + break; + case 'i': + if (!n_flag && !v_flag) { + i_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -n or -v set, -i ignored\n"), + prog_name); + } + break; + case 'u': + if (!e_flag && !g_flag) { + u_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -e or -g set, -u ignored\n"), + prog_name); + } + break; + case 'e': + if (!u_flag && !g_flag) { + e_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -u or -g set, -e ignored\n"), + prog_name); + } + break; + case 'g': + if (!u_flag && !e_flag) { + g_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -u or -e set, -g ignored\n"), + prog_name); + } + break; + case 'r': + if (R_flag) { + R_flag = 0; + (void) fprintf(stderr, gettext( + "%s: -r set, -R ignored\n"), + prog_name); + } + r_flag = 1; + break; + case 's': + s_flag = 1; + break; + case 'p': + if (P_flag == 1) { + (void) fprintf(stderr, gettext( + "nm: -P set. -p ignored\n")); + } else { + p_flag = 1; + } + break; + case 'P': + if (p_flag == 1) { + (void) fprintf(stderr, gettext( + "nm: -p set. -P ignored\n")); + } else { + P_flag = 1; + } + break; + case 'l': + l_flag = 1; + break; + case 'L': + if (D_flag == 1) { + (void) fprintf(stderr, gettext( + "nm: -D set. -L ignored\n")); + } else { + L_flag = 1; + } + break; + case 'D': + if (L_flag == 1) { + (void) fprintf(stderr, gettext( + "nm: -L set. -D ignored\n")); + } else { + D_flag = 1; + } + break; case 'C': - C_flag = 1; - break; - case 'A': A_flag = 1; - break; - case 'V': V_flag = 1; - (void) fprintf(stderr, "nm: %s %s\n", - (const char *)SGU_PKG, - (const char *)SGU_REL); - break; + C_flag = 1; + break; + case 'A': + A_flag = 1; + break; + case 'V': + V_flag = 1; + (void) fprintf(stderr, "nm: %s %s\n", + (const char *)SGU_PKG, + (const char *)SGU_REL); + break; case 'f': /* -f is a noop, see man page */ - break; - case 'R': if (!r_flag) - R_flag = 1; - else - (void) fprintf(stderr, gettext( - "%s: -r set, -R ignored\n"), - prog_name); - break; + break; + case 'R': + if (!r_flag) { + R_flag = 1; + } else { + (void) fprintf(stderr, gettext( + "%s: -r set, -R ignored\n"), + prog_name); + } + break; case 'T': - break; - case 't': if (strcmp(optarg, "o") == 0) { - new_fmt_flag = FMT_T_OCT; - } else if (strcmp(optarg, "d") == 0) { - new_fmt_flag = FMT_T_DEC; - } else if (strcmp(optarg, "x") == 0) { - new_fmt_flag = FMT_T_HEX; - } else { - new_fmt_flag = FMT_T_NONE; - } - if (new_fmt_flag == FMT_T_NONE) { - errflag += 1; - (void) fprintf(stderr, gettext( -"nm: -t requires radix value (d, o, x): %s\n"), optarg); - } else if (COMPAT_FMT_FLAG(new_fmt_flag)) { - fmt_flag = new_fmt_flag; - } else { - (void) fprintf(stderr, gettext( - "nm: -t or -o or -x set. -t ignored.\n")); - } - break; - case ':': errflag += 1; + break; + case 't': + if (strcmp(optarg, "o") == 0) { + new_fmt_flag = FMT_T_OCT; + } else if (strcmp(optarg, "d") == 0) { + new_fmt_flag = FMT_T_DEC; + } else if (strcmp(optarg, "x") == 0) { + new_fmt_flag = FMT_T_HEX; + } else { + new_fmt_flag = FMT_T_NONE; + } + if (new_fmt_flag == FMT_T_NONE) { + errflag += 1; (void) fprintf(stderr, gettext( - "nm: %c requires operand\n"), optopt); - break; - case '?': errflag += 1; - break; - default: break; + "nm: -t requires radix value (d, o, x): " + "%s\n"), optarg); + } else if (COMPAT_FMT_FLAG(new_fmt_flag)) { + fmt_flag = new_fmt_flag; + } else { + (void) fprintf(stderr, gettext( + "nm: -t or -o or -x set. -t ignored.\n")); + } + break; + case ':': + errflag += 1; + (void) fprintf(stderr, gettext( + "nm: %c requires operand\n"), optopt); + break; + case '?': + errflag += 1; + break; + default: + break; } } @@ -381,7 +427,7 @@ usage() { (void) fprintf(stderr, gettext( -"Usage: nm [-ACDhLlnPpRrsTVv] [-efox] [-g | -u] [-t d|o|x] file ...\n")); +"Usage: nm [-ACDhiLlnPpRrsTVv] [-efox] [-g | -u] [-t d|o|x] file ...\n")); } /* @@ -451,20 +497,20 @@ (void) printf(gettext( "\n\nUndefined symbols from %s:\n\n"), filename); - } else if (!h_flag & !P_flag) + } else if ((h_flag == 0) && (P_flag == 0)) { #else - if (!h_flag & !P_flag) + if ((h_flag == 0) && (P_flag == 0)) { #endif - { - if (p_flag) + if (p_flag) { (void) printf("\n\n%s:\n", filename); - else { - if (A_flag != 0) + } else { + if (A_flag != 0) { (void) printf("\n\n%s%s:\n", A_header, filename); - else + } else { (void) printf("\n\n%s:\n", filename); + } } } archive_name = (char *)0; @@ -616,11 +662,11 @@ continue; } - if (!h_flag & !P_flag) { - if (p_flag) + if ((h_flag == 0) && (P_flag == 0)) { + if (p_flag) { (void) printf("\n\n%s[%s]:\n", filename, p_ar->ar_name); - else { + } else { if (A_flag != 0) (void) printf("\n\n%s%s[%s]:\n", A_header, filename, p_ar->ar_name); @@ -715,8 +761,10 @@ prog_name, filename); return; } - qsort((char *)sym_data, count-1, sizeof (SYM), - (int (*)(const void *, const void *))compare); + if (i_flag == 0) { + qsort((char *)sym_data, count-1, sizeof (SYM), + (int (*)(const void *, const void *))compare); + } s = sym_data; while (count > 1) { #ifndef XPG4 @@ -725,18 +773,19 @@ * U_flag specified */ print_with_uflag(sym_data, filename); - } else if (p_flag) + } else if (p_flag) { #else - if (p_flag) + if (p_flag) { #endif print_with_pflag(ndigits, elf_file, shstrndx, sym_data, filename); - else if (P_flag) + } else if (P_flag) { print_with_Pflag(ndigits, elf_file, shstrndx, sym_data); - else + } else { print_with_otherflags(ndigits, elf_file, shstrndx, sym_data, filename); + } sym_data++; count--; } @@ -803,9 +852,9 @@ buf->indx = i; /* allow to work on machines where NULL-derefs dump core */ - if (sym.st_name == 0) + if (sym.st_name == 0) { buf->name = ""; - else if (C_flag) { + } else if (C_flag) { const char *dn = NULL; char *name = (char *)elf_strptr(elf, link, sym.st_name); @@ -817,9 +866,9 @@ name = FormatName(name, d_buf); } buf->name = name; + } else { + buf->name = (char *)elf_strptr(elf, link, sym.st_name); } - else - buf->name = (char *)elf_strptr(elf, link, sym.st_name); buf->value = sym.st_value; buf->size = sym.st_size; @@ -1456,29 +1505,34 @@ void parse_fn_and_print(const char *str, char *s) { - char c, *p1, *p2; + char c = '\0', *p1, *p2; int yes = 1; - if ((p1 = p2 = strstr(s, "_c_")) == NULL) - if ((p1 = p2 = strstr(s, "_C_")) == NULL) - if ((p1 = p2 = strstr(s, "_cc_")) == NULL) - if ((p1 = p2 = strstr(s, "_cxx_")) == NULL) + if ((p1 = p2 = strstr(s, "_c_")) == NULL) { + if ((p1 = p2 = strstr(s, "_C_")) == NULL) { + if ((p1 = p2 = strstr(s, "_cc_")) == NULL) { + if ((p1 = p2 = strstr(s, "_cxx_")) == NULL) { if ((p1 = p2 = strstr(s, "_h_")) == - NULL) - yes = 0; - else + NULL) { + yes = 0; + } else { p2 += 2; - else + } + } else { p2 += 4; - else + } + } else { p2 += 3; - else + } + } else { p2 += 2; - else + } + } else { p2 += 2; + } if (yes) { - *p1 = '.'; + *p1 = '.'; c = *p2; *p2 = '\0'; }
--- a/usr/src/cmd/sgs/nm/i386/Makefile Tue Dec 19 00:40:27 2017 +0000 +++ b/usr/src/cmd/sgs/nm/i386/Makefile Fri Mar 08 02:13:14 2019 +0000 @@ -21,7 +21,7 @@ # # Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. # -# Copyright (c) 2018, Joyent, Inc. +# Copyright (c) 2019, Joyent, Inc. # Copyright 2019 OmniOS Community Edition (OmniOSce) Association. # @@ -46,10 +46,6 @@ DEFLIST= -DTARGET=I386 -DI386=1 -D$(ARFORMAT) -DELF CPPFLAGS= $(INCLIST) $(DEFLIST) $(CPPFLAGS.master) -I$(ELFCAP) -CERRWARN += -_gcc=-Wno-uninitialized - -SMOFF += precedence,indenting - LDLIBS += $(CONVLIBDIR) $(CONV_LIB) $(ELFLIBDIR) -lelf objs.xpg4/%.o := CPPFLAGS += -DXPG4
--- a/usr/src/cmd/sgs/nm/sparc/Makefile Tue Dec 19 00:40:27 2017 +0000 +++ b/usr/src/cmd/sgs/nm/sparc/Makefile Fri Mar 08 02:13:14 2019 +0000 @@ -45,7 +45,6 @@ -I$(SRCBASE)/uts/$(ARCH)/sys DEFLIST= -DTARGET=SPARC -DSPARC=1 -D$(ARFORMAT) -DELF CPPFLAGS= $(INCLIST) $(DEFLIST) $(CPPFLAGS.master) -I$(ELFCAP) -CERRWARN += -_gcc=-Wno-uninitialized LDLIBS += $(CONVLIBDIR) $(CONV_LIB) $(ELFLIBDIR) -lelf objs.xpg4/%.o := CPPFLAGS += -DXPG4
--- a/usr/src/cmd/sgs/nm/sparcv9/Makefile Tue Dec 19 00:40:27 2017 +0000 +++ b/usr/src/cmd/sgs/nm/sparcv9/Makefile Fri Mar 08 02:13:14 2019 +0000 @@ -43,7 +43,6 @@ -I$(SRCBASE)/uts/$(ARCH)/sys DEFLIST= -DTARGET=SPARC -DSPARC=1 -D$(ARFORMAT) -DELF CPPFLAGS= $(INCLIST) $(DEFLIST) $(CPPFLAGS.master) -I$(ELFCAP) -CERRWARN += -_gcc=-Wno-uninitialized LDLIBS += $(CONVLIBDIR64) $(CONV_LIB) $(ELFLIBDIR) -lelf
--- a/usr/src/man/man1/nm.1 Tue Dec 19 00:40:27 2017 +0000 +++ b/usr/src/man/man1/nm.1 Fri Mar 08 02:13:14 2019 +0000 @@ -43,25 +43,25 @@ .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved +.\" Copyright 2019, Joyent, Inc. .\" -.TH NM 1 "Sep 10, 2013" +.TH NM 1 "March 7, 2019" .SH NAME nm \- print name list of an object file .SH SYNOPSIS .LP .nf -\fB/usr/bin/nm\fR [\fB-ACDhlnPprRsTuVv\fR] [\fB-efox\fR] [\fB-g\fR | \fB-u\fR] +\fB/usr/bin/nm\fR [\fB-ACDhilnPprRsTuVv\fR] [\fB-efox\fR] [\fB-g\fR | \fB-u\fR] [\fB-t\fR \fIformat\fR] \fIfile\fR... .fi .LP .nf -\fB/usr/xpg4/bin/nm\fR [\fB-ACDhlnPprRsTuVv\fR] [\fB-efox\fR] [\fB-g\fR | \fB-u\fR] +\fB/usr/xpg4/bin/nm\fR [\fB-ACDhilnPprRsTuVv\fR] [\fB-efox\fR] [\fB-g\fR | \fB-u\fR] [\fB-t\fR \fIformat\fR] \fIfile\fR... .fi .SH DESCRIPTION -.sp .LP The \fBnm\fR utility displays the symbol table of each \fBELF\fR object file that is specified by \fIfile\fR. @@ -70,7 +70,6 @@ If no symbolic information is available for a valid input file, the \fBnm\fR utility reports that fact, but not consider it an error condition. .SH OPTIONS -.sp .LP The output of \fBnm\fR can be controlled using the following options: .sp @@ -109,7 +108,7 @@ \fB\fB-e\fR\fR .ad .RS 13n -See NOTES below. +This option has been deprecated. For more information, see \fBNOTES\fR below. .RE .sp @@ -118,7 +117,7 @@ \fB\fB-f\fR\fR .ad .RS 13n -See NOTES below. +This option has been deprecated. For more information, see \fBNOTES\fR below. .RE .sp @@ -156,6 +155,15 @@ .sp .ne 2 .na +\fB\fB-i\fR\fR +.ad +.RS 13n +Display symbols in the existing symbol table order; do not sort them. +.RE + +.sp +.ne 2 +.na \fB\fB-l\fR\fR .ad .RS 13n @@ -392,11 +400,10 @@ \fB\fB-T\fR\fR .ad .RS 13n -See \fBNOTES\fR. +This option has been deprecated. For more information, see \fBNOTES\fR below. .RE .SS "/usr/bin/nm" -.sp .ne 2 .na \fB\fB-u\fR\fR @@ -406,7 +413,6 @@ .RE .SS "/usr/xpg4/bin/nm" -.sp .ne 2 .na \fB\fB-u\fR\fR @@ -452,7 +458,6 @@ and the second ignored with a warning message to the user. (See \fB-R\fR for exception.) .SH OPERANDS -.sp .LP The following operand is supported: .sp @@ -465,11 +470,9 @@ .RE .SH OUTPUT -.sp .LP This section describes the \fBnm\fR utility's output options. .SS "Standard Output" -.sp .LP For each symbol, the following information is printed: .sp @@ -814,13 +817,11 @@ If \fB-P\fR is specified, but \fB-t\fR is not, the format is as if \fB-t\fR \fBx\fR had been specified. .SH ENVIRONMENT VARIABLES -.sp .LP See \fBenviron\fR(5) for descriptions of the following environment variables that affect the execution of \fBnm\fR: \fBLANG\fR, \fBLC_ALL\fR, \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR. .SH EXIT STATUS -.sp .LP The following exit values are returned: .sp @@ -842,13 +843,9 @@ .RE .SH ATTRIBUTES -.sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .SH /USR/XPG4/BIN/NM -.sp - -.sp .TS box; c | c @@ -859,13 +856,11 @@ .TE .SH SEE ALSO -.sp .LP \fBar\fR(1), \fBas\fR(1), \fBdump\fR(1), \fBld\fR(1), \fBld.so.1\fR(1), \fBar.h\fR(3HEAD), \fBa.out\fR(4), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5) .SH NOTES -.sp .LP The following options are obsolete because of changes to the object file format and might be deleted in a future release.