1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # Author: Martin Schlemmer <azarah@gentoo.org>
4 # Contributor: Ned Ludd <solar@gentoo.org>
5 # Contributor: Natanael Copa <nat@c2i.net>
6 # Contributor: Carter Smithhart <derheld42@derheld.net>
7 # $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc/files/awk/scanforssp.awk,v 1.7 2004/07/15 00:59:02 agriffis Exp $
10 # Does not seem to be used in this script.
11 function printn(string)
16 function einfo(string)
18 printf(" %s %s%s", "\033[32;01m*\033[0m", string, "\n")
21 # Does not seem to be used in this script.
22 function einfon(string)
24 printf(" %s %s" , "\033[32;01m*\033[0m", string)
27 function ewarn(string)
29 printf(" %s %s%s" , "\033[33;01m*\033[0m", string, "\n")
32 # Does not seem to be used in this script.
33 function ewarnn(string)
35 printf("%s %s" , "\032[33;01m*\033[0m", string)
38 function eerror(string)
40 printf(" %s %s%s" , "\033[31;01m*\033[0m", string, "\n")
43 # These are private, else wierd things
45 function iself(scan_files, scan_file_pipe, scan_data) {
46 # Can we open() a file and read() 4 bytes?
47 scan_file_pipe = ("head -c 4 " scan_files " 2>/dev/null | tail -c 3")
48 scan_file_pipe | getline scan_data
50 return ((scan_data == "ELF") ? 0 : 1)
55 pipe = ("which etcat 2>/dev/null")
56 if ((((pipe) | getline etcat_data) > 0) && (etcat_data != ""))
61 # Fix bug that causes script to fail when pipe is not closed. Closes bug #36792
65 # Add the two default library paths
67 DIRLIST[2] = "/usr/lib"
69 # Walk /etc/ld.so.conf line for line and get any library paths
70 pipe = ("cat /etc/ld.so.conf 2>/dev/null | sort")
71 while(((pipe) | getline ldsoconf_data) > 0) {
73 if (ldsoconf_data !~ /^[[:space:]]*#/) {
75 if (ldsoconf_data == "") continue
77 # Remove any trailing comments
78 sub(/#.*$/, "", ldsoconf_data)
79 # Remove any trailing spaces
80 sub(/[[:space:]]+$/, "", ldsoconf_data)
82 split(ldsoconf_data, nodes, /[:,[:space:]]/)
84 # Now add the rest from ld.so.conf
87 sub(/=.*/, "", nodes[x])
88 sub(/\/$/, "", nodes[x])
90 if (nodes[x] == "") continue
94 # Drop the directory if its a child directory of
95 # one that was already added ...
98 if (nodes[x] ~ "^" DIRLIST[y]) {
107 DIRLIST[++DIRCOUNT + 2] = nodes[x]
112 # We have no guarantee that ld.so.conf have more library paths than
113 # the default, and its better scan files only in /lib and /usr/lib
114 # than nothing at all ...
116 # exit_val = close(pipe)
118 # print(exit_val " - " ERRNO)
120 # if (DIRCOUNT == 0) {
121 # eerror("Could not read from /etc/ld.so.conf!")
125 # Correct DIRCOUNT, as we already added /lib and /usr/lib
128 # Add all the dirs in $PATH
129 split(ENVIRON["PATH"], TMPPATHLIST, ":")
130 count = asort(TMPPATHLIST, PATHLIST)
131 for (x = 1;x <= count;x++) {
136 for (dnode in DIRLIST)
137 if (PATHLIST[x] == DIRLIST[dnode])
143 # Valid? If so, add it ...
144 if (((PATHLIST[x] != "") && (PATHLIST[x] != "/") && (PATHLIST[x] != ".")))
145 DIRLIST[++DIRCOUNT] = PATHLIST[x]
149 GCCLIBPREFIX = "/usr/lib/gcc-lib/"
151 for (x = 1;x <= DIRCOUNT;x++) {
153 # Do nothing if the target dir is gcc's internal library path
154 if (DIRLIST[x] ~ GCCLIBPREFIX) continue
156 einfo(" Scanning " ((x <= 9) ? "0"x : x)" of " DIRCOUNT " " DIRLIST[x] "...")
158 pipe = ("find " DIRLIST[x] "/ -type f -perm -1 2>/dev/null")
159 while ( (pipe | getline scan_files) > 0) {
162 # Do nothing if the file is located in gcc's internal lib path ...
163 if (scan_files ~ GCCLIBPREFIX) continue
164 # Or if its hardend files ...
165 if (scan_files ~ "/lib/libgcc-3" ) continue
166 # Or not a elf image ...
167 if (iself(scan_files)) continue
169 scan_file_pipe = ("readelf -s " scan_files " 2>&1")
170 while (((scan_file_pipe) | getline scan_data) > 0) {
172 if (scan_data ~ /__guard@GCC/ || scan_data ~ /__guard@@GCC/) {
176 # 194: 00000000 32 OBJECT GLOBAL DEFAULT UND __guard@GCC_3.0 (3)
177 # 59: 00008ee0 32 OBJECT GLOBAL DEFAULT 22 __guard@@GCC_3.0
178 split(scan_data, scan_data_nodes)
179 ewarn("Found " scan_data_nodes[8] " in " scan_files "!")
182 if (scan_data ~ /readelf: Error: Unable to seek/) {
185 ewarn("Error executing readelf. Bad block? Filesystem error? in " scan_files)
193 # Use etcat that comes with gentoolkit if auto_etcat is true.
194 etcat_pipe = ("etcat belongs " scan_files)
195 (etcat_pipe) | getline etcat_belongs
197 while(((etcat_pipe) | getline etcat_belongs) > 0)
198 eerror(etcat_belongs != "" ? "Please emerge '>=" etcat_belongs "'": "")
202 eerror("You need to remerge package that above file belongs to!")
203 eerror("To find out what package it is, please emerge gentoolkit,")
204 eerror("and then run:")
206 print " # etcat belongs " scan_files
211 close(scan_file_pipe)
216 close(scan_file_pipe)