#791537 nss: FTBFS on hppa: segmentation fault in PR_FindSymbol

Package:
nss
Source:
nss
Submitter:
John David Anglin
Date:
2015-08-05 23:57:04 UTC
Severity:
normal
#791537#5
Date:
2015-07-05 22:56:45 UTC
From:
To:
Build fails here:
dh_strip -a --dbg-package=libnss3-dbg
umask 022; LD_LIBRARY_PATH=debian/libnss3/usr/lib/hppa-linux-gnu debian/libnss3-tools/usr/bin/shlibsign -v -i debian/libnss3/usr/lib/hppa-linux-gnu/nss/libsoftokn3.so
ERROR: ld.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
Segmentation fault (core dumped)

Full log is here:
http://buildd.debian-ports.org/status/fetch.php?pkg=nss&arch=hppa&ver=2%3A3.19.2-1&stamp=1436132892

(gdb) disass
Dump of assembler code for function PR_FindSymbol:
   0xfcd89440 <+0>:	addil L%0,r19,r1
   0xfcd89444 <+4>:	stw rp,-14(sp)
   0xfcd89448 <+8>:	stw,ma r6,40(sp)
   0xfcd8944c <+12>:	copy r25,r6
   0xfcd89450 <+16>:	stw r5,-3c(sp)
   0xfcd89454 <+20>:	copy r26,r5
   0xfcd89458 <+24>:	stw r4,-38(sp)
   0xfcd8945c <+28>:	copy r19,r4
   0xfcd89460 <+32>:	stw r3,-34(sp)
   0xfcd89464 <+36>:	ldw 194(r1),r3
   0xfcd89468 <+40>:	stw r19,-20(sp)
   0xfcd8946c <+44>:	b,l 0xfcd7e150,rp
   0xfcd89470 <+48>:	ldw 0(r3),r26
   0xfcd89474 <+52>:	ldo 10(r5),r25
   0xfcd89478 <+56>:	copy r4,r19
=> 0xfcd8947c <+60>:	ldw c(r5),r26
   0xfcd89480 <+64>:	copy r6,r24

(gdb) p/x $r5
$1 = 0x0
(gdb) bt
#0  0xfcd8947c in PR_FindSymbol () from /usr/lib/hppa-linux-gnu/libnspr4.so
#1  0x00011b90 in main ()

Register r5 is a copy of register r26 which is the lib argument to
PR_FindSymbol.

This documentation for PR_FindSymbol indicates that it accepts a NULL
argument.  However, the current code from the npsr package doesn't accept
a NULL argument:

PR_FindSymbol(PRLibrary *lib, const char *raw_name)
{
    void *f = NULL;
#if defined(NEED_LEADING_UNDERSCORE)
    char *name;
#else
    const char *name;
#endif
    /*
    ** Mangle the raw symbol name in any way that is platform specific.
    */
#if defined(NEED_LEADING_UNDERSCORE)
    /* Need a leading _ */
    name = PR_smprintf("_%s", raw_name);
#elif defined(AIX)
    /*
    ** AIX with the normal linker put's a "." in front of the symbol
    ** name.  When use "svcc" and "svld" then the "." disappears. Go
    ** figure.
    */
    name = raw_name;
#else
    name = raw_name;
#endif

    PR_EnterMonitor(pr_linker_lock);
    PR_ASSERT(lib != NULL);
    f = pr_FindSymbolInLib(lib, name);

#if defined(NEED_LEADING_UNDERSCORE)
    PR_smprintf_free(name);
#endif

    PR_ExitMonitor(pr_linker_lock);
    return f;
}

Current gcc versions may remove NULL checks.

#791537#10
Date:
2015-08-05 17:31:43 UTC
From:
To:
This is caused by a bug in debian/rules.  The LD_LIBRARY_PATH used for the shlibsign command does not
contain the path to libsoftokn3.so.  As a result, PORT_LoadLibraryFromOrigin doesn't find the library and the variable
lib is NULL.

The assert is optimized away.  Thus, it might help if shlibsign printed an error message when a library is not
found.

Attached is a patch which fixes build on hppa.  Pleas apply.

There is an issue with buildd dependencies for hppa and some other ports:

nss build-depends on missing:
- empty-dependency-after-parsing

Thanks,
Dave
--
John David Anglin	dave.anglin@bell.net

#791537#15
Date:
2015-08-05 20:54:39 UTC
From:
To:
The thing is, it should be trying to load nss/libsoftokn3.so from the
directory containing libnss3.so. This works fine on other architectures,
by the way.

Mike

#791537#20
Date:
2015-08-05 21:50:29 UTC
From:
To:

If I was to guess, I would have to think the dladdr call in PR_GetLibraryFilePathname_stub fails because
hppa uses function descriptors for indirect calls.  Did this work for ia64?  There seems to be some  trickiness
there.

I removed my debugging build, so it will be some time before I can investigate further.

Dave
--
John David Anglin	dave.anglin@bell.net

#791537#25
Date:
2015-08-05 23:54:50 UTC
From:
To:
This hunk is used:

#if defined(USE_DLFCN) && defined(HAVE_DLADDR)
    Dl_info dli;
    char *result;

    if (dladdr((void *)addr, &dli) == 0) {
        PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, _MD_ERRNO());
        DLLErrorInternal(_MD_ERRNO());
        return NULL;
    }
    result = PR_Malloc(strlen(dli.dli_fname)+1);
    if (result != NULL) {
        strcpy(result, dli.dli_fname);
    }
    return result;

PR_GetLibraryFilePathname is passed the following:

Breakpoint 1, 0xfc4e09d4 in PORT_LoadLibraryFromOrigin ()
   from debian/libnss3/usr/lib/hppa-linux-gnu/libnssutil3.so
(gdb) p/x $r25
$11 = 0x173f2
(gdb) p (char *)$r26
$12 = 0x15ff0 "libnssutil3.so"

$r5 contains a function pointer pointing to a function descriptor:
(gdb) x/2x 0x173f0
0x173f0:	0x0001756c	0x0000000c

0x0001756c is the address of a stub:
(gdb) disass 0x0001756c,0x0001756c+8
Dump of assembler code from 0x1756c to 0x17574:
   0x0001756c:	b,l 0x17560,r20
   0x00017570:	depwi 0,31,2,r20

On return from dladdr, dli contains:
Breakpoint 5, 0xfc6bd74c in PR_GetLibraryFilePathname ()
   from /usr/lib/hppa-linux-gnu/libnspr4.so
(gdb) p/x $sp-0x78
$8 = 0xfd703a08
(gdb) x/4x 0xfd703a08
0xfd703a08:	0xfd7016e1	0x00010000	0x00000000	0x00000000
(gdb) p (char *)0xfd7016e1
$9 = 0xfd7016e1 "/home/dave/debian/nss/nss-3.19.2/debian/libnss3-tools/usr/bin/shlibsign"

Thus, dladdr doesn't correctly handle function pointers on hppa.  On the other hand, it's
not clear how dladdr can tell the difference between a data pointer and a function pointer.

Dave
--
John David Anglin	dave.anglin@bell.net