Previously cfi_check was created in LTO optimization pipeline, which
means LLD has no way of knowing about the existence of this symbol
without rescanning the LTO output object. As a result, LLD fails to
export cfi_check, even when given --export-dynamic-symbol flag.
Details
- Reviewers
pcc
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
2786 | Please add a comment explaining why we are creating this function. | |
2788 | What will happen in the CrossDSOCFI pass if it is given a module with this function definition? It looks like it will append its basic blocks to the end of the definition. Because the entry block you are creating here returns immediately, all of the blocks it adds will be unreachable. Probably the easiest thing to do is to change CrossDSOCFI to replace any __cfi_check definition it sees with its own definition. | |
2790 | Although this linkage may prevent inlining for now, we may in the future change the LTO implementation to promote weak functions to strong if the linker knows that a particular definition of a symbol is the final definition for the symbol. That will mean that this dummy definition may be inlined into callers. This is a largely theoretical problem because we never create a direct call to the __cfi_check function. But if we wanted to fix this I can imagine creating an intrinsic that the CrossDSOCFI pass expands to the definition of __cfi_check. | |
2885 | remove this line |
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
2788 | I suppose that would work for now, but what the CrossDSOCFI pass is doing seems a little hackish because it will crash if the type of the existing definition (or declaration) does not exactly match the expected type. | |
2790 | I mean basically that Clang would create a definition like this: define void @__cfi_check(i64 %0, i8* %1, i8* %2) { call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2) ret void } and CrossDSOCFI would find all calls to @llvm.cfi_check and replace them with the code that the pass currently generates as the body of __cfi_check. |
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
2790 | Ah, that definitely makes sense. Let's mention this in a comment for now. |
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
2790 | Works for me. |
LGTM
lib/CodeGen/CGExpr.cpp | ||
---|---|---|
2798 | I would terminate this definition in an llvm.trap so that the program will crash if this definition were to survive LTO for some reason. |
Please add a comment explaining why we are creating this function.