<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - lld/mac doesn't dedupe CFSTR()s"
   href="https://bugs.llvm.org/show_bug.cgi?id=51939">51939</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld/mac doesn't dedupe CFSTR()s
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>MachO
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>gkm@fb.com, jezreel@gmail.com, llvm-bugs@lists.llvm.org, smeenai@fb.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>% cat cf1.cc
#include <CoreFoundation/CoreFoundation.h>
void f();
int main() {
  f();
  CFShow(CFSTR("Hello"));
}

% cat cf2.cc
#include <CoreFoundation/CoreFoundation.h>

void f() {
  CFShow(CFSTR("Hello"));
}

% clang -c cf1.cc cf2.cc



CFSTR() gets transformed into __builtin___CFStringMakeConstantString(), which
gets compiled into something like:


        .section        __TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
        .asciz  "Hello"

        .section        __DATA,__cfstring
        .p2align        3               ## @_unnamed_cfstring_
L__unnamed_cfstring_:
        .quad   ___CFConstantStringClassReference
        .long   1992                    ## 0x7c8
        .space  4
        .quad   L_.str
        .quad   5                       ## 0x5





lld keeps two copies of that (it manages to dedup the "Hello" C string, but not
the CFStr):


% out/gn/bin/clang cf1.o cf2.o -framework CoreFoundation -fuse-ld=lld
-Wl,--deduplicate-literals -Wl,--icf=all
% xxd a.out | grep c807
00002010: c807 0000 0000 0000 ea06 0000 0100 0000  ................
00002030: c807 0000 0000 0000 ea06 0000 0100 0000  ................


ld64 gets it right:

% out/gn/bin/clang cf1.o cf2.o -framework CoreFoundation
% xxd a.out | grep c807
00004010: c807 0000 0000 0000 a63f 0000 0100 0000  .........?......




I vaguely remember Jez mentioning somewhere that he's aware of this (but I
might be making this up, not sure), but I didn't find an existing bug for it.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>