| @@ -1,122 +1,122 @@ | | | @@ -1,122 +1,122 @@ |
1 | # $NetBSD: check-shlibs-macho.awk,v 1.3 2016/08/20 18:52:42 adam Exp $ | | 1 | # $NetBSD: check-shlibs-macho.awk,v 1.4 2018/05/25 09:26:49 jperkin Exp $ |
2 | | | 2 | |
3 | # | | 3 | # |
4 | # Read a list of potential Mach-O binaries from stdin. | | 4 | # Read a list of potential Mach-O binaries from stdin. |
5 | # For each, check the list of required DSOs and ensure that each of them can | | 5 | # For each, check the list of required DSOs and ensure that each of them can |
6 | # be found correctly, and check that any pkgsrc-installed DSOs belong to a | | 6 | # be found correctly, and check that any pkgsrc-installed DSOs belong to a |
7 | # full dependency. | | 7 | # full dependency. |
8 | # | | 8 | # |
9 | | | 9 | |
10 | function shquote(IN, out) { | | 10 | function shquote(IN, out) { |
11 | out = IN; | | 11 | out = IN; |
12 | gsub("\\\\", "\\\\", out); | | 12 | gsub("\\\\", "\\\\", out); |
13 | gsub("\\\n", "\\n", out); | | 13 | gsub("\\\n", "\\n", out); |
14 | gsub("\\\t", "\\t", out); | | 14 | gsub("\\\t", "\\t", out); |
15 | gsub(" ", "\\ ", out); | | 15 | gsub(" ", "\\ ", out); |
16 | gsub("'", "\\'", out); | | 16 | gsub("'", "\\'", out); |
17 | gsub("`", "\\`", out); | | 17 | gsub("`", "\\`", out); |
18 | gsub("\"", "\\\"", out); | | 18 | gsub("\"", "\\\"", out); |
19 | gsub(";", "\\;", out); | | 19 | gsub(";", "\\;", out); |
20 | gsub("&", "\\&", out); | | 20 | gsub("&", "\\&", out); |
21 | gsub("<", "\\<", out); | | 21 | gsub("<", "\\<", out); |
22 | gsub(">", "\\>", out); | | 22 | gsub(">", "\\>", out); |
23 | gsub("\\(", "\\(", out); | | 23 | gsub("\\(", "\\(", out); |
24 | gsub("\\)", "\\)", out); | | 24 | gsub("\\)", "\\)", out); |
25 | gsub("\\|", "\\|", out); | | 25 | gsub("\\|", "\\|", out); |
26 | gsub("\\*", "\\*", out); | | 26 | gsub("\\*", "\\*", out); |
27 | gsub("\\?", "\\?", out); | | 27 | gsub("\\?", "\\?", out); |
28 | gsub("\\{", "\\{", out); | | 28 | gsub("\\{", "\\{", out); |
29 | gsub("\\}", "\\}", out); | | 29 | gsub("\\}", "\\}", out); |
30 | gsub("\\[", "\\[", out); | | 30 | gsub("\\[", "\\[", out); |
31 | gsub("\\]", "\\]", out); | | 31 | gsub("\\]", "\\]", out); |
32 | gsub("\\$", "\\$", out); | | 32 | gsub("\\$", "\\$", out); |
33 | gsub("!", "\\!", out); | | 33 | gsub("!", "\\!", out); |
34 | gsub("#", "\\#", out); | | 34 | gsub("#", "\\#", out); |
35 | gsub("\\^", "\\^", out); | | 35 | gsub("\\^", "\\^", out); |
36 | gsub("~", "\\~", out); | | 36 | gsub("~", "\\~", out); |
37 | return out; | | 37 | return out; |
38 | } | | 38 | } |
39 | | | 39 | |
40 | function check_pkg(DSO, pkg, found) { | | 40 | function check_pkg(DSO, pkg, found) { |
41 | if (destdir == "") | | 41 | if (destdir == "") |
42 | return 0 | | 42 | return 0 |
43 | if (DSO in pkgcache) { | | 43 | if (DSO in pkgcache) { |
44 | pkg = pkgcache[DSO] | | 44 | pkg = pkgcache[DSO] |
45 | } else { | | 45 | } else { |
46 | cmd = pkg_info_cmd " -Fe " shquote(DSO) " 2>/dev/null" | | 46 | cmd = pkg_info_cmd " -Fe " shquote(DSO) " 2>/dev/null" |
47 | if ((cmd | getline pkg) < 0) { | | 47 | if ((cmd | getline pkg) < 0) { |
48 | close(cmd) | | 48 | close(cmd) |
49 | return 0 | | 49 | return 0 |
50 | } | | 50 | } |
51 | close(cmd) | | 51 | close(cmd) |
52 | pkgcache[DSO] = pkg | | 52 | pkgcache[DSO] = pkg |
53 | } | | 53 | } |
54 | if (pkg == "") | | 54 | if (pkg == "") |
55 | return 0 | | 55 | return 0 |
56 | found=0 | | 56 | found=0 |
57 | while ((getline < depends_file) > 0) { | | 57 | while ((getline < depends_file) > 0) { |
58 | if ($3 == pkg) { | | 58 | if ($3 == pkg) { |
59 | found=1 | | 59 | found=1 |
60 | if ($1 != "full") | | 60 | if ($1 != "full") |
61 | continue | | 61 | continue |
62 | close(depends_file) | | 62 | close(depends_file) |
63 | return 0 | | 63 | return 0 |
64 | } | | 64 | } |
65 | } | | 65 | } |
66 | if (found) | | 66 | if (found) |
67 | print DSO ": " pkg " is not a runtime dependency" | | 67 | print DSO ": " pkg " is not a runtime dependency" |
68 | close(depends_file) | | 68 | close(depends_file) |
69 | } | | 69 | } |
70 | | | 70 | |
71 | function checkshlib(DSO, needed, found) { | | 71 | function checkshlib(DSO, needed, found) { |
72 | cmd = "otool -XL " shquote(DSO) " 2>/dev/null" | | 72 | cmd = "otool -XL " shquote(DSO) " 2>/dev/null" |
73 | while ((cmd | getline) > 0) { | | 73 | while ((cmd | getline) > 0) { |
74 | needed[$1] = "" | | 74 | needed[$1] = "" |
75 | } | | 75 | } |
76 | close(cmd) | | 76 | close(cmd) |
77 | ndirs = split(cross_destdir ":" destdir, check_dirs, ":") | | 77 | ndirs = split(cross_destdir ":" destdir, check_dirs, ":") |
78 | for (lib in needed) { | | 78 | for (lib in needed) { |
79 | # | | 79 | # |
80 | # Ensure we don't have any WRKDIR references. | | 80 | # Ensure we don't have any WRKDIR references. |
81 | # | | 81 | # |
82 | if (lib == wrkdir || | | 82 | if (lib == wrkdir || |
83 | substr(lib, 1, length(wrkdir) + 1) == wrkdir "/") | | 83 | substr(lib, 1, length(wrkdir) + 1) == wrkdir "/") |
84 | print DSO ": path relative to WRKDIR: " lib | | 84 | print DSO ": path relative to WRKDIR: " lib |
85 | | | 85 | |
86 | # | | 86 | # |
87 | # Ensure there are no relative paths. | | 87 | # Ensure there are no relative paths. |
88 | # | | 88 | # |
89 | if (substr(lib, 1, 1) != "/") | | 89 | if (substr(lib, 1, 1) != "/") |
90 | print DSO ": relative library path: " lib | | 90 | print DSO ": relative library path: " lib |
91 | | | 91 | |
92 | # | | 92 | # |
93 | # Check destination dirs for library existence. If found in a | | 93 | # Check destination dirs for library existence. If found in a |
94 | # system path (cross_destdir is somewhat confusing but if set | | 94 | # system path (cross_destdir is somewhat confusing but if set |
95 | # it points to the populated cross destdir, otherwise we are | | 95 | # it points to the populated cross destdir, otherwise we are |
96 | # checking '/') then check_pkg() ensures it is a runtime dep. | | 96 | # checking '/') then check_pkg() ensures it is a runtime dep. |
97 | # | | 97 | # |
98 | for (i = 1; i <= ndirs; i++) { | | 98 | for (i = 1; i <= ndirs; i++) { |
99 | libfile = check_dirs[i] lib | | 99 | libfile = check_dirs[i] lib |
100 | if (!(libfile in libcache)) | | 100 | if (!(libfile in libcache)) |
101 | libcache[libfile] = system("test -f " \ | | 101 | libcache[libfile] = system("test -f " \ |
102 | shquote(libfile)) | | 102 | shquote(libfile)) |
103 | if (libcache[libfile] == 0) { | | 103 | if (libcache[libfile] == 0) { |
104 | check_pkg(lib) | | 104 | check_pkg(lib) |
105 | found = 1 | | 105 | found = 1 |
106 | break | | 106 | break |
107 | } | | 107 | } |
108 | } | | 108 | } |
109 | if (found == 0) | | 109 | if (found == 0) |
110 | print DSO ": missing library: " lib | | 110 | print DSO ": missing library: " lib |
111 | } | | 111 | } |
112 | } | | 112 | } |
113 | | | 113 | |
114 | BEGIN { | | 114 | BEGIN { |
115 | cross_destdir = ENVIRON["CROSS_DESTDIR"] | | 115 | cross_destdir = ENVIRON["CROSS_DESTDIR"] |
116 | destdir = ENVIRON["DESTDIR"] | | 116 | destdir = ENVIRON["DESTDIR"] |
117 | wrkdir = ENVIRON["WRKDIR"] | | 117 | wrkdir = ENVIRON["WRKDIR"] |
118 | pkg_info_cmd = ENVIRON["PKG_INFO_CMD"] | | 118 | pkg_info_cmd = ENVIRON["PKG_INFO_CMD"] |
119 | depends_file = ENVIRON["DEPENDS_FILE"] | | 119 | depends_file = ENVIRON["DEPENDS_FILE"] |
120 | } | | 120 | } |
121 | | | 121 | |
122 | /\t/ { checkshlib($0); } | | 122 | { checkshlib($0); } |