/// Also if next byte is on a different page, don't assume it is readable.
MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
{
- const char* startPtr = (char*)mem;
- const char* endPtr = startPtr+length;
- if ( (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0)
- || (*endPtr != 0) )
- return MemoryBuffer::getMemBufferCopy(startPtr, endPtr);
- else
- return MemoryBuffer::getMemBuffer(startPtr, endPtr);
+ const char* startPtr = (char*)mem;
+ const char* endPtr = startPtr+length;
+ if ( (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0)
+ || (*endPtr != 0) )
+ return MemoryBuffer::getMemBufferCopy(startPtr, endPtr);
+ else
+ return MemoryBuffer::getMemBuffer(startPtr, endPtr);
}
addDefinedSymbol(v, mangler, false);
// add external symbols referenced by this data.
- for (unsigned count = 0, total = v->getNumOperands();\
+ for (unsigned count = 0, total = v->getNumOperands();
count != total; ++count) {
findExternalRefs(v->getOperand(count), mangler);
}
// set definition part
if ( def->hasWeakLinkage() || def->hasLinkOnceLinkage() ) {
- // lvm bitcode does not differenciate between weak def data
- // and tentative definitions!
- // HACK HACK HACK
- // C++ does not use tentative definitions, but does use weak symbols
- // so guess that anything that looks like a C++ symbol is weak and others
- // are tentative definitions
- if ( (strncmp(symbolName, "__Z", 3) == 0) )
- attr |= LTO_SYMBOL_DEFINITION_WEAK;
- else {
- attr |= LTO_SYMBOL_DEFINITION_TENTATIVE;
- }
+ attr |= LTO_SYMBOL_DEFINITION_WEAK;
}
else if ( def->hasCommonLinkage()) {
attr |= LTO_SYMBOL_DEFINITION_TENTATIVE;
if (GlobalValue* gv = dyn_cast<GlobalValue>(value)) {
if ( !gv->hasExternalLinkage() )
addPotentialUndefinedSymbol(gv, mangler);
+ // If this is a variable definition, do not recursively process
+ // initializer. It might contain a reference to this variable
+ // and cause an infinite loop. The initializer will be
+ // processed in addDefinedDataSymbol().
+ return;
}
-
+
// GlobalValue, even with InternalLinkage type, may have operands with
// ExternalLinkage type. Do not ignore these operands.
if (Constant* c = dyn_cast<Constant>(value)) {