# Copyright 1999-2003 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 # Author: Martin Schlemmer # Contributor: Ned Ludd # $Header: /home/httpd/cvsroot/gentoo-x86/sys-devel/gcc/files/awk/scanforssp.awk,v 1.1 2003/12/28 21:46:24 azarah Exp $ # does not seem to be used in this script. function printn(string) { printf("%s", string) } function einfo(string) { printf(" %s %s%s", "\033[32;01m*\033[0m", string, "\n") } # does not seem to be used in this script. function einfon(string) { printf(" %s %s" , "\033[32;01m*\033[0m", string) } function ewarn(string) { printf(" %s %s%s" , "\033[33;01m*\033[0m", string, "\n") } # does not seem to be used in this script. function ewarnn(string) { printf("%s %s" , "\032[33;01m*\033[0m", string) } # does not seem to be used in this script. function eerror(string) { printf(" %s %s%s" , "\033[31;01m*\033[0m", string, "\n") } function iself(scan_files) { # can we open() a file and read() 4 bytes? scan_file_pipe = ("head -c 4 " scan_files " 2>/dev/null | tail -c 3") scan_file_pipe | getline scan_data close("head -c 4 " scan_files " 2>/dev/null | tail -c 3") return ((scan_data == "ELF") ? 0 : 1) } BEGIN { auto_etcat = 0 DIRCOUNT = 0 # Add the two default library paths DIRLIST[1] = "/lib" DIRLIST[2] = "/usr/lib" # Walk /etc/ld.so.conf line for line and get any library paths pipe = "cat /etc/ld.so.conf 2>/dev/null | sort" while(((pipe) | getline ldsoconf_data) > 0) { if (ldsoconf_data !~ /^[[:space:]]*#/) { if (ldsoconf_data == "") continue # Remove any trailing comments sub(/#.*$/, "", ldsoconf_data) # Remove any trailing spaces sub(/[[:space:]]+$/, "", ldsoconf_data) split(ldsoconf_data, nodes, /[:,[:space:]]/) # Now add the rest from ld.so.conf for (x in nodes) { sub(/=.*/, "", nodes[x]) sub(/\/$/, "", nodes[x]) if (nodes[x] == "") continue CHILD = 0 # Drop the directory if its a child directory of # one that was already added ... for (y in DIRLIST) { if (nodes[x] ~ "^" DIRLIST[y]) { CHILD = 1 break } } if (CHILD) continue DIRLIST[++DIRCOUNT + 2] = nodes[x] } } } exit_val = close(pipe) if (exit_val != 0) print(exit_val " - " ERRNO) # We have no guarantee that ld.so.conf have more library paths than # the default, and its better scan files only in /lib and /usr/lib # than not at all ... # if (DIRCOUNT == 0) { # eerror("Could not read from /etc/ld.so.conf!") # exit 1 # } # Correct DIRCOUNT, as we already added /lib and /usr/lib DIRCOUNT += 2 # Add all the dirs in $PATH split(ENVIRON["PATH"], TMPPATHLIST, ":") count = asort(TMPPATHLIST, PATHLIST) for (x = 1;x <= count;x++) { ADDED = 0 for (dnode in DIRLIST) if (PATHLIST[x] == DIRLIST[dnode]) ADDED = 1 if (ADDED) continue if (((PATHLIST[x] != "") && (PATHLIST[x] != "/") && (PATHLIST[x] != "."))) DIRLIST[++DIRCOUNT] = PATHLIST[x] } GCCLIBPREFIX = "/usr/lib/gcc-lib/" for (x = 1;x <= DIRCOUNT;x++) { # Do nothing if the target dir is gcc's internal library path if (DIRLIST[x] ~ GCCLIBPREFIX) continue einfo("Scanning " ((x <= 9) ? "0"x : x)" of " DIRCOUNT " " DIRLIST[x] "...") pipe = ("find " DIRLIST[x] "/ -type f -perm -1 -maxdepth 90 2>/dev/null") while ( (pipe | getline scan_files) > 0) { # Do nothing if the file is located in gcc's internal lib path if (scan_files ~ GCCLIBPREFIX) continue if (scan_files ~ "/lib/libgcc-3" ) continue if (iself(scan_files)) continue scan_file_pipe = ("readelf -s " scan_files " 2>/dev/null") while ((scan_file_pipe | getline scan_data) > 0) { if (scan_data ~ /__guard@GCC/ || scan_data ~ /__guard@@GCC/) { # 194: 00000000 32 OBJECT GLOBAL DEFAULT UND __guard@GCC_3.0 (3) # 59: 00008ee0 32 OBJECT GLOBAL DEFAULT 22 __guard@@GCC_3.0 # how can we get the 8th index? ewarn("Found " scan_data " in " scan_files) if (auto_etcat) { # use etcat that comes with gentoolkit if auto_etcat is true. etcat_pipe = ("etcat belongs " scan_files) etcat_pipe | getline etcat_belongs while((etcat_pipe | getline etcat_belongs) > 0) eerror(etcat_belongs != "" ? "Please emerge '>=" etcat_belongs "'": "") close("etcat belongs " scan_files) } exit(1) } } close("readelf -s " scan_files " 2>/dev/null") } close("find " DIRLIST[x] "/ -type f -perm -1 -maxdepth 90 2>/dev/null") } exit(0) } # vim:ts=4