Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / check / check-shlibs-elf.awk
blob750803c8c53c4860dcbcde789a7f38ec7bec203a
1 # $NetBSD: check-shlibs-elf.awk,v 1.4 2012/06/15 14:46:53 obache Exp $
3 # Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
4 # All rights reserved.
6 # This code was developed as part of Google's Summer of Code 2007 program.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in
16 # the documentation and/or other materials provided with the
17 # distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 # INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
33 # Read a list of potential ELF binaries from stdin.
34 # For each, extract the DT_RPATH and DT_NEEDED fields.
35 # Check that DT_RPATH is not relative to WRKDIR.
36 # Check that DT_NEEDED can be resolved either via DT_RPATH
37 # or a system specific default path.
38 # Check that the resolved DSO belongs to full dependency.
41 function shquote(IN, out) {
42 out = IN;
43 gsub("\\\\", "\\\\", out);
44 gsub("\\\n", "\\n", out);
45 gsub("\\\t", "\\t", out);
46 gsub(" ", "\\ ", out);
47 gsub("'", "\\'", out);
48 gsub("`", "\\`", out);
49 gsub("\"", "\\\"", out);
50 gsub(";", "\\;", out);
51 gsub("&", "\\&", out);
52 gsub("<", "\\<", out);
53 gsub(">", "\\>", out);
54 gsub("\\(", "\\(", out);
55 gsub("\\)", "\\)", out);
56 gsub("\\|", "\\|", out);
57 gsub("\\*", "\\*", out);
58 gsub("\\?", "\\?", out);
59 gsub("\\{", "\\{", out);
60 gsub("\\}", "\\}", out);
61 gsub("\\[", "\\[", out);
62 gsub("\\]", "\\]", out);
63 gsub("\\$", "\\$", out);
64 gsub("!", "\\!", out);
65 gsub("#", "\\#", out);
66 gsub("\\^", "\\^", out);
67 gsub("~", "\\~", out);
68 return out;
71 function check_pkg(DSO, pkg, found) {
72 if (destdir == "")
73 return 0
74 cmd = pkg_info_cmd " -Fe " shquote(DSO) " 2> /dev/null"
75 if ((cmd | getline pkg) < 0) {
76 close(cmd)
77 return 0
79 close(cmd)
80 if (pkg == "")
81 return 0
82 found=0
83 while ((getline < depends_file) > 0) {
84 if ($3 == pkg) {
85 found=1
86 if ($1 != "full")
87 continue
88 close(depends_file)
89 return 0
92 if (found)
93 print DSO ": " pkg " is not a runtime dependency"
94 # Not yet:
95 # print DSO ": " pkg " is not a dependency"
96 close(depends_file)
99 function checkshlib(DSO, needed, rpath, found, dso_rath, got_rpath) {
100 cmd = readelf " -Wd " shquote(DSO) " 2> /dev/null"
101 while ((cmd | getline) > 0) {
102 if ($2 == "(RPATH)") {
103 sub("^[[:space:]]*0[xX][[:xdigit:]]+[[:space:]]+\\(RPATH\\)[[:space:]]+Library rpath: \\[", "")
104 dso_rpath = substr($0, 1, length($0) - 1)
105 if (length(system_rpath) > 0)
106 split(dso_rpath ":" system_rpath, rpath, ":")
107 else
108 split(dso_rpath, rpath, ":")
109 got_rpath = 1
111 if ($2 == "(NEEDED)") {
112 sub("^[[:space:]]*0[xX][[:xdigit:]]+[[:space:]]+\\(NEEDED\\)[[:space:]]+Shared library: \\[", "")
113 needed[substr($0, 1, length($0) - 1)] = ""
116 if (!got_rpath)
117 split(system_rpath, rpath, ":")
118 close(cmd)
119 for (p in rpath) {
120 if (rpath[p] == wrkdir ||
121 substr(rpath[p], 1, length(wrkdir) + 1) == wrkdir "/") {
122 print DSO ": rpath relative to WRKDIR"
125 for (lib in needed) {
126 for (p in rpath) {
127 if (!system("test -f " shquote(cross_destdir rpath[p] "/" lib))) {
128 check_pkg(rpath[p] "/" lib)
129 found = 1
130 break
132 if (!system("test -f " shquote(destdir rpath[p] "/" lib))) {
133 found = 1
134 break
137 if (found == 0)
138 print DSO ": missing library: " lib;
140 delete rpath
141 delete needed
144 BEGIN {
145 system_rpath = ENVIRON["PLATFORM_RPATH"]
146 cross_destdir = ENVIRON["CROSS_DESTDIR"]
147 destdir = ENVIRON["DESTDIR"]
148 readelf = ENVIRON["PLATFORM_READELF"]
149 wrkdir = ENVIRON["WRKDIR"]
150 pkg_info_cmd = ENVIRON["PKG_INFO_CMD"]
151 depends_file = ENVIRON["DEPENDS_FILE"]
152 if (readelf == "")
153 readelf = "readelf"
156 { checkshlib($0); }