<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jun 5, 2015, at 6:45 PM, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:</div><blockquote type="cite"><blockquote class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr"><br class="Apple-interchange-newline">- Dont halt the linker operation if there are undefined symbols but they are not called from the root set (Do garbage collection and then report whether symbols are really undefined)<br></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Dead-stripping is done after eliminating duplicate COMDAT symbols. Unreferenced symbols are naturally ignored.</div></blockquote><br></div><div>Global symbols that did not make it into the final symbol table (because of coalescing or group COMDAT), are easy to discard.</div><div><br></div><div>But, darwin supports “dead code stripping”.  The way it works is you start with atoms (symbols) that must be preserved (for an executable program, that would be “main”), mark them live then start recursively marking live the atoms they reference.  In order to do this, you must parse the relocations to and figure out: 1) which function/data each relocation applies to, and 2) what function/data each relocation references.  </div><div><br></div><div>A couple interesting points:</div><div>a) The master symbol table does not help with dead code stripping because often functions/data are static or anonymous and thus are not in the master symbol table.</div><div>b) It is ok for dead code to reference undefined symbols, since the dead code will be stripped away.  The resolver phase normally ends when there are no undefined symbols remaining or with an error about undefined symbols.  But with dead stripping, it is not an error to end with undefined symbols.</div><div>c) Once the dead code is identified, any symbols the dead code added to the master symbol table need to be removed.</div><div><br></div><div>-Nick</div><div><br></div></body></html>