<div>Hello list,</div><div><br></div><div>I'm wondering about the feasibility of collapsing the following two globals within llvm-link:</div><div><br></div><div>@"OBJC_CLASSLIST_REFERENCES_$_2" = private global %struct.objc_class* bitcast (%struct._class_t* @"OBJC_CLASS_$_NSString" to %struct.objc_class*), section "__DATA, __objc_classrefs, regular, no_dead_strip", align 4</div>

<div>@"OBJC_CLASSLIST_REFERENCES_$_8" = private global %struct.objc_class* bitcast (%struct._class_t* @"OBJC_CLASS_$_NSString" to %struct.objc_class*), section "__DATA, __objc_classrefs, regular, no_dead_strip", align 4</div>

<div><br></div><div>The reason we'd like to do it in llvm-link is because the Mach-O linker isn't doing it for us, and instead giving us the following error when we try to link:</div><div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">

ld: in /var/folders/q7/q7f3KCNoGkOtsKthZvb6LJWOlJU/-Tmp-//ccjnT818.o, __objc_classrefs element missing reloc (count=2) for target class in /var/folders/q7/q7f3KCNoGkOtsKthZvb6LJWOlJU/-Tmp-//ccjnT818.o</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo">collect2: ld returned 1 exit status</p></div><div><br></div><div>The code that generates this error (from ld.cpp) is here:</div><div><br></div><div>template <typename A></div>

<div>void AnonymousAtom<A>::resolveName()</div><div>{</div><div>/*some code omitted*/</div><div>   else if ( (strncmp(fSection->sectname(),  "__objc_classrefs", 16) == 0) && (strcmp(fSection->segname(), "__DATA") == 0) ) {</div>

<div><div>                std::vector<ObjectFile::Reference*>& references = this->getReferences();</div><div>                if ( references.size() != 1 )</div><div>                        throwf("__objc_classrefs element missing reloc (count=%ld) for target class in %s", references.size(), fOwner.getPath());</div>

<div>                const char* targetName = references[0]->getTargetName();</div><div>                if ( strncmp(targetName, "_OBJC_CLASS_$_", 14) == 0 )</div><div>                        asprintf((char**)&fSynthesizedName, "objc-class-ref-to-%s", &targetName[14]);</div>

<div>                else</div><div>                        asprintf((char**)&fSynthesizedName, "objc-class-ref-to-%s", targetName);</div><div>        }</div></div><div>}</div><div><br></div><div><div>The Mach-O linker knows how to do the collapsing, but does not do it.  It doesn't do it (seemingly) because we remove the .subsections_via_symbols assembly directive from the .s file generated by llc.  We removed this directive at the recommendation of Apple support, because the linker was shuffling our code in a way that broke it.  (We insert labels in the middle of instruction streams, that aren't referenced by anything else).  I can't for the life of me find the code in the linker that does the collapsing; all I know is that it isn't doing it.</div>

</div><div><br></div><div>I'm also open to other suggestions from the list on how to work around this issue.  Basically, it seems like I need to collapse these two references somewhere, either in llvm-link or by hand-editting the assembly file.  Does anyone have any insight or advice on how to work around this linker limitation?  Thanks in advance.</div>

<div><br></div><div>Nathan McCauley</div><div>Arxan Technologies</div><div><br></div><div><br></div><div><br></div><div><br></div>