Bug 260913 - databases/tiledb: SIGILL, Illegal instruction.
Summary: databases/tiledb: SIGILL, Illegal instruction.
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Po-Chuan Hsieh
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-03 21:41 UTC by jau
Modified: 2023-10-16 16:31 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (sunpoet)


Attachments
avx2_knob_Makefile.diff (925 bytes, patch)
2023-05-04 02:24 UTC, alt2600
no flags Details | Diff
git-tiledb-avx2_knob_Makefile_rev1.diff (562 bytes, patch)
2023-10-01 00:52 UTC, alt2600
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jau 2022-01-03 21:41:14 UTC
While trying to run Mapper (openorienteering-mapper) I found this...

(gdb) run
Starting program: /usr/local/bin/Mapper 

Program received signal SIGILL, Illegal instruction.
Privileged opcode.
0x00000008049faee4 in ?? () from /usr/local/lib/libtiledb.so
(gdb) bt
#0  0x00000008049faee4 in ?? () from /usr/local/lib/libtiledb.so
#1  0x000000080061f71d in objlist_call_init (list=<optimized out>, 
    list@entry=0x7fffffffe878, lockstate=<optimized out>, 
    lockstate@entry=0x7fffffffe6f8)
    at /usr/src-12-stable/libexec/rtld-elf/rtld.c:2827
#2  0x000000080061e0ad in _rtld (sp=<optimized out>, exit_proc=0x7fffffffe900, 
    objp=0x7fffffffe908) at /usr/src-12-stable/libexec/rtld-elf/rtld.c:811
#3  0x000000080061ba39 in rtld_start ()
    at /usr/src-12-stable/libexec/rtld-elf/amd64/rtld_start.S:39
#4  0x0000000000000000 in ?? ()
(gdb) q
A debugging session is active.

	Inferior 1 [process 48623] will be killed.

Quit anyway? (y or n) y
Comment 1 Daniel Engberg freebsd_committer freebsd_triage 2022-01-04 01:43:20 UTC
Having a quick look it seems like tiledb incorrectly always enables AVX2 instructions.

...
-- Performing Test HAVE_AVX2 - Success

/usr/bin/c++ ... -DNDEBUG -O3 -mavx2 ...
Comment 2 Daniel Engberg freebsd_committer freebsd_triage 2022-01-04 02:16:06 UTC
Put this in ./files (/usr/ports/databases/tiledb/files) and recompile, does it fix the issue?
https://projects.pyret.net/files/public/freebsd/patch-CMakeLists.txt
Comment 3 jau 2022-01-04 12:27:17 UTC
(In reply to Daniel Engberg from comment #2)

Uh-er... Now the build ends with this...

FAILED: tiledb/CMakeFiles/TILEDB_CORE_OBJECTS.dir/__/external/src/blosc/shuffle.cc.o 
/usr/bin/c++ -DFMT_SHARED -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -DSPDLOG_FMT_EXTERNAL=1 -DSPDLOG_SHARED_LIB -DTILEDB_CORE_OBJECTS_EXPORTS -DTILEDB_SERIALIZATION -DTILEDB_STATS -D_FILE_OFFSET_BITS=64 -I/usr/ports/databases/tiledb/work/TileDB-2.5.2/tiledb/.. -I/usr/ports/databases/tiledb/work/TileDB-2.5.2/tiledb/../tiledb/sm/c_api -I/usr/ports/databases/tiledb/work/TileDB-2.5.2/tiledb/../external/include -I/usr/ports/databases/tiledb/work/TileDB-2.5.2/tiledb/../external/include/bitshuffle -I/usr/ports/databases/tiledb/work/TileDB-2.5.2/tiledb/../external/include/blosc -I/usr/ports/databases/tiledb/work/.build/tiledb/.. -I/usr/ports/databases/tiledb/work/TileDB-2.5.2/tiledb/../tiledb/sm/cpp_api -I/usr/ports/databases/tiledb/work/.build/tiledb -O3 -pipe -DSPDLOG_FMT_EXTERNAL=1 -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -isystem /usr/local/include -O3 -pipe -DSPDLOG_FMT_EXTERNAL=1 -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -isystem /usr/local/include -fPIC -fvisibility=hidden -Wall -Wextra -DNDEBUG -O3 -std=c++17 -MD -MT tiledb/CMakeFiles/TILEDB_CORE_OBJECTS.dir/__/external/src/blosc/shuffle.cc.o -MF tiledb/CMakeFiles/TILEDB_CORE_OBJECTS.dir/__/external/src/blosc/shuffle.cc.o.d -o tiledb/CMakeFiles/TILEDB_CORE_OBJECTS.dir/__/external/src/blosc/shuffle.cc.o -c /usr/ports/databases/tiledb/work/TileDB-2.5.2/external/src/blosc/shuffle.cc
/usr/ports/databases/tiledb/work/TileDB-2.5.2/external/src/blosc/shuffle.cc:238:21: error: use of undeclared identifier '_xgetbv'
    xcr0_contents = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
                    ^
1 error generated.
ninja: build stopped: subcommand failed.
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make: stopped in /usr/ports/databases/tiledb
(sleipnir:pts/1) 14:24:07 databases/tiledb# man xgetbv
No manual entry for xgetbv
Comment 4 Daniel Engberg freebsd_committer freebsd_triage 2022-01-05 10:43:52 UTC
...and replace the current version of (in files) with this one:

https://projects.pyret.net/files/public/freebsd/patch-external-src-blosc-shuffle.cc

Disclaimer, I have no idea if this is correct way or solving it and/or if it will do something unintentional but it now at least compiles without avx2 being set.
Comment 5 alt2600 2023-05-04 01:46:16 UTC
(In reply to Daniel Engberg from comment #4)


See PR 271217 Just stumbled into this one itself, was going to look at making an AVX knob cmake can turn those complicated sometimes. seeing if I can patch just our Makefile to fix this.

$ lldb gdal_translate
(lldb) target create "gdal_translate"
Current executable set to 'gdal_translate' (x86_64).
(lldb) r
Process 74458 launched: '/usr/local/bin/gdal_translate' (x86_64)
Process 74458 stopped
* thread #1, name = 'gdal_translate', stop reason = signal SIGILL: privileged instruction
    frame #0: 0x000000083ccb60c4 libtiledb.so`___lldb_unnamed_symbol1342 + 4
libtiledb.so`___lldb_unnamed_symbol1342:
->  0x83ccb60c4 <+4>:  vxorps %xmm0, %xmm0, %xmm0
    0x83ccb60c8 <+8>:  vmovups %ymm0, 0x877528(%rip)
    0x83ccb60d0 <+16>: movq   $0x0, 0x87753d(%rip)
    0x83ccb60db <+27>: leaq   0x877516(%rip), %rsi
(lldb) q

was just about to enter a bug when I noticed this one so I concur its still going on, or just came back maybe with 2.15.2
Comment 6 alt2600 2023-05-04 02:24:38 UTC
Created attachment 241961 [details]
avx2_knob_Makefile.diff

Adds knob to enable or disable AVX2 use by cmake. didn't make default, I'll let maintainer make that call if they accept this patch. I have locked it out on my end in portconf either way.

no more illegal instructions with tiledb use on westmere amd64 13.2
Comment 7 alt2600 2023-10-01 00:52:43 UTC
Created attachment 245345 [details]
git-tiledb-avx2_knob_Makefile_rev1.diff

update patch for 2.17.1 port update. enables turning off AVX being forced on by cmake due solely to compiler support without checking machine support
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-10-16 16:30:22 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=3c4e074f49230172dc8d458a4cd155def9eb4494

commit 3c4e074f49230172dc8d458a4cd155def9eb4494
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2023-10-16 16:29:17 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2023-10-16 16:30:07 +0000

    databases/tiledb: Add AVX2 option

    - Fix SIGILL for machines without AVX2 support

    PR:             260913
    Reported by:    <jau@iki.fi>
    Submitted by:   <alt2600@icloud.com>

 databases/tiledb/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 9 Po-Chuan Hsieh freebsd_committer freebsd_triage 2023-10-16 16:31:01 UTC
Committed. Thanks!