new gcc snapshot
[dottout.git] / net-im / emesene / files / sys-devel / gcc / files / awk / scanforssp.awk
blobe8a1fe8fc82aadb277d6a3660f8f1d409be8dc74
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)
13 printf("%s", 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
44 # might happen ...
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
49 close(scan_file_pipe)
50 return ((scan_data == "ELF") ? 0 : 1)
53 BEGIN {
54 # Do we have etcat ?
55 pipe = ("which etcat 2>/dev/null")
56 if ((((pipe) | getline etcat_data) > 0) && (etcat_data != ""))
57 auto_etcat = 1
58 else
59 auto_etcat = 0
61 # Fix bug that causes script to fail when pipe is not closed. Closes bug #36792
62 close(pipe)
64 DIRCOUNT = 0
65 # Add the two default library paths
66 DIRLIST[1] = "/lib"
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
85 for (x in nodes) {
87 sub(/=.*/, "", nodes[x])
88 sub(/\/$/, "", nodes[x])
90 if (nodes[x] == "") continue
92 CHILD = 0
94 # Drop the directory if its a child directory of
95 # one that was already added ...
96 for (y in DIRLIST) {
98 if (nodes[x] ~ "^" DIRLIST[y]) {
100 CHILD = 1
101 break
105 if (CHILD) continue
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)
117 # if (exit_val != 0)
118 # print(exit_val " - " ERRNO)
120 # if (DIRCOUNT == 0) {
121 # eerror("Could not read from /etc/ld.so.conf!")
122 # exit 1
125 # Correct DIRCOUNT, as we already added /lib and /usr/lib
126 DIRCOUNT += 2
128 # Add all the dirs in $PATH
129 split(ENVIRON["PATH"], TMPPATHLIST, ":")
130 count = asort(TMPPATHLIST, PATHLIST)
131 for (x = 1;x <= count;x++) {
133 ADDED = 0
135 # Already added?
136 for (dnode in DIRLIST)
137 if (PATHLIST[x] == DIRLIST[dnode])
138 ADDED = 1
140 if (ADDED)
141 continue
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) {
161 #print scan_files
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) {
171 bad = 0;
172 if (scan_data ~ /__guard@GCC/ || scan_data ~ /__guard@@GCC/) {
173 bad = 1;
174 print
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 "!")
180 print
182 if (scan_data ~ /readelf: Error: Unable to seek/) {
183 bad = 1;
184 print
185 ewarn("Error executing readelf. Bad block? Filesystem error? in " scan_files)
186 print
189 if (bad) {
191 if (auto_etcat) {
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 "'": "")
199 close(etcat_pipe)
200 } else {
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:")
205 print
206 print " # etcat belongs " scan_files
209 print
211 close(scan_file_pipe)
212 close(pipe)
213 exit(1)
216 close(scan_file_pipe)
218 close(pipe)
221 exit(0)
225 # vim:ts=4