[PATCH] D64962: appendToGlobalCtors: allow for llvm.global_ctors functions of varying type

Anthony Eden via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 16:51:29 PDT 2019


aeden created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When calling global constructor functions, the dynamic linker may pass arguments without breaking the ABI, such as (argc, argv, envp) in the case of glibc.

The utility function llvm::appendToGlobalCtors accepts a pointer to an llvm::Function, but if it is not of the type FunctionType::get(IRB.getVoidTy(), false), then the resulting LLVM IR will be invalid, possibly leading to a "LLVM constant table mismatch" error in the future.


Repository:
  rL LLVM

https://reviews.llvm.org/D64962

Files:
  lib/Transforms/Utils/ModuleUtils.cpp


Index: lib/Transforms/Utils/ModuleUtils.cpp
===================================================================
--- lib/Transforms/Utils/ModuleUtils.cpp
+++ lib/Transforms/Utils/ModuleUtils.cpp
@@ -42,7 +42,7 @@
   // Build a 3 field global_ctor entry.  We don't take a comdat key.
   Constant *CSVals[3];
   CSVals[0] = IRB.getInt32(Priority);
-  CSVals[1] = F;
+  CSVals[1] = ConstantExpr::getBitCast(F, FnTy);
   CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getInt8PtrTy())
                    : Constant::getNullValue(IRB.getInt8PtrTy());
   Constant *RuntimeCtorInit =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64962.210704.patch
Type: text/x-patch
Size: 587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190718/cb6b107a/attachment.bin>


More information about the llvm-commits mailing list