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>.
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
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
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
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
) {
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
);
71 function check_pkg
(DSO
, pkg
, found
) {
74 cmd = pkg_info_cmd
" -Fe " shquote
(DSO
) " 2> /dev/null"
75 if ((cmd
| getline pkg
) < 0) {
83 while ((getline < depends_file
) > 0) {
93 print DSO
": " pkg
" is not a runtime dependency"
95 # print DSO ": " pkg " is not a dependency"
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
, ":")
108 split(dso_rpath
, rpath
, ":")
111 if ($
2 ==
"(NEEDED)") {
112 sub("^[[:space:]]*0[xX][[:xdigit:]]+[[:space:]]+\\(NEEDED\\)[[:space:]]+Shared library: \\[", "")
113 needed
[substr($
0, 1, length($
0) - 1)] =
""
117 split(system_rpath
, 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
) {
127 if (!
system("test -f " shquote
(cross_destdir rpath
[p
] "/" lib
))) {
128 check_pkg
(rpath
[p
] "/" lib
)
132 if (!
system("test -f " shquote
(destdir rpath
[p
] "/" lib
))) {
138 print DSO
": missing library: " lib
;
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"]