[postgis-devel] C-Library function returning PostGIS point crashing backend

David Fuhry dfuhry at gmail.com
Fri Jan 11 14:20:55 PST 2013


I tried statically linking liblwgeom by changing SHLIB_LINK from
"-L/usr/local/lib -llwgeom" to "/usr/local/lib/liblwgeom.a" but the
segfault in pfree occurred just as before.

There are no compile-time warnings when compiling the module:

$ make clean && make
rm -f test2.so   libtest2.a
rm -f test2.o
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard
-g -fpic -g -O0 -I. -I. -I/usr/local/pgsql/include/server
-I/usr/local/pgsql/include/internal -D_GNU_SOURCE   -c -o test2.o test2.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard
-g -fpic -shared -o test2.so test2.o -L/usr/local/pgsql/lib -Wl,--as-needed
-Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags
 /usr/local/lib/liblwgeom.a

I am not sure how to verify that there is no mismatch between
postgresql-server headers at build time and postgresql  libraries at run
time. `pg_config --includedir-server` returns
"/usr/local/pgsql/include/server" which seems correct. According to ldd,
neither my test2.so nor /usr/local/pgsql/lib/postgis-2.0.so link to
postgresql libraries:

test2.so dynamically linked to liblwgeom.so:
$ ldd test2.so
linux-vdso.so.1 =>  (0x00007fffad914000)
 liblwgeom-2.0.2.so => /usr/local/lib/liblwgeom-2.0.2.so(0x00007f5cfd2df000)
libc.so.6 => /lib64/libc.so.6 (0x00007f5cfcf4b000)
 libgeos_c.so.1 => /usr/local/lib/libgeos_c.so.1 (0x00007f5cfcd27000)
libproj.so.0 => /usr/lib64/libproj.so.0 (0x00007f5cfcae4000)
 /lib64/ld-linux-x86-64.so.2 (0x00007f5cfd764000)
libgeos-3.3.6.so => /usr/local/lib/libgeos-3.3.6.so (0x00007f5cfc759000)
 libstdc++.so.6 => /usr/local/lib/../lib64/libstdc++.so.6
(0x00007f5cfc452000)
libm.so.6 => /lib64/libm.so.6 (0x00007f5cfc1ce000)
 libgcc_s.so.1 => /usr/local/lib/../lib64/libgcc_s.so.1 (0x00007f5cfbfb8000)

test2.so statically linked to liblwgeom.a:
$ ldd test2.so
linux-vdso.so.1 =>  (0x00007fff27bff000)
libc.so.6 => /lib64/libc.so.6 (0x00007f1476360000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1476951000)

$ ldd /usr/local/pgsql/lib/postgis-2.0.so
linux-vdso.so.1 =>  (0x00007fff11bff000)
libgeos_c.so.1 => /usr/local/lib/libgeos_c.so.1 (0x00007f0077428000)
libproj.so.0 => /usr/lib64/libproj.so.0 (0x00007f00771e4000)
libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00007f0076e92000)
libm.so.6 => /lib64/libm.so.6 (0x00007f0076c0e000)
libc.so.6 => /lib64/libc.so.6 (0x00007f007687a000)
libgeos-3.3.6.so => /usr/local/lib/libgeos-3.3.6.so (0x00007f00764f0000)
libstdc++.so.6 => /usr/local/lib/../lib64/libstdc++.so.6
(0x00007f00761e9000)
libgcc_s.so.1 => /usr/local/lib/../lib64/libgcc_s.so.1 (0x00007f0075fd3000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f0075dcf000)
libz.so.1 => /lib64/libz.so.1 (0x00007f0075bb9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0077926000)

-Dave



On Fri, Jan 11, 2013 at 3:53 AM, Sandro Santilli <strk at keybit.net> wrote:

> On Thu, Jan 10, 2013 at 02:29:31PM -0500, David Fuhry wrote:
>
> > I built the latest stable versions of PostgreSQL (9.2.2) and PostGIS
> > (2.0.2), both built with --enable-debug, on a different machine (RHEL 6)
> > and following Paul's instructions, got the following backtrace showing
> the
> > segfault occurring in pfree:
>
> [...]
>
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x000000000072488b in pfree (pointer=0xc63e40) at mcxt.c:659
> > 659 (*header->context->methods->free_p) (header->context, pointer);
>
> [...]
>
> > I noticed that header->context->methods points (as do ->parent and
> ->name)
> > to an invalid address:
> >
> > (gdb) f 0
> > #0  0x000000000072488b in pfree (pointer=0xc63e40) at mcxt.c:659
> > 659 (*header->context->methods->free_p) (header->context, pointer);
> > (gdb) p *header->context
> > $8 = {type = 1237353800, methods = 0x7e01be000003c484, parent =
> > 0x9a00e8c789480087, firstchild = 0xfa840fc08548ffd4, nextchild =
> > 0x1c3883d0ff000002,
> >   name = 0x279840fc58948 <Address 0x279840fc58948 out of bounds>,
> isReset =
> > 0 '\000'}
> > (gdb) p *header->context->methods
> > Cannot access memory at address 0x7e01be000003c484
> >
> > Suggestions?
>
> Can it be a mismatch between postgresql-server headers at build time
> and postgresql libraries at run time ? Any compile-time warning ?
> Also try statically linking liblwgeom
>
> --strk;
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20130111/acf2f00a/attachment.html>


More information about the postgis-devel mailing list