Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/TargetLoweringObjectFile.cpp @ 100:7d135dc70f03 LLVM 3.9
LLVM 3.9
author | Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Jan 2016 22:53:40 +0900 |
parents | afa8332a0e37 |
children | 1172e4bd9c6f |
comparison
equal
deleted
inserted
replaced
96:6418606d0ead | 100:7d135dc70f03 |
---|---|
167 // a mergable string section, or general .data if it contains relocations. | 167 // a mergable string section, or general .data if it contains relocations. |
168 if (GVar->isConstant()) { | 168 if (GVar->isConstant()) { |
169 // If the initializer for the global contains something that requires a | 169 // If the initializer for the global contains something that requires a |
170 // relocation, then we may have to drop this into a writable data section | 170 // relocation, then we may have to drop this into a writable data section |
171 // even though it is marked const. | 171 // even though it is marked const. |
172 switch (C->getRelocationInfo()) { | 172 if (!C->needsRelocation()) { |
173 case Constant::NoRelocation: | |
174 // If the global is required to have a unique address, it can't be put | 173 // If the global is required to have a unique address, it can't be put |
175 // into a mergable section: just drop it into the general read-only | 174 // into a mergable section: just drop it into the general read-only |
176 // section instead. | 175 // section instead. |
177 if (!GVar->hasUnnamedAddr()) | 176 if (!GVar->hasUnnamedAddr()) |
178 return SectionKind::getReadOnly(); | 177 return SectionKind::getReadOnly(); |
179 | 178 |
180 // If initializer is a null-terminated string, put it in a "cstring" | 179 // If initializer is a null-terminated string, put it in a "cstring" |
181 // section of the right width. | 180 // section of the right width. |
182 if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { | 181 if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { |
183 if (IntegerType *ITy = | 182 if (IntegerType *ITy = |
184 dyn_cast<IntegerType>(ATy->getElementType())) { | 183 dyn_cast<IntegerType>(ATy->getElementType())) { |
205 case 16: return SectionKind::getMergeableConst16(); | 204 case 16: return SectionKind::getMergeableConst16(); |
206 default: | 205 default: |
207 return SectionKind::getReadOnly(); | 206 return SectionKind::getReadOnly(); |
208 } | 207 } |
209 | 208 |
210 case Constant::LocalRelocation: | 209 } else { |
211 // In static relocation model, the linker will resolve all addresses, so | 210 // In static relocation model, the linker will resolve all addresses, so |
212 // the relocation entries will actually be constants by the time the app | 211 // the relocation entries will actually be constants by the time the app |
213 // starts up. However, we can't put this into a mergable section, because | 212 // starts up. However, we can't put this into a mergable section, because |
214 // the linker doesn't take relocations into consideration when it tries to | 213 // the linker doesn't take relocations into consideration when it tries to |
215 // merge entries in the section. | 214 // merge entries in the section. |
216 if (ReloModel == Reloc::Static) | 215 if (ReloModel == Reloc::Static) |
217 return SectionKind::getReadOnly(); | 216 return SectionKind::getReadOnly(); |
218 | 217 |
219 // Otherwise, the dynamic linker needs to fix it up, put it in the | 218 // Otherwise, the dynamic linker needs to fix it up, put it in the |
220 // writable data.rel.local section. | |
221 return SectionKind::getReadOnlyWithRelLocal(); | |
222 | |
223 case Constant::GlobalRelocations: | |
224 // In static relocation model, the linker will resolve all addresses, so | |
225 // the relocation entries will actually be constants by the time the app | |
226 // starts up. However, we can't put this into a mergable section, because | |
227 // the linker doesn't take relocations into consideration when it tries to | |
228 // merge entries in the section. | |
229 if (ReloModel == Reloc::Static) | |
230 return SectionKind::getReadOnly(); | |
231 | |
232 // Otherwise, the dynamic linker needs to fix it up, put it in the | |
233 // writable data.rel section. | 219 // writable data.rel section. |
234 return SectionKind::getReadOnlyWithRel(); | 220 return SectionKind::getReadOnlyWithRel(); |
235 } | 221 } |
236 } | 222 } |
237 | 223 |
239 // to require a runtime relocation by the dynamic linker, put it into a more | 225 // to require a runtime relocation by the dynamic linker, put it into a more |
240 // specific section to improve startup time of the app. This coalesces these | 226 // specific section to improve startup time of the app. This coalesces these |
241 // globals together onto fewer pages, improving the locality of the dynamic | 227 // globals together onto fewer pages, improving the locality of the dynamic |
242 // linker. | 228 // linker. |
243 if (ReloModel == Reloc::Static) | 229 if (ReloModel == Reloc::Static) |
244 return SectionKind::getDataNoRel(); | 230 return SectionKind::getData(); |
245 | 231 |
246 switch (C->getRelocationInfo()) { | 232 if (C->needsRelocation()) |
247 case Constant::NoRelocation: | 233 return SectionKind::getData(); |
248 return SectionKind::getDataNoRel(); | 234 return SectionKind::getData(); |
249 case Constant::LocalRelocation: | |
250 return SectionKind::getDataRelLocal(); | |
251 case Constant::GlobalRelocations: | |
252 return SectionKind::getDataRel(); | |
253 } | |
254 llvm_unreachable("Invalid relocation"); | |
255 } | 235 } |
256 | 236 |
257 /// This method computes the appropriate section to emit the specified global | 237 /// This method computes the appropriate section to emit the specified global |
258 /// variable or function definition. This should not be passed external (or | 238 /// variable or function definition. This should not be passed external (or |
259 /// available externally) globals. | 239 /// available externally) globals. |
342 // null return could mean 'no location' & we should just do that here. | 322 // null return could mean 'no location' & we should just do that here. |
343 return MCSymbolRefExpr::create(Sym, *Ctx); | 323 return MCSymbolRefExpr::create(Sym, *Ctx); |
344 } | 324 } |
345 | 325 |
346 void TargetLoweringObjectFile::getNameWithPrefix( | 326 void TargetLoweringObjectFile::getNameWithPrefix( |
347 SmallVectorImpl<char> &OutName, const GlobalValue *GV, | 327 SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang, |
348 bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const { | 328 const TargetMachine &TM) const { |
349 Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel); | 329 Mang.getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false); |
350 } | 330 } |