Discussion:
Bug#932581: libminini: FTBFS on hppa - PIC and assert issues
Add Reply
John David Anglin
2019-07-20 21:10:02 UTC
Reply
Permalink
Source: libminini
Version: 1.2.a+ds-2
Severity: normal

Dear Maintainer,

The build fails in test1 with a segmentation fault:

LD_LIBRARY_PATH=. ./test1
Segmentation fault

This is caused by the fact that objects linked into shared libraries need
to be compiled with the -fPIC option. This option also needs to be added
when linking shared libraries. With this problem fixed, test1 now runs
correctly but test2 fails at the following assert:

LD_LIBRARY_PATH=. ./test2
test2: minIni.cc:214: char* save_strncpy(char*, const char*, size_t, quote_option): Assertion `dest <= source || dest >= source + maxlen' failed.
Aborted

Breakpoint 1, save_strncpy (dest=0xf8f02808 "\370\360\"\300",
source=0xf8f02630 "aap", maxlen=512, option=QUOTE_NONE) at minIni.cc:214
214 assert(dest <= source || dest >= source + maxlen);
(gdb) p dest <= source
$4 = false
(gdb) p dest
$5 = 0xf8f02808 "\370\360\"\300"
(gdb) p source
$6 = 0xf8f02630 "aap"
(gdb) p dest >= source + maxlen
$7 = false
(gdb) p maxlen
$8 = 512
(gdb) p/x $sp
$9 = 0xf8f02b40

It looks like the assert is triggered on hppa because the stack grows up.

Package builds if I disable assert:

***@atlas:~/debian/libminini/libminini-1.2.a+ds$ diff -u minIni.cc.save minIni.cc
--- minIni.cc.save 2019-07-20 16:46:47.744616954 -0400
+++ minIni.cc 2019-07-20 16:47:31.594198802 -0400
@@ -211,7 +211,9 @@
size_t d, s;

assert(maxlen>0);
+#ifndef __hppa__
assert(dest <= source || dest >= source + maxlen);
+#endif
if (option == QUOTE_ENQUOTE && maxlen < 3)
option = QUOTE_NONE; /* cannot store two quotes and a terminating zero in less than 3 characters */

Regards,
Dave Anglin


-- System Information:
Debian Release: bullseye/sid
APT prefers buildd-unstable
APT policy: (500, 'buildd-unstable'), (500, 'unstable')
Architecture: hppa (parisc64)

Kernel: Linux 4.14.133+ (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=C (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Yangfl
2019-07-21 05:10:01 UTC
Reply
Permalink
Post by John David Anglin
Source: libminini
Version: 1.2.a+ds-2
Severity: normal
Dear Maintainer,
LD_LIBRARY_PATH=. ./test1
Segmentation fault
This is caused by the fact that objects linked into shared libraries need
to be compiled with the -fPIC option. This option also needs to be added
when linking shared libraries. With this problem fixed, test1 now runs
Hmm, I'm still confused why this option is not needed on any other arch?
John David Anglin
2019-07-21 14:20:01 UTC
Reply
Permalink
Post by Yangfl
Post by John David Anglin
Source: libminini
Version: 1.2.a+ds-2
Severity: normal
Dear Maintainer,
LD_LIBRARY_PATH=. ./test1
Segmentation fault
This is caused by the fact that objects linked into shared libraries need
to be compiled with the -fPIC option. This option also needs to be added
when linking shared libraries. With this problem fixed, test1 now runs
Hmm, I'm still confused why this option is not needed on any other arch?
It's definitely a problem on architectures that aren't PIC by default.

On 32-bit hppa, register r19 is the PIC register when PIC code is generated.  In non-PIC code,
r19 is a general register.  The PIC register for a shared library is set on entry by long branch
stubs set up by the linker.  If a shared library contains non PIC code, r19 may be clobbered.

That's what happens here in test1:

(gdb) c
Continuing.

Breakpoint 1, 0xfabcca28 in ini_gets (Section=0x11878 "first",
    Key=0x11870 "string", DefValue=0x11868 "dummy",
    Buffer=0xf8f022d4 "\372Wl\200", BufferSize=<optimized out>,
    Filename=<optimized out>) at minIni.cc:374
374       if (ini_openread(Filename, &fp)) {
(gdb) stepi
0xfabcca2c      374       if (ini_openread(Filename, &fp)) {
(gdb) disass $pc-16,$pc+16
Dump of assembler code from 0xfabcca1c to 0xfabcca3c:
   0xfabcca1c <ini_gets(char const*, char const*, char const*, char*, int, char const*)+44>:    stw r4,-68(sp)
   0xfabcca20 <ini_gets(char const*, char const*, char const*, char*, int, char const*)+48>:    ldw -b4(sp),r4
   0xfabcca24 <ini_gets(char const*, char const*, char const*, char*, int, char const*)+52>:    stw r3,-64(sp)
   0xfabcca28 <ini_gets(char const*, char const*, char const*, char*, int, char const*)+56>:    b,l 0xfabcb91c,rp
=> 0xfabcca2c <ini_gets(char const*, char const*, char const*, char*, int, char const*)+60>:    copy r23,r3
   0xfabcca30 <ini_gets(char const*, char const*, char const*, char*, int, char const*)+64>:    cmpib,= 0,ret0,0xfabcca70 <ini_gets(char const*,
char const*, char const*, char*, int, char const*)+128>
   0xfabcca34 <ini_gets(char const*, char const*, char const*, char*, int, char const*)+68>:    stw ret0,-78(sp)
   0xfabcca38 <ini_gets(char const*, char const*, char const*, char*, int, char const*)+72>:    ldi -1,ret0
End of assembler dump.
(gdb) stepi
0xfabcb91c in ?? ()
   from /home/dave/debian/libminini-x/libminini-1.2.a+ds/libminIni.so.1
(gdb) x/4i $pc
=> 0xfabcb91c:  addil L%-800,r19,r1
   0xfabcb920:  ldw 794(r1),r21
   0xfabcb924:  bv r0(r21)
   0xfabcb928:  ldw 798(r1),r19
(gdb) p/x $r19
$1 = 0x0
(gdb) stepi
0xfabcb920 in ?? ()
   from /home/dave/debian/libminini-x/libminini-1.2.a+ds/libminIni.so.1
(gdb) bt
#0  0xfabcb920 in ?? ()
   from /home/dave/debian/libminini-x/libminini-1.2.a+ds/libminIni.so.1
#1  0xfabcca30 in ini_gets (Section=0x11878 "first", Key=0x11870 "string",
    DefValue=0x11868 "dummy", Buffer=0xf8f022d4 "\372Wl\200",
    BufferSize=<optimized out>, Filename=<optimized out>) at minIni.cc:374
#2  0x000108b4 in main ()
(gdb) stepi

Program received signal SIGSEGV, Segmentation fault.
0xfabcb920 in ?? ()
   from /home/dave/debian/libminini-x/libminini-1.2.a+ds/libminIni.so.1

Non-PIC code also uses different relocations.  Some are not valid in PIC code.

The reason to pass "-fPIC" in shared link commands is in some circumstances (e.g., lto) the
linker may perform compilations and generate objects that are linked into the shared object.

Dave
--
John David Anglin ***@bell.net
John David Anglin
2019-07-31 15:40:02 UTC
Reply
Permalink
Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
replying to this email.
Although the PIC compilation issue was addressed, the second half of the bug report wasn't:

6. String deletion tests passed
LD_LIBRARY_PATH=. ./test2
test2: minIni.cc:214: char* save_strncpy(char*, const char*, size_t, quote_option): Assertion `dest <= source || dest >= source + maxlen' failed.
Aborted
make[1]: *** [Makefile:57: test] Error 134
make[1]: Leaving directory '/<<PKGBUILDDIR>>'
dh_auto_test: make -j4 test returned exit code 2
make: *** [debian/rules:17: build-arch] Error 255
dpkg-buildpackage: error: debian/rules build-arch subprocess returned exit status 2

Regards,
Dave
--
John David Anglin ***@bell.net
Loading...