Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 1 | //===-LTOModule.cpp - LLVM Link Time Optimizer ----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Link Time Optimization library. This library is |
| 11 | // intended to be used by linker to optimize code at link time. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 15 | #include "LTOModule.h" |
| 16 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 18 | #include "llvm/ModuleProvider.h" |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/OwningPtr.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 20 | #include "llvm/Bitcode/ReaderWriter.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 21 | #include "llvm/Support/SystemUtils.h" |
| 22 | #include "llvm/Support/Mangler.h" |
| 23 | #include "llvm/Support/MemoryBuffer.h" |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 24 | #include "llvm/Support/MathExtras.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 25 | #include "llvm/System/Path.h" |
Nick Kledzik | 90dcff7 | 2008-05-09 01:09:59 +0000 | [diff] [blame] | 26 | #include "llvm/System/Process.h" |
Bill Wendling | 604a818 | 2008-06-18 06:35:30 +0000 | [diff] [blame] | 27 | #include "llvm/Target/SubtargetFeature.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetMachine.h" |
| 29 | #include "llvm/Target/TargetMachineRegistry.h" |
| 30 | #include "llvm/Target/TargetAsmInfo.h" |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 31 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 32 | #include <fstream> |
| 33 | |
| 34 | using namespace llvm; |
| 35 | |
| 36 | bool LTOModule::isBitcodeFile(const void* mem, size_t length) |
| 37 | { |
| 38 | return ( llvm::sys::IdentifyFileType((char*)mem, length) |
| 39 | == llvm::sys::Bitcode_FileType ); |
| 40 | } |
| 41 | |
| 42 | bool LTOModule::isBitcodeFile(const char* path) |
| 43 | { |
| 44 | return llvm::sys::Path(path).isBitcodeFile(); |
| 45 | } |
| 46 | |
Chris Lattner | 038112a | 2008-04-01 18:04:03 +0000 | [diff] [blame] | 47 | bool LTOModule::isBitcodeFileForTarget(const void* mem, size_t length, |
| 48 | const char* triplePrefix) |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 49 | { |
Nick Kledzik | 90dcff7 | 2008-05-09 01:09:59 +0000 | [diff] [blame] | 50 | MemoryBuffer* buffer = makeBuffer(mem, length); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 51 | if ( buffer == NULL ) |
| 52 | return false; |
| 53 | return isTargetMatch(buffer, triplePrefix); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 56 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 57 | bool LTOModule::isBitcodeFileForTarget(const char* path, |
Chris Lattner | 038112a | 2008-04-01 18:04:03 +0000 | [diff] [blame] | 58 | const char* triplePrefix) |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 59 | { |
Chris Lattner | 038112a | 2008-04-01 18:04:03 +0000 | [diff] [blame] | 60 | MemoryBuffer *buffer = MemoryBuffer::getFile(path); |
| 61 | if (buffer == NULL) |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 62 | return false; |
| 63 | return isTargetMatch(buffer, triplePrefix); |
| 64 | } |
| 65 | |
| 66 | // takes ownership of buffer |
| 67 | bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix) |
| 68 | { |
| 69 | OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer)); |
| 70 | // on success, mp owns buffer and both are deleted at end of this method |
| 71 | if ( !mp ) { |
| 72 | delete buffer; |
| 73 | return false; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 74 | } |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 75 | std::string actualTarget = mp->getModule()->getTargetTriple(); |
| 76 | return ( strncmp(actualTarget.c_str(), triplePrefix, |
| 77 | strlen(triplePrefix)) == 0); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | LTOModule::LTOModule(Module* m, TargetMachine* t) |
| 82 | : _module(m), _target(t), _symbolsParsed(false) |
| 83 | { |
| 84 | } |
| 85 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 86 | LTOModule* LTOModule::makeLTOModule(const char* path, std::string& errMsg) |
| 87 | { |
Chris Lattner | 038112a | 2008-04-01 18:04:03 +0000 | [diff] [blame] | 88 | OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg)); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 89 | if ( !buffer ) |
| 90 | return NULL; |
| 91 | return makeLTOModule(buffer.get(), errMsg); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Nick Kledzik | 6b89d92 | 2008-05-09 18:44:41 +0000 | [diff] [blame] | 94 | /// makeBuffer - create a MemoryBuffer from a memory range. |
| 95 | /// MemoryBuffer requires the byte past end of the buffer to be a zero. |
| 96 | /// We might get lucky and already be that way, otherwise make a copy. |
| 97 | /// Also if next byte is on a different page, don't assume it is readable. |
Nick Kledzik | 90dcff7 | 2008-05-09 01:09:59 +0000 | [diff] [blame] | 98 | MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length) |
| 99 | { |
Nick Kledzik | ed185d6 | 2008-05-28 00:06:14 +0000 | [diff] [blame] | 100 | const char* startPtr = (char*)mem; |
| 101 | const char* endPtr = startPtr+length; |
| 102 | if ( (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0) |
| 103 | || (*endPtr != 0) ) |
| 104 | return MemoryBuffer::getMemBufferCopy(startPtr, endPtr); |
| 105 | else |
| 106 | return MemoryBuffer::getMemBuffer(startPtr, endPtr); |
Nick Kledzik | 90dcff7 | 2008-05-09 01:09:59 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 110 | LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length, |
| 111 | std::string& errMsg) |
| 112 | { |
Nick Kledzik | 90dcff7 | 2008-05-09 01:09:59 +0000 | [diff] [blame] | 113 | OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length)); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 114 | if ( !buffer ) |
| 115 | return NULL; |
| 116 | return makeLTOModule(buffer.get(), errMsg); |
| 117 | } |
| 118 | |
Bill Wendling | e424254 | 2008-06-18 21:39:02 +0000 | [diff] [blame] | 119 | /// getFeatureString - Return a string listing the features associated with the |
| 120 | /// target triple. |
| 121 | /// |
| 122 | /// FIXME: This is an inelegant way of specifying the features of a |
| 123 | /// subtarget. It would be better if we could encode this information into the |
| 124 | /// IR. See <rdar://5972456>. |
| 125 | std::string getFeatureString(const char *TargetTriple) { |
| 126 | SubtargetFeatures Features; |
| 127 | |
| 128 | if (strncmp(TargetTriple, "powerpc-apple-", 14) == 0) { |
| 129 | Features.AddFeature("altivec", true); |
| 130 | } else if (strncmp(TargetTriple, "powerpc64-apple-", 16) == 0) { |
| 131 | Features.AddFeature("64bit", true); |
| 132 | Features.AddFeature("altivec", true); |
| 133 | } |
| 134 | |
| 135 | return Features.getString(); |
| 136 | } |
| 137 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 138 | LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg) |
| 139 | { |
| 140 | // parse bitcode buffer |
| 141 | OwningPtr<Module> m(ParseBitcodeFile(buffer, &errMsg)); |
| 142 | if ( !m ) |
| 143 | return NULL; |
| 144 | // find machine architecture for this module |
| 145 | const TargetMachineRegistry::entry* march = |
| 146 | TargetMachineRegistry::getClosestStaticTargetForModule(*m, errMsg); |
Bill Wendling | 604a818 | 2008-06-18 06:35:30 +0000 | [diff] [blame] | 147 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 148 | if ( march == NULL ) |
| 149 | return NULL; |
Bill Wendling | 604a818 | 2008-06-18 06:35:30 +0000 | [diff] [blame] | 150 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 151 | // construct LTModule, hand over ownership of module and target |
Bill Wendling | e424254 | 2008-06-18 21:39:02 +0000 | [diff] [blame] | 152 | std::string FeatureStr = getFeatureString(m->getTargetTriple().c_str()); |
| 153 | TargetMachine* target = march->CtorFn(*m, FeatureStr); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 154 | return new LTOModule(m.take(), target); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | const char* LTOModule::getTargetTriple() |
| 159 | { |
| 160 | return _module->getTargetTriple().c_str(); |
| 161 | } |
| 162 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 163 | void LTOModule::addDefinedFunctionSymbol(Function* f, Mangler &mangler) |
| 164 | { |
| 165 | // add to list of defined symbols |
| 166 | addDefinedSymbol(f, mangler, true); |
| 167 | |
| 168 | // add external symbols referenced by this function. |
| 169 | for (Function::iterator b = f->begin(); b != f->end(); ++b) { |
| 170 | for (BasicBlock::iterator i = b->begin(); i != b->end(); ++i) { |
| 171 | for (unsigned count = 0, total = i->getNumOperands(); |
| 172 | count != total; ++count) { |
| 173 | findExternalRefs(i->getOperand(count), mangler); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void LTOModule::addDefinedDataSymbol(GlobalValue* v, Mangler &mangler) |
| 180 | { |
| 181 | // add to list of defined symbols |
| 182 | addDefinedSymbol(v, mangler, false); |
| 183 | |
| 184 | // add external symbols referenced by this data. |
Nick Kledzik | 9178a65 | 2008-05-27 22:07:08 +0000 | [diff] [blame] | 185 | for (unsigned count = 0, total = v->getNumOperands(); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 186 | count != total; ++count) { |
| 187 | findExternalRefs(v->getOperand(count), mangler); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 192 | void LTOModule::addDefinedSymbol(GlobalValue* def, Mangler &mangler, |
| 193 | bool isFunction) |
| 194 | { |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 195 | // string is owned by _defines |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 196 | const char* symbolName = ::strdup(mangler.getValueName(def).c_str()); |
| 197 | |
| 198 | // set alignment part log2() can have rounding errors |
| 199 | uint32_t align = def->getAlignment(); |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 200 | uint32_t attr = align ? CountTrailingZeros_32(def->getAlignment()) : 0; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 201 | |
| 202 | // set permissions part |
| 203 | if ( isFunction ) |
| 204 | attr |= LTO_SYMBOL_PERMISSIONS_CODE; |
| 205 | else { |
| 206 | GlobalVariable* gv = dyn_cast<GlobalVariable>(def); |
| 207 | if ( (gv != NULL) && gv->isConstant() ) |
| 208 | attr |= LTO_SYMBOL_PERMISSIONS_RODATA; |
| 209 | else |
| 210 | attr |= LTO_SYMBOL_PERMISSIONS_DATA; |
| 211 | } |
| 212 | |
| 213 | // set definition part |
| 214 | if ( def->hasWeakLinkage() || def->hasLinkOnceLinkage() ) { |
Dale Johannesen | ed1ec3a | 2008-05-23 00:15:10 +0000 | [diff] [blame] | 215 | attr |= LTO_SYMBOL_DEFINITION_WEAK; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 216 | } |
Dale Johannesen | 6a6f2dd | 2008-05-16 22:46:40 +0000 | [diff] [blame] | 217 | else if ( def->hasCommonLinkage()) { |
| 218 | attr |= LTO_SYMBOL_DEFINITION_TENTATIVE; |
| 219 | } |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 220 | else { |
| 221 | attr |= LTO_SYMBOL_DEFINITION_REGULAR; |
| 222 | } |
| 223 | |
| 224 | // set scope part |
| 225 | if ( def->hasHiddenVisibility() ) |
| 226 | attr |= LTO_SYMBOL_SCOPE_HIDDEN; |
Devang Patel | f0d286b | 2008-07-15 00:00:11 +0000 | [diff] [blame] | 227 | else if ( def->hasExternalLinkage() || def->hasWeakLinkage() |
| 228 | || def->hasLinkOnceLinkage() ) |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 229 | attr |= LTO_SYMBOL_SCOPE_DEFAULT; |
| 230 | else |
| 231 | attr |= LTO_SYMBOL_SCOPE_INTERNAL; |
| 232 | |
| 233 | // add to table of symbols |
| 234 | NameAndAttributes info; |
| 235 | info.name = symbolName; |
| 236 | info.attributes = (lto_symbol_attributes)attr; |
| 237 | _symbols.push_back(info); |
| 238 | _defines[info.name] = 1; |
| 239 | } |
| 240 | |
Devang Patel | c2aec57 | 2008-07-16 18:06:52 +0000 | [diff] [blame] | 241 | void LTOModule::addAsmGlobalSymbol(const char *name) { |
| 242 | // string is owned by _defines |
| 243 | const char *symbolName = ::strdup(name); |
| 244 | uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR; |
| 245 | attr |= LTO_SYMBOL_SCOPE_DEFAULT; |
| 246 | |
| 247 | // add to table of symbols |
| 248 | NameAndAttributes info; |
| 249 | info.name = symbolName; |
| 250 | info.attributes = (lto_symbol_attributes)attr; |
| 251 | _symbols.push_back(info); |
| 252 | _defines[info.name] = 1; |
| 253 | } |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 254 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 255 | void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler) |
| 256 | { |
| 257 | const char* name = mangler.getValueName(decl).c_str(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 258 | // ignore all llvm.* symbols |
| 259 | if ( strncmp(name, "llvm.", 5) != 0 ) { |
| 260 | _undefines[name] = 1; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | |
| 265 | |
| 266 | // Find exeternal symbols referenced by VALUE. This is a recursive function. |
| 267 | void LTOModule::findExternalRefs(Value* value, Mangler &mangler) { |
| 268 | |
| 269 | if (GlobalValue* gv = dyn_cast<GlobalValue>(value)) { |
| 270 | if ( !gv->hasExternalLinkage() ) |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 271 | addPotentialUndefinedSymbol(gv, mangler); |
Nick Kledzik | ed185d6 | 2008-05-28 00:06:14 +0000 | [diff] [blame] | 272 | // If this is a variable definition, do not recursively process |
| 273 | // initializer. It might contain a reference to this variable |
| 274 | // and cause an infinite loop. The initializer will be |
| 275 | // processed in addDefinedDataSymbol(). |
| 276 | return; |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 277 | } |
Nick Kledzik | ed185d6 | 2008-05-28 00:06:14 +0000 | [diff] [blame] | 278 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 279 | // GlobalValue, even with InternalLinkage type, may have operands with |
| 280 | // ExternalLinkage type. Do not ignore these operands. |
| 281 | if (Constant* c = dyn_cast<Constant>(value)) { |
| 282 | // Handle ConstantExpr, ConstantStruct, ConstantArry etc.. |
| 283 | for (unsigned i = 0, e = c->getNumOperands(); i != e; ++i) |
| 284 | findExternalRefs(c->getOperand(i), mangler); |
| 285 | } |
| 286 | } |
| 287 | |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 288 | void LTOModule::lazyParseSymbols() |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 289 | { |
| 290 | if ( !_symbolsParsed ) { |
| 291 | _symbolsParsed = true; |
| 292 | |
| 293 | // Use mangler to add GlobalPrefix to names to match linker names. |
| 294 | Mangler mangler(*_module, _target->getTargetAsmInfo()->getGlobalPrefix()); |
| 295 | |
| 296 | // add functions |
| 297 | for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 298 | if ( f->isDeclaration() ) |
| 299 | addPotentialUndefinedSymbol(f, mangler); |
| 300 | else |
| 301 | addDefinedFunctionSymbol(f, mangler); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // add data |
| 305 | for (Module::global_iterator v = _module->global_begin(), |
| 306 | e = _module->global_end(); v != e; ++v) { |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 307 | if ( v->isDeclaration() ) |
| 308 | addPotentialUndefinedSymbol(v, mangler); |
| 309 | else |
| 310 | addDefinedDataSymbol(v, mangler); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Devang Patel | c2aec57 | 2008-07-16 18:06:52 +0000 | [diff] [blame] | 313 | // add asm globals |
| 314 | const std::string &inlineAsm = _module->getModuleInlineAsm(); |
| 315 | const std::string glbl = ".globl"; |
| 316 | std::string asmSymbolName; |
| 317 | std::string::size_type pos = inlineAsm.find(glbl, 0); |
| 318 | while (pos != std::string::npos) { |
| 319 | // eat .globl |
| 320 | pos = pos + 6; |
| 321 | |
| 322 | // skip white space between .globl and symbol name |
| 323 | std::string::size_type pbegin = inlineAsm.find_first_not_of(' ', pos); |
| 324 | if (pbegin == std::string::npos) |
| 325 | break; |
| 326 | |
| 327 | // find end-of-line |
| 328 | std::string::size_type pend = inlineAsm.find_first_of('\n', pbegin); |
| 329 | if (pend == std::string::npos) |
| 330 | break; |
| 331 | |
Devang Patel | 4139070 | 2008-07-16 19:49:09 +0000 | [diff] [blame^] | 332 | asmSymbolName.assign(inlineAsm, pbegin, pend - pbegin); |
Devang Patel | c2aec57 | 2008-07-16 18:06:52 +0000 | [diff] [blame] | 333 | addAsmGlobalSymbol(asmSymbolName.c_str()); |
| 334 | |
| 335 | // search next .globl |
| 336 | pos = inlineAsm.find(glbl, pend); |
| 337 | } |
| 338 | |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 339 | // make symbols for all undefines |
| 340 | for (StringSet::iterator it=_undefines.begin(); |
| 341 | it != _undefines.end(); ++it) { |
| 342 | // if this symbol also has a definition, then don't make an undefine |
| 343 | // because it is a tentative definition |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 344 | if ( _defines.count(it->getKeyData(), it->getKeyData()+ |
| 345 | it->getKeyLength()) == 0 ) { |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 346 | NameAndAttributes info; |
| 347 | info.name = it->getKeyData(); |
| 348 | info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; |
| 349 | _symbols.push_back(info); |
| 350 | } |
| 351 | } |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | uint32_t LTOModule::getSymbolCount() |
| 357 | { |
| 358 | lazyParseSymbols(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 359 | return _symbols.size(); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) |
| 364 | { |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 365 | lazyParseSymbols(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 366 | if ( index < _symbols.size() ) |
| 367 | return _symbols[index].attributes; |
| 368 | else |
| 369 | return lto_symbol_attributes(0); |
| 370 | } |
| 371 | |
| 372 | const char* LTOModule::getSymbolName(uint32_t index) |
| 373 | { |
Nick Kledzik | ef194ed | 2008-02-27 22:25:36 +0000 | [diff] [blame] | 374 | lazyParseSymbols(); |
Nick Kledzik | 77595fc | 2008-02-26 20:26:43 +0000 | [diff] [blame] | 375 | if ( index < _symbols.size() ) |
| 376 | return _symbols[index].name; |
| 377 | else |
| 378 | return NULL; |
| 379 | } |
| 380 | |