OLD | NEW |
1 //===- ExpandCtors.cpp - Convert ctors/dtors to concrete arrays -----------===// | 1 //===- ExpandCtors.cpp - Convert ctors/dtors to concrete arrays -----------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This pass converts LLVM's special symbols llvm.global_ctors and | 10 // This pass converts LLVM's special symbols llvm.global_ctors and |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 NewArray->setName(StartSymbol); | 128 NewArray->setName(StartSymbol); |
129 | 129 |
130 // We replace "__{init,fini}_array_end" with the address of the end | 130 // We replace "__{init,fini}_array_end" with the address of the end |
131 // of NewArray. This removes the name "__{init,fini}_array_end" | 131 // of NewArray. This removes the name "__{init,fini}_array_end" |
132 // from the output, which is not ideal for debugging. Ideally we | 132 // from the output, which is not ideal for debugging. Ideally we |
133 // would convert "__{init,fini}_array_end" to being a GlobalAlias | 133 // would convert "__{init,fini}_array_end" to being a GlobalAlias |
134 // that points to the end of the array. However, unfortunately LLVM | 134 // that points to the end of the array. However, unfortunately LLVM |
135 // does not generate correct code when a GlobalAlias contains a | 135 // does not generate correct code when a GlobalAlias contains a |
136 // GetElementPtr ConstantExpr. | 136 // GetElementPtr ConstantExpr. |
137 Constant *NewArrayEnd = | 137 Constant *NewArrayEnd = |
138 ConstantExpr::getGetElementPtr(NewArray, | 138 ConstantExpr::getGetElementPtr(ArrayTy, NewArray, |
139 ConstantInt::get(M.getContext(), | 139 ConstantInt::get(M.getContext(), |
140 APInt(32, 1))); | 140 APInt(32, 1))); |
141 setGlobalVariableValue(M, EndSymbol, NewArrayEnd); | 141 setGlobalVariableValue(M, EndSymbol, NewArrayEnd); |
142 } | 142 } |
143 | 143 |
144 bool ExpandCtors::runOnModule(Module &M) { | 144 bool ExpandCtors::runOnModule(Module &M) { |
145 defineFuncArray(M, "llvm.global_ctors", | 145 defineFuncArray(M, "llvm.global_ctors", |
146 "__init_array_start", "__init_array_end"); | 146 "__init_array_start", "__init_array_end"); |
147 defineFuncArray(M, "llvm.global_dtors", | 147 defineFuncArray(M, "llvm.global_dtors", |
148 "__fini_array_start", "__fini_array_end"); | 148 "__fini_array_start", "__fini_array_end"); |
149 return true; | 149 return true; |
150 } | 150 } |
151 | 151 |
152 ModulePass *llvm::createExpandCtorsPass() { | 152 ModulePass *llvm::createExpandCtorsPass() { |
153 return new ExpandCtors(); | 153 return new ExpandCtors(); |
154 } | 154 } |
OLD | NEW |