<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi there,</p>
<p>When I compile my code with -fdata-sections and -ffunction-sections, I still see some unused string in my shared library (Android). Actually, the strings appear together inside a .rodata.str1.1 section instead of getting their own section. It seems that the C-string literal are considered differently than other constant and the -fdata-sections is not respected in <a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L799">https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L799.</a>  I came across the following GCC bug <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=192">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=192</a> where they have fixed the issue back in 2015. Any reason not to do so in LLVM?</p>
<p>My code example:<br />- static library 1 : expose functions api1() and api3()</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p>#include "lib1.h"</p>
<p>static char *test = "Test";<br />static char *unused = "Unused";</p>
<p>void api1(){<br />   printf(test);<br />}</p>
<p>void api3(){<br />   printf(unused);<br />}</p>
</blockquote>
<p>- shared library : use only function api1() from static library 1</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p>#include "lib1.h"</p>
<p>void test(){<br />   api1();<br />}</p>
</blockquote>
<p>Both compiled with "-fdata-sections -ffunction-sections -fvisibility=hidden" and linked with "--gc-sections".</p>
<p><br /></p>
<p>While the api3() function is correctly gone, the result for the C-string is the following (in Hopper):</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p class="p1"><span class="Apple-converted-space">        </span>; Section .rodata.str1.1</p>
<p class="p1"><span class="Apple-converted-space">        </span>; Range: [0x63; 0x6f[ (12 bytes)</p>
<p class="p1"><span class="Apple-converted-space">        </span>; File offset : [151; 163[ (12 bytes)</p>
<p class="p1"><span class="Apple-converted-space">        </span>; Flags: 0x32</p>
<p class="p1"><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHT_PROGBITS</p>
<p class="p1"><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHF_ALLOC</p>
<p class="p2"> </p>
<p class="p3"><span class="Apple-converted-space">             </span><span class="s1">.L.str</span>:</p>
<p class="p4"><span class="s2">00000063</span><span class="s3"> <span class="Apple-converted-space">        </span>db <span class="Apple-converted-space">        </span></span>"Test"<span class="s3">, </span><span class="s2">0</span></p>
<p class="p3"><span class="Apple-converted-space">             </span><span class="s1">.L.str.1</span>:</p>
<p class="p3"><span class="s2">00000068</span> <span class="Apple-converted-space">        </span>db <span class="Apple-converted-space">        </span><span class="s4">"Unused"</span>, <span class="s2">0</span></p>
</blockquote>
<p><br /></p>

</body></html>