[cfi] Implement cfi-icall using inline assembly.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 11 Nov 2016 18:49:09 +0000 (18:49 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 11 Nov 2016 18:49:09 +0000 (18:49 +0000)
commitf48ffab554fa77306246eaac63970d53229b0c0d
tree6ba0f0313f89f1b277f04e6a72209dcd5d8fd51a
parent6285f5b441bf602319c2bc3b4ed04a1450aa8247
[cfi] Implement cfi-icall using inline assembly.

The current implementation is emitting a global constant that happens
to evaluate to the same bytes + relocation as a jump instruction on
X86. This does not work for PIE executables and shared libraries
though, because we end up with a wrong relocation type. And it has no
chance of working on ARM/AArch64 which use different relocation types
for jump instructions (R_ARM_JUMP24) that is never generated for
data.

This change replaces the constant with module-level inline assembly
followed by a hidden declaration of the jump table. Works fine for
ARM/AArch64, but has some drawbacks.
* Extra symbols are added to the static symbol table, which inflate
the size of the unstripped binary a little. Stripped binaries are not
affected. This happens because jump table declarations must be
external (because their body is in the inline asm).
* Original functions that were anonymous are now named
<original name>.cfi, and it affects symbolization sometimes. This is
necessary because the only user of these functions is the (inline
asm) jump table, so they had to be added to @llvm.used, which does
not allow unnamed functions.

llvm-svn: 286611
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/test/Transforms/LowerTypeTests/function-disjoint.ll
llvm/test/Transforms/LowerTypeTests/function-ext.ll
llvm/test/Transforms/LowerTypeTests/function.ll
llvm/test/Transforms/LowerTypeTests/section.ll