diff options
author | Jason King <jason.brian.king@gmail.com> | 2012-09-14 12:26:23 -0400 |
---|---|---|
committer | Richard Lowe <richlowe@richlowe.net> | 2012-09-14 14:27:29 -0400 |
commit | a0ed50307cf80490d23a92f5eac0bfcd26343dd6 (patch) | |
tree | 16329dc2ed4814e15952accc959cd7ef14d15ece /usr | |
parent | 2007c08f9799ffdd411bdfb139620e810813c068 (diff) | |
download | illumos-gate-a0ed50307cf80490d23a92f5eac0bfcd26343dd6.tar.gz |
2224 closed-bins should be stripped of CTF
Reviewed by: Andrew Stormont <Andrew.Stormont@nexenta.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Diffstat (limited to 'usr')
-rw-r--r-- | usr/src/Makefile | 5 | ||||
-rw-r--r-- | usr/src/Makefile.master | 1 | ||||
-rw-r--r-- | usr/src/pkg/manifests/developer-build-onbld.mf | 1 | ||||
-rw-r--r-- | usr/src/tools/ctf/Makefile | 3 | ||||
-rw-r--r-- | usr/src/tools/ctf/ctfstrip/Makefile | 45 | ||||
-rw-r--r-- | usr/src/tools/ctf/ctfstrip/ctfstrip.c | 156 |
6 files changed, 208 insertions, 3 deletions
diff --git a/usr/src/Makefile b/usr/src/Makefile index 45252e17c9..c9cccb4502 100644 --- a/usr/src/Makefile +++ b/usr/src/Makefile @@ -125,7 +125,7 @@ mapfiles: bldtools clean clobber: $(SUBDIRS) head pkg -closedbins: FRC $(ROOTDIRS) +closedbins: bldtools $(ROOTDIRS) FRC @CLOSED_ROOT="$$ON_CLOSED_BINS/root_$(MACH)$${RELEASE_BUILD+-nd}"; \ if [ "$$CLOSED_IS_PRESENT" = no ]; then \ if [ ! -d "$$CLOSED_ROOT" ]; then \ @@ -139,6 +139,9 @@ closedbins: FRC $(ROOTDIRS) (cd $$CLOSED_ROOT; \ $(TAR) cfX - $(CODEMGR_WS)/exception_lists/closed-bins .) | \ (cd $(ROOT); $(TAR) xBpf -); \ + ( cd $(ROOT); $(CTFSTRIP) $$(cd $$CLOSED_ROOT; $(FIND) \ + ./kernel ./usr/kernel ./platform/*/kernel -type f -a -perm -u+x | \ + $(EGREP) -vf $(CODEMGR_WS)/exception_lists/closed-bins) ); \ fi # diff --git a/usr/src/Makefile.master b/usr/src/Makefile.master index 795f8e1d91..013363c9ef 100644 --- a/usr/src/Makefile.master +++ b/usr/src/Makefile.master @@ -193,6 +193,7 @@ JAR= $(JAVA_ROOT)/bin/jar CTFCONVERT= $(ONBLD_TOOLS)/bin/$(MACH)/ctfconvert CTFMERGE= $(ONBLD_TOOLS)/bin/$(MACH)/ctfmerge CTFSTABS= $(ONBLD_TOOLS)/bin/$(MACH)/ctfstabs +CTFSTRIP= $(ONBLD_TOOLS)/bin/$(MACH)/ctfstrip NDRGEN= $(ONBLD_TOOLS)/bin/$(MACH)/ndrgen GENOFFSETS= $(ONBLD_TOOLS)/bin/genoffsets CTFCVTPTBL= $(ONBLD_TOOLS)/bin/ctfcvtptbl diff --git a/usr/src/pkg/manifests/developer-build-onbld.mf b/usr/src/pkg/manifests/developer-build-onbld.mf index b97fa7ea1b..dbb194fb77 100644 --- a/usr/src/pkg/manifests/developer-build-onbld.mf +++ b/usr/src/pkg/manifests/developer-build-onbld.mf @@ -67,6 +67,7 @@ file path=opt/onbld/bin/$(ARCH)/ctfconvert mode=0555 file path=opt/onbld/bin/$(ARCH)/ctfdump mode=0555 file path=opt/onbld/bin/$(ARCH)/ctfmerge mode=0555 file path=opt/onbld/bin/$(ARCH)/ctfstabs mode=0555 +file path=opt/onbld/bin/$(ARCH)/ctfstrip mode=0555 file path=opt/onbld/bin/$(ARCH)/cw mode=0555 $(i386_ONLY)file path=opt/onbld/bin/$(ARCH)/elfextract mode=0555 file path=opt/onbld/bin/$(ARCH)/findunref mode=0555 diff --git a/usr/src/tools/ctf/Makefile b/usr/src/tools/ctf/Makefile index 3128f64e1f..0746c4943f 100644 --- a/usr/src/tools/ctf/Makefile +++ b/usr/src/tools/ctf/Makefile @@ -23,11 +23,10 @@ # Copyright 2004 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -#ident "%Z%%M% %I% %E% SMI" include ../Makefile.tools -SUBDIRS = cvt dump stabs scripts +SUBDIRS = cvt dump stabs scripts ctfstrip .PARALLEL: $(SUBDIRS) diff --git a/usr/src/tools/ctf/ctfstrip/Makefile b/usr/src/tools/ctf/ctfstrip/Makefile new file mode 100644 index 0000000000..80eca447e4 --- /dev/null +++ b/usr/src/tools/ctf/ctfstrip/Makefile @@ -0,0 +1,45 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +.KEEP_STATE: + +PROG = ctfstrip +SRCS = \ + ctfstrip.c + +CFLAGS += $(CCVERBOSE) +include $(SRC)/tools/Makefile.tools + +OBJS = $(SRCS:%.c=%.o) +LINTFILES = $(SRCS:%.c=%.ln) + +LINTFLAGS = -mnux -L$(ROOT)/usr/lib + +.NO_PARALLEL: +.PARALLEL: $(OBJS) $(LINTFILES) + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +$(ROOTONBLDMACHPROG): $(PROG) + +install: $(ROOTONBLDMACHPROG) + +clean: + $(RM) $(OBJS) $(LINTFILES) + +lint: $(LINTFILES) + $(LINT) $(LINTFLAGS) $(LINTFILES) $(LDLIBS) + +include $(SRC)/tools/Makefile.targ diff --git a/usr/src/tools/ctf/ctfstrip/ctfstrip.c b/usr/src/tools/ctf/ctfstrip/ctfstrip.c new file mode 100644 index 0000000000..60180c6921 --- /dev/null +++ b/usr/src/tools/ctf/ctfstrip/ctfstrip.c @@ -0,0 +1,156 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2011 Jason King. All rights reserved. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <fcntl.h> +#include <err.h> +#include <spawn.h> + +#define MCS "/usr/bin/mcs" + +#define ELFLEN 4 +static const char elf_signature[] = "\177ELF"; +static posix_spawnattr_t attr; +static const char *cmd[] = { MCS, "-d", "-n", ".SUNW_ctf", NULL, NULL }; + +extern char **environ; + +static boolean_t check_file(const char *, mode_t *); +static boolean_t fix_file(const char *, mode_t); +static void usage(const char *); + +int +main(int argc, const char **argv) +{ + const char **p; + int rc = 0; + mode_t mode; + + if (argc < 2) + usage(argv[0]); + + rc = posix_spawnattr_init(&attr); + if (rc != 0) { + errx(EXIT_FAILURE, "Spawn attribute initialization failed: %s", + strerror(rc)); + } + + for (p = argv + 1; *p != NULL; p++) { + if (!check_file(*p, &mode)) + continue; + if (!fix_file(*p, mode)) + rc = 1; + } + + return (rc); +} + +static boolean_t +check_file(const char *filename, mode_t *mode) +{ + char elfbuf[4]; + struct stat sb; + int fd; + + fd = open(filename, O_RDONLY); + if (fd == -1) { + warn("Unable to open %s", filename); + return (B_FALSE); + } + + if (fstat(fd, &sb) == -1) { + warn("stat(2) failed on %s", filename); + (void) close(fd); + return (B_FALSE); + } + + if (!S_ISREG(sb.st_mode)) { + warnx("%s is not a regular file", filename); + (void) close(fd); + return (B_FALSE); + } + + if (sb.st_size < ELFLEN) { + warnx("%s is not an ELF file", filename); + (void) close(fd); + return (B_FALSE); + } + + if (read(fd, elfbuf, ELFLEN) != ELFLEN) { + warn("Error reading %s", filename); + (void) close(fd); + return (B_FALSE); + } + + if (strncmp(elfbuf, elf_signature, ELFLEN) != 0) { + warnx("%s is not an ELF file", filename); + (void) close(fd); + return (B_FALSE); + } + + *mode = sb.st_mode & S_IAMB; + (void) close(fd); + return (B_TRUE); +} + +static boolean_t +fix_file(const char *filename, mode_t mode) +{ + pid_t pid; + int i, rc; + int stat = 0; + + if ((mode & S_IWUSR) == 0) { + if (chmod(filename, mode | S_IWUSR) == -1) { + warn("failed to make %s writable", filename); + return (B_FALSE); + } + } + + cmd[4] = filename; + if ((rc = posix_spawn(&pid, MCS, NULL, &attr, + (char *const *)cmd, environ)) != 0) { + warnx("could not exec mcs: %s", strerror(rc)); + return (B_FALSE); + } + + waitpid(pid, &stat, 0); + if (!WIFEXITED(stat) || WEXITSTATUS(stat) != 0) { + warnx("Removing CTF information from %s failed", filename); + return (B_FALSE); + } + + if ((mode & S_IWUSR) == 0) { + if (chmod(filename, mode) == -1) { + warn("could not reset permissions of %s", filename); + return (B_FALSE); + } + } + + return (B_TRUE); +} + +static void +usage(const char *name) +{ + (void) fprintf(stderr, "Usage: %s file...\n", name); + exit(EXIT_FAILURE); +} |