Make global aliases have symbol size equal to their type

This is mainly for the benefit of GlobalMerge, so that an alias into a
MergedGlobals variable has the same size as the original non-merged
variable.

Differential Revision: http://reviews.llvm.org/D10837


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242520 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John Brawn
2015-07-17 12:12:03 +00:00
parent fe6ad9692a
commit 591adee23b
4 changed files with 34 additions and 0 deletions

View File

@@ -1111,6 +1111,16 @@ bool AsmPrinter::doFinalization(Module &M) {
// Emit the directives as assignments aka .set:
OutStreamer->EmitAssignment(Name, lowerConstant(Alias.getAliasee()));
// Set the size of the alias symbol if we can, as otherwise the alias gets
// the size of the aliasee which may not be correct e.g. if the alias is of
// a member of a struct.
if (MAI->hasDotTypeDotSizeDirective() && Alias.getValueType()->isSized()) {
const DataLayout &DL = M.getDataLayout();
uint64_t Size = DL.getTypeAllocSize(Alias.getValueType());
OutStreamer->emitELFSize(cast<MCSymbolELF>(Name),
MCConstantExpr::create(Size, OutContext));
}
}
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();