dxma / perl5-json-jq

JSON::JQ - jq (https://stedolan.github.io/jq/) library binding
MIT License
5 stars 4 forks source link

Missing `assert_isa` symbol #9

Closed rjbell4 closed 3 years ago

rjbell4 commented 3 years ago

When I try to compile and run in an Alpine Linux Docker image, I get the following error:

Can't load '/usr/src/app/local/lib/perl5/x86_64-linux-thread-multi/auto/JSON/JQ/JQ.so' for module JSON::JQ: Error relocating /usr/src/app/local/lib/perl5/x86_64-linux-thread-multi/auto/JSON/JQ/JQ.so: assert_isa: symbol not found at /usr/share/perl5/core_perl/XSLoader.pm line 93.
 at /usr/src/app/local/lib/perl5/x86_64-linux-thread-multi/JSON/JQ.pm line 23.
Compilation failed in require.
BEGIN failed--compilation aborted.

I've searched, but I cannot find where assert_isa should be defined. It's not in libperl.so:

# LD_PRELOAD=/usr/lib/perl5/core_perl/CORE/libperl.so ldd /usr/src/app/local/lib/perl5/x86_64-linux-thread-multi/auto/JSON/JQ/JQ.so
        /lib/ld-musl-x86_64.so.1 (0x7fe36870b000)
        /usr/lib/perl5/core_perl/CORE/libperl.so => /usr/lib/perl5/core_perl/CORE/libperl.so (0x7fe368310000)
        libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fe36870b000)
Error relocating /usr/src/app/local/lib/perl5/x86_64-linux-thread-multi/auto/JSON/JQ/JQ.so: assert_isa: symbol not found

And some Googling hasn't been helpful. I'm hoping you will be!

dxma commented 3 years ago

Hi, it is defined within the code https://github.com/dxma/perl5-json-jq/blob/master/lib/JSON/JQ.xs#L191 Kind of strange it compiled but raised this runtime error. Could you recompile it and show me the full output ?

rjbell4 commented 3 years ago

My exact environment is a little more complicated, so to try to make in simpler for you to reproduce, I boiled it down to this Dockerfile (so far), which reproduces the issue:

FROM alpine:3.13
RUN apk add bash wget unzip perl perl-dev perl-app-cpanminus build-base cmake openssl openssl-dev zlib-dev
RUN env PERL_MM_USE_DEFAULT=1 cpanm Carton
RUN cd /root && echo "requires 'JSON::JQ';" > cpanfile && carton install
RUN perl -I/root/local/lib/perl5 -MJSON::JQ -le 'print "It works"'

This isn't exactly my setup, but if you could see what's wrong with the above Dockerfile (put into an empty directory, run docker build ., look for an It works output, etc.), then I would be grateful, and would take it from there.

rjbell4 commented 3 years ago

FYI, I also tried using cpanm, rather than carton. Here's the build log in that case: https://gist.github.com/c7b2e6ddc58c933649af63ad5db6f54e

The output to screen ended as follow:

Building and testing JSON-JQ-0.05
Building JSON-JQ
cc -I. -I/usr/lib/perl5/core_perl/CORE -DVERSION="0.05" -DXS_VERSION="0.05" -fPIC -I/usr/local/lib/perl5/site_perl/auto/share/dist/Alien-LibJQ/include -c -D_REENTRANT -D_GNU_SOURCE -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Os -fomit-frame-pointer -o lib/JSON/JQ.o lib/JSON/JQ.c
ExtUtils::Mkbootstrap::Mkbootstrap('blib/arch/auto/JSON/JQ/JQ.bs')
cc -L/usr/local/lib/perl5/site_perl/auto/share/dist/Alien-LibJQ/lib -shared -Os -fomit-frame-pointer -L/usr/local/lib -fstack-protector-strong -o blib/arch/auto/JSON/JQ/JQ.so lib/JSON/JQ.o -ljq -lonig -lm

#   Failed test 'use JSON::JQ;'
#   at t/001_load.t line 9.
#     Tried to use 'JSON::JQ'.
#     Error:  Can't load '/root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/arch/auto/JSON/JQ/JQ.so' for module JSON::JQ: Error relocating /root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/arch/auto/JSON/JQ/JQ.so: assert_isa: symbol not found at /usr/lib/perl5/core_perl/DynaLoader.pm line 193.
#  at t/001_load.t line 9.
# Compilation failed in require at t/001_load.t line 9.
# BEGIN failed--compilation aborted at t/001_load.t line 9.

#   Failed test 'JSON::JQ->can(...)'
#   at t/001_load.t line 10.
#     JSON::JQ->can('JV_PRINT_INDENT_FLAGS') failed
#     JSON::JQ->can('_init') failed
#     JSON::JQ->can('_process') failed
#     JSON::JQ->can('DESTROY') failed
Undefined subroutine &JSON::JQ::JV_PRINT_INDENT_FLAGS called at /root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/lib/JSON/JQ.pm line 43.
# Looks like your test exited with 255 just after 2.
t/001_load.t ...........
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 6/6 subtests
Can't load '/root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/arch/auto/JSON/JQ/JQ.so' for module JSON::JQ: Error relocating /root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/arch/auto/JSON/JQ/JQ.so: assert_isa: symbol not found at /usr/lib/perl5/core_perl/DynaLoader.pm line 193.
 at t/002_basis.t line 7.
Compilation failed in require at t/002_basis.t line 7.
BEGIN failed--compilation aborted at t/002_basis.t line 7.
# Looks like your test exited with 2 before it could output anything.
t/002_basis.t ..........
Dubious, test returned 2 (wstat 512, 0x200)
Failed 14/14 subtests
Can't load '/root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/arch/auto/JSON/JQ/JQ.so' for module JSON::JQ: Error relocating /root/.cpanm/work/1621022484.6/JSON-JQ-0.05/blib/arch/auto/JSON/JQ/JQ.so: assert_isa: symbol not found at /usr/lib/perl5/core_perl/DynaLoader.pm line 193.
 at t/003_basic_filters.t line 7.
Compilation failed in require at t/003_basic_filters.t line 7.
BEGIN failed--compilation aborted at t/003_basic_filters.t line 7.
# Looks like your test exited with 2 before it could output anything.
t/003_basic_filters.t ..
Dubious, test returned 2 (wstat 512, 0x200)
Failed 27/27 subtests

Test Summary Report
-------------------
t/001_load.t         (Wstat: 65280 Tests: 2 Failed: 2)
  Failed tests:  1-2
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 6 tests but ran 2.
t/002_basis.t        (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: Bad plan.  You planned 14 tests but ran 0.
t/003_basic_filters.t (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: Bad plan.  You planned 27 tests but ran 0.
Files=3, Tests=2,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.37 cusr  0.07 csys =  0.48 CPU)
Result: FAIL
Failed 3/3 test programs. 2/2 subtests failed.
-> FAIL Installing JSON::JQ failed. See /root/.cpanm/work/1621022484.6/build.log for details. Retry with --force to force install it.
25 distributions installed
rjbell4 commented 3 years ago

I looked at the code. I noticed that assert_isa() is declared as inline, but not static, like all the other functions around it. I have verified that if I add static (either in place of inline or in addition to it), then JQ.so loads successfully.