Annotation of wikisrc/users/leot/aarch64_problems.mdwn, revision 1.12

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