<div dir="ltr"><div>ldd libAPP.so does NOT have any reference to libSSL.so or for that matter any SSL library. Which is why I had to use nm to check for SSL related symbols<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 4, 2019 at 6:31 PM Floodeenjr, Thomas <<a href="mailto:thomas_floodeenjr@mentor.com">thomas_floodeenjr@mentor.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_4597605818224177673WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri",sans-serif;color:rgb(31,73,125)">To check if you are linked statically or dynamically, what does ldd tell you? (</span><code><span style="font-size:10pt">ldd libAPP.so</span></code><span style="font-size:11pt;font-family:"Calibri",sans-serif;color:rgb(31,73,125)">)
 Your library should not have a dependency on libssl.so or libcrypto.so if you are linked statically.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri",sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri",sans-serif;color:rgb(31,73,125)">-Tom<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri",sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11pt;font-family:"Calibri",sans-serif"> openssl-users [mailto:<a href="mailto:openssl-users-bounces@openssl.org" target="_blank">openssl-users-bounces@openssl.org</a>]
<b>On Behalf Of </b>Aijaz Baig<br>
<b>Sent:</b> Sunday, November 3, 2019 11:30 PM<br>
<b>To:</b> <a href="mailto:openssl-users@openssl.org" target="_blank">openssl-users@openssl.org</a><br>
<b>Subject:</b> static linking libssl and libcrypto<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">I am trying to build a shared library that internally links openssl and crypto libraries statically so I can use it in a production environment. To that end I am using the following Makefile<u></u><u></u></p>
</div>
<div>
<pre><code>APPBASE=/home/AB/Documents/APP/APP_2.17.0<u></u><u></u></code></pre>
<pre><code>OPENSSL1.0.2p_INSTALL_LOC=/home/AB/Documents/APP/OpenSSL-1.0.2p-installation<u></u><u></u></code></pre>
<pre><code>CC=gcc<u></u><u></u></code></pre>
<pre><code>CFLAGS= -Wall -g -O -fPIC<u></u><u></u></code></pre>
<pre><code>RM= rm -f<u></u><u></u></code></pre>
<pre><code>.PHONY: all clean<u></u><u></u></code></pre>
<pre><code><u></u> <u></u></code></pre>
<pre><code>src=$(wildcard *Generic/*.c *Linux/*.c)<u></u><u></u></code></pre>
<pre><code>$(info source=$(src))<u></u><u></u></code></pre>
<pre><code><u></u> <u></u></code></pre>
<pre><code>#we use the custom compiled openssl version<u></u><u></u></code></pre>
<pre><code>#and NOT the one available on the system<u></u><u></u></code></pre>
<pre><code>#INC=-I/usr/include/openssl<u></u><u></u></code></pre>
<pre><code>INC+=-I$(OPENSSL1.0.2p_INSTALL_LOC)/include/openssl<u></u><u></u></code></pre>
<pre><code>INC+=$(foreach d,$(incdir),-I$d)<u></u><u></u></code></pre>
<pre><code>$(info includes=$(INC))<u></u><u></u></code></pre>
<pre><code><u></u> <u></u></code></pre>
<pre><code>LIB=-L$(OPENSSL1.0.2p_INSTALL_LOC)/lib<u></u><u></u></code></pre>
<pre><code>#LIB=-llibssl -llibcrypto<u></u><u></u></code></pre>
<pre><code>LIB+=-lssl -lcrypto<u></u><u></u></code></pre>
<pre><code>$(info links=$(LIB))<u></u><u></u></code></pre>
<pre><code>#LIB+=-L/usr/lib/<u></u><u></u></code></pre>
<pre><code><u></u> <u></u></code></pre>
<pre><code>obj=$(src:.c=.o)<u></u><u></u></code></pre>
<pre><code>all: libAPP.so<u></u><u></u></code></pre>
<pre><code>clean:<u></u><u></u></code></pre>
<pre><code>    $(RM) *.o *.so<u></u><u></u></code></pre>
<pre><code>    $(shell find $(APPBASE) -type f -iname "*.o" -exec rm -rf {} \;)<u></u><u></u></code></pre>
<pre><code><u></u> <u></u></code></pre>
<pre><code>.c.o:<u></u><u></u></code></pre>
<pre><code>    ${CC} -static ${CFLAGS} $(INC) -c $< $(LIB) -o $@<u></u><u></u></code></pre>
<pre><code><u></u> <u></u></code></pre>
<pre><code>libAPP.so: $(obj)<u></u><u></u></code></pre>
<pre><code>    $(LINK.c) -shared $^ -o $@<u></u><u></u></code></pre>
</div>
<div>
<p class="MsoNormal">As mentioned here (<a href="https://stackoverflow.com/questions/18185618/how-to-use-static-linking-with-openssl-in-c-c/25811538#25811538" target="_blank">https://stackoverflow.com/questions/18185618/how-to-use-static-linking-with-openssl-in-c-c/25811538#25811538</a>),
 I've changed the linker flags to:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">-lcrypto -lz -ldl -static-libgcc</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">but it doesn't seem to change the size of the generated so file. On checking for references to SSL in this so file, I see there are a total of 87 entries</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">nm libAPP.so | grep -i "ssl" | wc -l</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">87</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">whereas listing </span>
</code><em><span style="font-size:10pt;font-family:"Courier New"">only</span></em><code><span style="font-size:10pt"> the global symbols from libssl.a tells me it has 1113 globally defined symbols.</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">nm -g ../OpenSSL-1.0.2p-installation/lib/libssl.a | grep -i "ssl" | wc -l
</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">1113</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">I do not know if libSSL got indeed linked statically or not. Could someone please shed some light on it?</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
Best Regards,<u></u><u></u></p>
<div>
<p class="MsoNormal">Aijaz Baig<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><br>Best Regards,<div>Aijaz Baig</div></div></div>