[PATCH] Prevent user-supplied libc implementations from premature removal in LTO

Duncan Exon Smith dexonsmith at apple.com
Mon Nov 4 10:56:35 PST 2013


This patch adds C runtime library functions to llvm.compiler.used during -internalize.  Since some transformations in -instcombine introduce new runtime library calls (e.g., by optimizing printf => puts), and some llvm intrinsics are lowered to runtime library calls (e.g., llvm.memset => memset), then it’s dangerous to discard any runtime library functions during optimizations.

Adding internalized runtime library functions to llvm.compiler.used keeps them safe.  We still want internal linkage so that if these calls are truly unused, an intelligent linker can remove them (e.g., with -dead_strip).

This is a particular problem when linking statically against user-supplied runtime libraries.

Note: there’s a related problem with calls into compiler-rt that are added during instruction lowering (e.g., calls to __divdi3).  TargetLibraryInfo doesn’t know about any of those, so this patch does not address those cases.

<rdar://problem/14740087>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: internalize-runtime_libraries.patch
Type: application/octet-stream
Size: 6236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131104/4dd0b8f5/attachment.obj>


More information about the llvm-commits mailing list