[llvm-bugs] [Bug 51939] New: lld/mac doesn't dedupe CFSTR()s

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 22 08:39:27 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51939

            Bug ID: 51939
           Summary: lld/mac doesn't dedupe CFSTR()s
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: MachO
          Assignee: unassignedbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: gkm at fb.com, jezreel at gmail.com,
                    llvm-bugs at lists.llvm.org, smeenai at fb.com

% 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210922/7f2ee648/attachment.html>


More information about the llvm-bugs mailing list