sysdetect fortran bindings

Issue #127 resolved
Giuseppe Congiu created an issue

Fortran bindings that have string_len generated by the compiler cause a segfault in strncpy as the string_len appears to be initialised to a random value. Running query_device_simple_f under debugger produces the following:

Starting program: /home/gcongiu/papi/src/components/sysdetect/tests/./query_device_simple_f
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fffef034700 (LWP 40652)]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6e2ec60 in __strncpy_sse2_unaligned () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libgfortran-4.8.5-44.el7.x86_64 libquadmath-4.8.5-44.el7.x86_64 nvidia-driver-latest-dkms-cuda-libs-470.103.01-1.el7.x86_64
(gdb) bt
#0  0x00007ffff6e2ec60 in __strncpy_sse2_unaligned () from /lib64/libc.so.6
#1  0x00000000004057f6 in papif_get_dev_attr_ (handle_index=0x7fffffffc4f0, id=0x7fffffffc4ec, attribute=0x49eca4, value=0x7fffffffc4f8,
    string=0x7fffffffc500 "Intel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHz", check=0x7fffffffc510, string_len=-15212) at papi_fwrappers.c:1602
#2  0x0000000000402f3c in MAIN__ ()                                                          ^^^^^^^^^^^^^^^^^
#3  0x0000000000000000 in ?? ()

Where string_len=-15212.

A quick fix could be ignoring the compiler generated string_len argument and compute the length of the string using strlen instead.

Comments (1)

  1. Log in to comment