Skip to content

Instantly share code, notes, and snippets.

@goertzenator
Created October 31, 2014 20:19
Show Gist options
  • Save goertzenator/6237e0200a5f7bf22976 to your computer and use it in GitHub Desktop.
Save goertzenator/6237e0200a5f7bf22976 to your computer and use it in GitHub Desktop.
dirty nif build and segfault
goertzen-G550JK dlibusb # make V=1
erl -noshell -noinput -eval "file:write_file(\"env.mk\", \
io_lib:format(\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/\", \
[code:root_dir(), erlang:system_info(version)])), \
init:stop()."
erlc -v -Werror +debug_info +warn_export_all +warn_export_vars +warn_shadow_vars +warn_obsolete_guard -o ebin/ -pa ebin/ -I include/ src/dlibusb_nif.erl src/dlibusb_sup.erl src/dlibusb_app.erl src/dlibusb.erl
cat src/dlibusb.app.src \
| sed "s/{modules,[[:space:]]*\[\]}/{modules, \['dlibusb_nif', 'dlibusb', 'dlibusb_app', 'dlibusb_sup'\]}/" \
> ebin/dlibusb.app
cc -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes -I/usr/local/lib/erlang/erts-6.2/include/ -fPIC -c -o /device/apps/erlapps/dlibusb/c_src/dlibusb.o /device/apps/erlapps/dlibusb/c_src/dlibusb.c
/device/apps/erlapps/dlibusb/c_src/dlibusb.c:3:5: warning: no previous prototype for ‘load’ [-Wmissing-prototypes]
/device/apps/erlapps/dlibusb/c_src/dlibusb.c:8:6: warning: no previous prototype for ‘unload’ [-Wmissing-prototypes]
/device/apps/erlapps/dlibusb/c_src/dlibusb.c:13:14: warning: no previous prototype for ‘mytest’ [-Wmissing-prototypes]
cc -shared -o /device/apps/erlapps/dlibusb/priv/dlibusb.so /device/apps/erlapps/dlibusb/c_src/dlibusb.o
goertzen-G550JK dlibusb # LD_PRELOAD=/lib/libSegFault.so ERL_LIBS=.. erl
Erlang/OTP 17 [erts-6.2] [source] [smp:8:8] [ds:8:8:10] [async-threads:10] [kernel-poll:false]
Eshell V6.2 (abort with ^G)
1> dlibusb:mytest_io().
*** Segmentation fault
Register dump:
EAX: 00000000 EBX: e64f870c ECX: 00000000 EDX: e64f8718
ESI: f6543100 EDI: 08192d1e EBP: f59801d8 ESP: f363f1d0
EIP: 08190b56 EFLAGS: 00010246
CS: 0023 DS: 002b ES: 002b FS: 0000 GS: 0063 SS: 002b
Trap: 0000000e Error: 00000005 OldMask: 00010202
ESP/signal: f363f1d0 CR2: fffffffe
FPUCW: ffff037f FPUSW: ffff0120 TAG: ffffffff
IPOFF: 08150ed0 CSSEL: 0023 DATAOFF: f363ffff DATASEL: 002b
ST(0) 0000 0000000000000000 ST(1) 0000 0000000000000000
ST(2) 0000 0000000000000000 ST(3) 0000 0000000000000000
ST(4) 0000 0000000000000000 ST(5) 0000 0000000000000000
ST(6) 0000 ed5bfd70a3d70e91 ST(7) 0000 8000000000000000
Backtrace:
/usr/local/lib/erlang/erts-6.2/bin/beam.smp(process_main+0xc36)[0x8190b56]
/usr/local/lib/erlang/erts-6.2/bin/beam.smp[0x80e565f]
/usr/local/lib/erlang/erts-6.2/bin/beam.smp[0x820982c]
/lib/libpthread.so.0(+0x7f47)[0xf764cf47]
/lib/libc.so.6(clone+0x5e)[0xf75ab97e]
Memory map:
08048000-08274000 r-xp 00000000 08:02 7215224 /usr/local/lib/erlang/erts-6.2/bin/beam.smp
08274000-08275000 r--p 0022b000 08:02 7215224 /usr/local/lib/erlang/erts-6.2/bin/beam.smp
08275000-082b2000 rw-p 0022c000 08:02 7215224 /usr/local/lib/erlang/erts-6.2/bin/beam.smp
082b2000-082ce000 rw-p 00000000 00:00 0
09d54000-09d7b000 rw-p 00000000 00:00 0 [heap]
e5700000-e5c00000 rw-p 00000000 00:00 0
e5c00000-e5c09000 rw-p 00000000 00:00 0
e5c09000-e5d00000 ---p 00000000 00:00 0
e5d00000-e5d09000 rw-p 00000000 00:00 0
e5d09000-e5e00000 ---p 00000000 00:00 0
e5e00000-e5e08000 rw-p 00000000 00:00 0
e5e08000-e5f00000 ---p 00000000 00:00 0
e5fc0000-e6000000 rw-p 00000000 00:00 0
e6000000-e6009000 rw-p 00000000 00:00 0
e6009000-e6100000 ---p 00000000 00:00 0
e6100000-e6109000 rw-p 00000000 00:00 0
e6109000-e6200000 ---p 00000000 00:00 0
e6200000-e6209000 rw-p 00000000 00:00 0
e6209000-e6300000 ---p 00000000 00:00 0
e6300000-e6309000 rw-p 00000000 00:00 0
e6309000-e6400000 ---p 00000000 00:00 0
e6422000-e643e000 r-xp 00000000 08:02 6460884 /usr/lib/gcc/i486-pc-linux-gnu/4.8.3/libgcc_s.so.1
e643e000-e643f000 r--p 0001b000 08:02 6460884 /usr/lib/gcc/i486-pc-linux-gnu/4.8.3/libgcc_s.so.1
e643f000-e6440000 rw-p 0001c000 08:02 6460884 /usr/lib/gcc/i486-pc-linux-gnu/4.8.3/libgcc_s.so.1
e6440000-e6640000 rw-p 00000000 00:00 0
e6640000-e6641000 ---p 00000000 00:00 0
e6641000-e6e40000 rw-p 00000000 00:00 0 [stack:22967]
e6e40000-e6e41000 ---p 00000000 00:00 0
e6e41000-e7640000 rw-p 00000000 00:00 0 [stack:22966]
e7640000-e7641000 ---p 00000000 00:00 0
e7641000-e7e40000 rw-p 00000000 00:00 0 [stack:22965]
e7e40000-e7e41000 ---p 00000000 00:00 0
e7e41000-e8640000 rw-p 00000000 00:00 0 [stack:22964]
e8640000-e8641000 ---p 00000000 00:00 0
e8641000-e8e40000 rw-p 00000000 00:00 0 [stack:22963]
e8e40000-e8e41000 ---p 00000000 00:00 0
e8e41000-e9640000 rw-p 00000000 00:00 0 [stack:22962]
e9640000-e9641000 ---p 00000000 00:00 0
e9641000-e9e40000 rw-p 00000000 00:00 0 [stack:22961]
e9e40000-e9e41000 ---p 00000000 00:00 0
e9e41000-ea640000 rw-p 00000000 00:00 0 [stack:22960]
ea640000-ea641000 ---p 00000000 00:00 0
ea641000-eae40000 rw-p 00000000 00:00 0 [stack:22959]
eae40000-eae41000 ---p 00000000 00:00 0
eae41000-eb640000 rw-p 00000000 00:00 0 [stack:22958]
eb640000-eb641000 ---p 00000000 00:00 0
eb641000-ebe40000 rw-p 00000000 00:00 0 [stack:22957]
ebe40000-ebe41000 ---p 00000000 00:00 0
ebe41000-ec640000 rw-p 00000000 00:00 0 [stack:22956]
ec640000-ec641000 ---p 00000000 00:00 0
ec641000-ece40000 rw-p 00000000 00:00 0 [stack:22955]
ece40000-ece41000 ---p 00000000 00:00 0
ece41000-ed640000 rw-p 00000000 00:00 0 [stack:22954]
ed640000-ed641000 ---p 00000000 00:00 0
ed641000-ede40000 rw-p 00000000 00:00 0 [stack:22953]
ede40000-ede41000 ---p 00000000 00:00 0
ede41000-ee640000 rw-p 00000000 00:00 0 [stack:22952]
ee640000-ee641000 ---p 00000000 00:00 0
ee641000-eee40000 rw-p 00000000 00:00 0 [stack:22951]
eee40000-eee41000 ---p 00000000 00:00 0
eee41000-ef640000 rw-p 00000000 00:00 0 [stack:22950]
ef640000-ef641000 ---p 00000000 00:00 0
ef641000-efe40000 rw-p 00000000 00:00 0 [stack:22949]
efe40000-efe41000 ---p 00000000 00:00 0
efe41000-f0640000 rw-p 00000000 00:00 0 [stack:22948]
f0640000-f0641000 ---p 00000000 00:00 0
f0641000-f0e40000 rw-p 00000000 00:00 0 [stack:22947]
f0e40000-f0e41000 ---p 00000000 00:00 0
f0e41000-f1640000 rw-p 00000000 00:00 0 [stack:22946]
f1640000-f1641000 ---p 00000000 00:00 0
f1641000-f1e40000 rw-p 00000000 00:00 0 [stack:22945]
f1e40000-f1e41000 ---p 00000000 00:00 0
f1e41000-f2640000 rw-p 00000000 00:00 0 [stack:22944]
f2640000-f2641000 ---p 00000000 00:00 0
f2641000-f2e40000 rw-p 00000000 00:00 0 [stack:22943]
f2e40000-f2e41000 ---p 00000000 00:00 0
f2e41000-f3640000 rw-p 00000000 00:00 0 [stack:22942]
f3640000-f3641000 ---p 00000000 00:00 0
f3641000-f3f40000 rw-p 00000000 00:00 0 [stack:22941]
f3f56000-f3f57000 ---p 00000000 00:00 0
f3f57000-f3f67000 rw-p 00000000 00:00 0 [stack:22939]
f3f67000-f3f68000 ---p 00000000 00:00 0
f3f68000-f3f78000 rw-p 00000000 00:00 0 [stack:22938]
f3f78000-f3f79000 ---p 00000000 00:00 0
f3f79000-f3f89000 rw-p 00000000 00:00 0 [stack:22937]
f3f89000-f3f8a000 ---p 00000000 00:00 0
f3f8a000-f3f9a000 rw-p 00000000 00:00 0 [stack:22936]
f3f9a000-f3f9b000 ---p 00000000 00:00 0
f3f9b000-f3fab000 rw-p 00000000 00:00 0 [stack:22935]
f3fab000-f3fac000 ---p 00000000 00:00 0
f3fac000-f3fbc000 rw-p 00000000 00:00 0 [stack:22934]
f3fbc000-f3fbd000 ---p 00000000 00:00 0
f3fbd000-f3fcd000 rw-p 00000000 00:00 0 [stack:22933]
f3fcd000-f3fce000 ---p 00000000 00:00 0
f3fce000-f3fde000 rw-p 00000000 00:00 0 [stack:22932]
f3fde000-f3fdf000 ---p 00000000 00:00 0
f3fdf000-f3fef000 rw-p 00000000 00:00 0 [stack:22931]
f3fef000-f3ff0000 ---p 00000000 00:00 0
f3ff0000-f4000000 rw-p 00000000 00:00 0 [stack:22930]
f4000000-f4001000 ---p 00000000 00:00 0
f4001000-f4c40000 rw-p 00000000 00:00 0 [stack:22929]
f4c4e000-f4d80000 r--p 00ef5000 08:02 5898454 /usr/lib/locale/locale-archive
f4d80000-f4f80000 r--p 00000000 08:02 5898454 /usr/lib/locale/locale-archive
f4f80000-f4f81000 ---p 00000000 00:00 0
f4f81000-f57c0000 rw-p 00000000 00:00 0 [stack:22928]
f57c3000-f57c4000 r-xp 00000000 08:02 6690923 /device/apps/erlapps/dlibusb/priv/dlibusb.so
f57c4000-f57c5000 r--p 00000000 08:02 6690923 /device/apps/erlapps/dlibusb/priv/dlibusb.so
f57c5000-f57c6000 rw-p 00001000 08:02 6690923 /device/apps/erlapps/dlibusb/priv/dlibusb.so
f57c6000-f74c9000 rw-p 00000000 00:00 0
f74c9000-f7636000 r-xp 00000000 08:02 6048158 /lib/libc-2.20.so
f7636000-f7638000 r--p 0016c000 08:02 6048158 /lib/libc-2.20.so
f7638000-f7639000 rw-p 0016e000 08:02 6048158 /lib/libc-2.20.so
f7639000-f763c000 rw-p 00000000 00:00 0
f763c000-f7643000 r-xp 00000000 08:02 6048134 /lib/librt-2.20.so
f7643000-f7644000 r--p 00006000 08:02 6048134 /lib/librt-2.20.so
f7644000-f7645000 rw-p 00007000 08:02 6048134 /lib/librt-2.20.so
f7645000-f765c000 r-xp 00000000 08:02 6044152 /lib/libpthread-2.20.so
f765c000-f765d000 r--p 00016000 08:02 6044152 /lib/libpthread-2.20.so
f765d000-f765e000 rw-p 00017000 08:02 6044152 /lib/libpthread-2.20.so
f765e000-f7660000 rw-p 00000000 00:00 0
f7660000-f7677000 r-xp 00000000 08:02 6041837 /lib/libz.so.1.2.8
f7677000-f7678000 r--p 00016000 08:02 6041837 /lib/libz.so.1.2.8
f7678000-f7679000 rw-p 00017000 08:02 6041837 /lib/libz.so.1.2.8
f7679000-f76c3000 r-xp 00000000 08:02 7344897 /lib/libncurses.so.5.9
f76c3000-f76c4000 ---p 0004a000 08:02 7344897 /lib/libncurses.so.5.9
f76c4000-f76c6000 r--p 0004a000 08:02 7344897 /lib/libncurses.so.5.9
f76c6000-f76c7000 rw-p 0004c000 08:02 7344897 /lib/libncurses.so.5.9
f76c7000-f76c8000 rw-p 00000000 00:00 0
f76c8000-f770f000 r-xp 00000000 08:02 6044134 /lib/libm-2.20.so
f770f000-f7710000 r--p 00046000 08:02 6044134 /lib/libm-2.20.so
f7710000-f7711000 rw-p 00047000 08:02 6044134 /lib/libm-2.20.so
f7711000-f7714000 r-xp 00000000 08:02 6044145 /lib/libdl-2.20.so
f7714000-f7715000 r--p 00002000 08:02 6044145 /lib/libdl-2.20.so
f7715000-f7716000 rw-p 00003000 08:02 6044145 /lib/libdl-2.20.so
f7716000-f7718000 r-xp 00000000 08:02 6048164 /lib/libutil-2.20.so
f7718000-f7719000 r--p 00001000 08:02 6048164 /lib/libutil-2.20.so
f7719000-f771a000 rw-p 00002000 08:02 6048164 /lib/libutil-2.20.so
f771a000-f771b000 rw-p 00000000 00:00 0
f771b000-f771c000 ---p 00000000 00:00 0
f771c000-f7720000 rw-p 00000000 00:00 0 [stack:22940]
f7720000-f7723000 r-xp 00000000 08:02 6048219 /lib/libSegFault.so
f7723000-f7724000 r--p 00002000 08:02 6048219 /lib/libSegFault.so
f7724000-f7725000 rw-p 00003000 08:02 6048219 /lib/libSegFault.so
f7725000-f7726000 rw-p 00000000 00:00 0
f7726000-f7727000 r-xp 00000000 00:00 0 [vdso]
f7727000-f7729000 r--p 00000000 00:00 0 [vvar]
f7729000-f774a000 r-xp 00000000 08:02 6048167 /lib/ld-2.20.so
f774a000-f774b000 r--p 00020000 08:02 6048167 /lib/ld-2.20.so
f774b000-f774c000 rw-p 00021000 08:02 6048167 /lib/ld-2.20.so
ffa1b000-ffa3c000 rw-p 00000000 00:00 0 [stack]
Segmentation fault (core dumped)
goertzen-G550JK dlibusb #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment