- if (const char *UsedDirective = TAI->getUsedDirective())
- O << UsedDirective << EHFrameInfo.FnName << "\n\n";
+ // If the function is marked used, this table should be also. We cannot
+ // make the mark unconditional in this case, since retaining the table
+ // also retains the function in this case, and there is code around
+ // that depends on unused functions (calling undefined externals) being
+ // dead-stripped to link correctly. Yes, there really is.
+ if (MMI->getUsedFunctions().count(EHFrameInfo.function))
+ if (const char *UsedDirective = TAI->getUsedDirective())
+ O << UsedDirective << EHFrameInfo.FnName << "\n\n";
+ }