Balázs Udvary
Balázs Udvary

Reputation: 13

Segmentation fault at xml parsing only with libdb2

I have a testprogram which tries to parse an example xml on SLES11, but the result is a segmentation fault. However if I link without libdb2 than it works fine.

g++-8.3 -o testXmlParser main.cpp -m31 -lxml2

Added the -ldb2 and I get the mentioned segmentation fault and before that a "1: parser error : Document is empty"

g++-8.3 -o testXmlParser main.cpp -m31 -lxml2 -ldb2

My code:

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <iostream>


int main ()
{
        xmlDoc *doc = NULL;
        xmlNode *root_element = NULL;
        std::cout << "log1" << std::endl;
        doc = xmlParseEntity("/tmp/testXML.xml");
        std::cout << "log2" << std::endl;
        root_element = xmlDocGetRootElement(doc);
        std::cout << "root element: "<<root_element->name << std::endl ;
        return 0;
}

And the callstack:

#0  0x7b30399e in free () from /lib/libc.so.6
#1  0x7bb3bb92 in destroy () from /data/db2inst1/sqllib/lib32/libdb2.so.1
#2  0x7bb3cdf4 in gzclose () from /data/db2inst1/sqllib/lib32/libdb2.so.1
#3  0x7d1896f0 in ?? () from /usr/lib/libxml2.so.2
#4  0x7d187e80 in xmlFreeParserInputBuffer () from /usr/lib/libxml2.so.2
#5  0x7d1602f4 in xmlFreeInputStream () from /usr/lib/libxml2.so.2
#6  0x7d160336 in xmlFreeParserCtxt () from /usr/lib/libxml2.so.2
#7  0x7d17427c in xmlSAXParseEntity () from /usr/lib/libxml2.so.2
#8  0x00400c02 in main ()

Could you help me solve this problem?

This is a test program, the db2 is not used here, but used in our software where this problem comes from.

Upvotes: 1

Views: 184

Answers (2)

kkuduk
kkuduk

Reputation: 601

Db2 uses zlib internally and those symbols are (incorrectly) exported. This will be addressed via APAR IT29520: ZLIB SYMBOLS INSIDE LIBDB2.SO ARE GLOBALLY VISIBLE WHICH MEANS THEY COLLIDE WITH ZLIB SYMBOLS INSIDE LIBZ.SO

With LD_DEBUG=all you'll see how symbols mapped/resolved. You can try @memmertoIBM's suggestion or put libdb2 behind zlib in LD_LIBRARY_PTH

Upvotes: 1

memmertoIBM
memmertoIBM

Reputation: 71

The problem is that libxml requires libz and you're not linking with it.

Since Db2 includes zlib in their libraries (see stack frames #1, #2) the symbols are getting resolved by the linker.

There must be some incompatibility between the zlib that libxml expects, and the version that is embedded into Db2.

Try adding '-lz' to your compile line, before '-ldb2', so that the linker will try to use that library first.

Upvotes: 3

Related Questions