1: # Various (possible) problems of aarch64
2:
3: Here a list of possible problems of NetBSD/evbarm aarch64 that needs further
4: investigation in order to write proper PR or better yet to fix them!
5:
6:
7: ## `mpv` SIGSEGVs (strnlen(s, (size_t)-1) always returns -1)
8: Just by invoking `mpv` via:
9:
10: % mpv
11:
12: It SEGV as follows:
13:
14: % mpv
15: /usr/pkg/lib/ffmpeg4/libavcodec.so.58: text relocations
16: mpv 0.29.0 Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects
17: built on Sat Jul 28 21:02:57 CEST 2018
18: ffmpeg library versions:
19: libavutil 56.14.100
20: libavcodec 58.18.100
21: libavformat 58.12.100
22: libswscale 5.1.100
23: libavfilter 7.16.100
24: libswresample 3.1.100
25: ffmpeg version: 4.0.2
26:
27: Usage: mpv [options] [url|path/]filename
28:
29: Basic options:
30: --start=<time> seek to given (percent, seconds, or hh:mm:ss) position
31: --no-audio do not play sound
32: --no-video do not play video
33: --fs fullscreen playback
34: --sub-file=<file> specify subtitle file to use
35: --playlist=<file> specify playlist file
36:
37: --list-options list all mpv options
38: --h=<string> print options which contain the given string in their name
39:
40: [1] Segmentation fault (core dumped) /usr/pkg/bin/mpv...
41: % gdb -core mpv.core /usr/pkg/bin/mpv
42: Reading symbols from /usr/pkg/bin/mpv...done.
43: [New process 5]
44: [New process 6]
45: [New process 4]
46: [New process 3]
47: [New process 2]
48: [New process 1]
49: Core was generated by `mpv'.
50: Program terminated with signal SIGSEGV, Segmentation fault.
51: #0 0x0000f96f727f40b0 in memcpy () from /usr/lib/libc.so.12
52: [Current thread is 1 (process 5)]
53: (gdb) bt
54: #0 0x0000f96f727f40b0 in memcpy () from /usr/lib/libc.so.12
55: #1 0x00000002001cba34 in __memcpy_ichk (len=18446744073709551615, src=0xf96f6e10fec0, dst=<optimized out>)
56: at /usr/include/ssp/string.h:82
57: #2 strndup_append_at (str=str@entry=0xf96f6f4ff348, at=0, append=0xf96f6e10fec0 "speed", append_len=<optimized out>,
58: append_len@entry=18446744073709551615) at ../ta/ta_utils.c:113
59: #3 0x00000002001cbea4 in ta_strdup_append_buffer (str=str@entry=0xf96f6f4ff348, a=<optimized out>) at ../ta/ta_utils.c:165
60: #4 0x00000002001cb7b8 in ta_talloc_strdup_append_buffer (s=<optimized out>, s@entry=0x0, a=<optimized out>) at ../ta/ta_talloc.c:31
61: #5 0x0000000200157eec in print_str_list (opt=<optimized out>, src=<optimized out>) at ../options/m_option.c:1477
62: [...]
63:
64: This happens because `strnlen(s, (size_t)-1)`, always returns -1, e.g.:
65:
66: % cat strnlen_size_max.c
67: #include <stdio.h>
68: #include <string.h>
69:
70:
71: int
72: main(int argc, char *argv[])
73: {
74: int i;
75: for (i = 1; i < argc; i++) {
76: printf("strnlen(\"%s\", (size_t)-1) -> %ld\n",
77: argv[i], strnlen(argv[i], ~(size_t)0));
78: }
79:
80: return 0;
81: }
82: % gcc -Wall strnlen_size_max.c
83: % ./a.out foo
84: strnlen("foo", (size_t)-1) -> -1
85:
86: (This should returns 3, not -1!)
87:
88: The following patch workaround the mpv problem by avoiding all
89: `strnlen(s, (size_t)-1)` calls (and just using strlen() instead):
90:
91: $NetBSD: aarch64_problems.mdwn,v 1.11 2018/07/31 22:22:28 leot Exp $
92:
93: Avoid to directly call:
94:
95: strnlen(s, (size_t)-1)
96:
97: because on aarch64 ATM it (incorrectly) always returns -1 (also
98: when s is a string with less than SIZE_MAX characters).
99:
100: Add a kludge in order to use strlen() in these cases.
101:
102: --- ta/ta_utils.c.orig 2018-07-31 21:45:47.492269366 +0000
103: +++ ta/ta_utils.c
104: @@ -98,7 +98,11 @@ static bool strndup_append_at(char **str
105: if (!*str && !append)
106: return true; // stays NULL, but not an OOM condition
107:
108: - size_t real_len = append ? strnlen(append, append_len) : 0;
109: + size_t real_len = append ?
110: + append_len == (size_t)-1 ?
111: + strlen(append) :
112: + strnlen(append, append_len) :
113: + 0;
114: if (append_len > real_len)
115: append_len = real_len;
116:
117:
118: ## Python `import requests` SIGILLs
119: Doing a (please note that also `python36` is affected):
120:
121: $ python2.7 -c 'import requests'
122: Illegal instruction (core dumped)
123: Exit 132
124:
125: ...where:
126:
127: % gdb -core python2.7.core `which python2.7`
128: Reading symbols from /usr/pkg/bin/python2.7...(no debugging symbols found)...done.
129: [New process 1]
130: Core was generated by `python2.7'.
131: Program terminated with signal SIGILL, Illegal instruction.
132: #0 0x0000f42f5fd00000 in ?? ()
133: (gdb) bt 5
134: #0 0x0000f42f5fd00000 in ?? ()
135: #1 0x0000f42f5fd0a3d0 in restore_errno_only () at c/misc_thread_common.h:43
136: #2 0x0000f42f5fbf0f90 in _cffi_f_SSL_library_init (self=<optimized out>, noarg=<optimized out>)
137: at build/temp.netbsd-8.99.22-evbarm-2.7/_openssl.c:51839
138: #3 0x0000f42f617606ac in PyEval_EvalFrameEx () from /usr/pkg/lib/libpython2.7.so.1.0
139: #4 0x0000f42f6175e5c0 in PyEval_EvalCodeEx () from /usr/pkg/lib/libpython2.7.so.1.0
140: (More stack frames follow...)
141: (gdb) f 2
142: #2 0x0000f42f5fbf0f90 in _cffi_f_SSL_library_init (self=<optimized out>, noarg=<optimized out>)
143: at build/temp.netbsd-8.99.22-evbarm-2.7/_openssl.c:51839
144: warning: Source file is more recent than executable.
145: 51839 _cffi_restore_errno();
146: (gdb) list
147: 51834 _cffi_f_SSL_library_init(PyObject *self, PyObject *noarg)
148: 51835 {
149: 51836 int result;
150: 51837
151: 51838 Py_BEGIN_ALLOW_THREADS
152: 51839 _cffi_restore_errno();
153: 51840 { result = SSL_library_init(); }
154: 51841 _cffi_save_errno();
155: 51842 Py_END_ALLOW_THREADS
156: 51843
157: (gdb) f 1
158: #1 0x0000f42f5fd0a3d0 in restore_errno_only () at c/misc_thread_common.h:43
159: 43 static void restore_errno_only(void) { errno = cffi_saved_errno; }
160: (gdb) list
161: 38 syntactically valid to use "__thread" with this C compiler. */
162: 39 #ifdef USE__THREAD
163: 40
164: 41 static __thread int cffi_saved_errno = 0;
165: 42 static void save_errno_only(void) { cffi_saved_errno = errno; }
166: 43 static void restore_errno_only(void) { errno = cffi_saved_errno; }
167: 44
168: 45 #else
169: 46
170: 47 static void save_errno_only(void)
171: (gdb) disas
172: Dump of assembler code for function restore_errno_only:
173: 0x0000f42f5fd0a3b0 <+0>: str x30, [sp, #-16]!
174: 0x0000f42f5fd0a3b4 <+4>: bl 0xf42f5fd075c0 <__errno@plt>
175: 0x0000f42f5fd0a3b8 <+8>: mov x2, x0
176: 0x0000f42f5fd0a3bc <+12>: mrs x1, tpidr_el0
177: 0x0000f42f5fd0a3c0 <+16>: adrp x0, 0xf42f5fd34000
178: 0x0000f42f5fd0a3c4 <+20>: ldr x3, [x0, #4088]
179: 0x0000f42f5fd0a3c8 <+24>: add x0, x0, #0xff8
180: 0x0000f42f5fd0a3cc <+28>: blr x3
181: => 0x0000f42f5fd0a3d0 <+32>: ldr w0, [x1, x0]
182: 0x0000f42f5fd0a3d4 <+36>: str w0, [x2]
183: 0x0000f42f5fd0a3d8 <+40>: ldr x30, [sp], #16
184: 0x0000f42f5fd0a3dc <+44>: ret
185: End of assembler dump.
186: (gdb) info reg
187: x0 0xf42f5fd34ff8 268484308324344
188: x1 0xf42f61875080 268484336898176
189: x2 0xf42f6186c848 268484336863304
190: x3 0xf42f5fd00000 268484308107264
191: x4 0xf42f5ff3c0b8 268484310450360
192: x5 0xf42f60000570 268484311254384
193: x6 0x65000000000000 28428972647776256
194: x7 0x65 101
195: x8 0xf42f6185e000 268484336803840
196: x9 0xf42f6185e668 268484336805480
197: x10 0xf42f6185e668 268484336805480
198: x11 0x1 1
199: x12 0x30 48
200: x13 0xffffff9264f0 281474969527536
201: x14 0x65 101
202: x15 0x3 3
203: x16 0xf42f615bd730 268484334049072
204: x17 0xf42f615ec2c8 268484334240456
205: x18 0xf42f615ca1a0 268484334100896
206: x19 0xf42f5fc9cea8 268484307701416
207: x20 0xf42f5fd9c3c0 268484308747200
208: x21 0xf42f61307090 268484331204752
209: x22 0xf42f5fcd38e8 268484307925224
210: x23 0xf42f5fcd10a0 268484307914912
211: x24 0xf42f5fb8c5a8 268484306585000
212: x25 0xf42f5fd9c3c0 268484308747200
213: x26 0xf42f5fbf0f70 268484306997104
214: x27 0xf42f5fdd467e 268484308977278
215: x28 0xf42f61307090 268484331204752
216: x29 0x0 0
217: x30 0xf42f5fd0a3d0 268484308149200
218: sp 0xffffff926760 0xffffff926760
219: pc 0xf42f5fd0a3d0 0xf42f5fd0a3d0 <restore_errno_only+32>
220: cpsr 0x60000000 [ EL=0 C Z ]
221: fpsr 0x3000000 50331648
222: fpcr 0x10 16
223: (gdb) quit
224:
225: ...and `_cffi_restore_errno` and `_cffi_save_errno` are defined in
226: `cffi/_cffi_include.h` as follows:
227:
228: #define _cffi_restore_errno \
229: ((void(*)(void))_cffi_exports[13])
230: #define _cffi_save_errno \
231: ((void(*)(void))_cffi_exports[14])
232:
233: Since py-cffi-1.11.5nb1 a kludge to workaround the issue is present (by
234: disabling __thread).
235:
236:
237: ## polkitd crashes
238:
239: pinebook# /usr/pkg/lib/polkit-1/polkitd
240: Successfully changed to user polkitd
241: Error loading /var/run/ConsoleKit/database: Error statting file /var/run/ConsoleKit/database: No such file or directory[1] Segmentation fault /usr/pkg/lib/polkit-1/polkitd
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb