<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-family:"Courier New"'>I’m working on
some sample programs and I’ve run into a weird problem with libibverbs.
If I have a simple program linked with libibverbs, things worked smoothly, but
if I more those functions into a shared library which then calls libibverbs, I
core dump, with what appears to be a corrupted call stack.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>Are there special
flags I need to use when creating an SO that works with libibverbs?<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>Here’s what I
mean:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
hca = open_device(argv[optind]); // value of hca is 0x5054a0.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
if (!hca) {<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
fprintf(stderr, "Could not open HCA.\n");<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
return -1;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
struct ibv_device_attr attr;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
ibv_query_device(hca,&attr); // this call completes successfully.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
fprintf(stderr,"MHEINZ: Firmware = %s\n",<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
attr.fw_ver);<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> err =
my_shared_func(hca);<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> …<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>int my_shared_func(struct
ibv_context *hca)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>{<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> struct
ibv_device_attr attr;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> hca_context->ops.query_device(hca_context,
&attr); // This works!<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> ibv_query_device(hca_context,&attr);
// core dump here.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> fprintf(stderr,"MHEINZ:
Firmware = %s\n",<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
attr.fw_ver);<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
return 0;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>} <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>First, note that
calling the device query directly, by using the function pointers in
hca_context, works – so I know that the value of hca_context is correct.
On the other hand, at the point of the core dump, gdb reports that inside
ibv_query_device, the value of hca_context has changed from 0x5044a0 to 0x2b46392fb310!<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>--</span><span
style='font-size:12.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Michael
Heinz</span><span style='font-size:12.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Principal
Engineer, Qlogic Corporation</span><span style='font-size:12.0pt;font-family:
"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>King
of Prussia, Pennsylvania</span><span style='font-family:"Courier New"'><o:p></o:p></span></p>
</div>
</body>
</html>