Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1108,6 +1108,17 @@ // 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.getType()->getElementType()->isSized()) { + const DataLayout *DL = TM.getDataLayout(); + uint64_t Size = DL->getTypeAllocSize(Alias.getType()->getElementType()); + OutStreamer->emitELFSize(cast(Name), + MCConstantExpr::create(Size, OutContext)); + } } GCModuleInfo *MI = getAnalysisIfAvailable(); Index: test/CodeGen/AArch64/global-merge-2.ll =================================================================== --- test/CodeGen/AArch64/global-merge-2.ll +++ test/CodeGen/AArch64/global-merge-2.ll @@ -35,10 +35,13 @@ ;CHECK: .globl x ;CHECK: x = _MergedGlobals_x +;CHECK: .size x, 4 ;CHECK: .globl y ;CHECK: y = _MergedGlobals_x+4 +;CHECK: .size y, 4 ;CHECK: .globl z ;CHECK: z = _MergedGlobals_x+8 +;CHECK: .size z, 4 ;CHECK-APPLE-IOS: .globl __MergedGlobals_x ; @_MergedGlobals_x ;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_x,12,3 Index: test/CodeGen/AArch64/global-merge-3.ll =================================================================== --- test/CodeGen/AArch64/global-merge-3.ll +++ test/CodeGen/AArch64/global-merge-3.ll @@ -42,8 +42,10 @@ ;CHECK: .globl x ;CHECK: x = _MergedGlobals_x+4 +;CHECK: .size x, 4000 ;CHECK: .globl y ;CHECK: y = _MergedGlobals_y +;CHECK: .size y, 4000 ;CHECK-APPLE-IOS:.globl _x ;CHECK-APPLE-IOS: _x = __MergedGlobals_x+4 Index: test/CodeGen/ARM/aliases.ll =================================================================== --- test/CodeGen/ARM/aliases.ll +++ test/CodeGen/ARM/aliases.ll @@ -2,19 +2,34 @@ ; CHECK: .globl test +; CHECK: .globl structvar +; CHECK: .size structvar, 8 + ; CHECK: .globl foo1 ; CHECK: foo1 = bar +; CHECK: .size foo1, 4 ; CHECK: .globl foo2 ; CHECK: foo2 = bar +; CHECK: .size foo2, 4 ; CHECK: .weak bar_f ; CHECK: bar_f = foo_f ; CHECK: bar_i = bar +; CHECK: .size bar_i, 4 ; CHECK: .globl A ; CHECK: A = bar +; CHECK: .size A, 8 + +; CHECK: .globl elem0 +; CHECK: elem0 = structvar +; CHECK: .size elem0, 4 + +; CHECK: .globl elem1 +; CHECK: elem1 = structvar+4 +; CHECK: .size elem1, 4 @bar = global i32 42 @foo1 = alias i32* @bar @@ -31,6 +46,10 @@ @A = alias bitcast (i32* @bar to i64*) +@structvar = global {i32, i32} {i32 1, i32 2} +@elem0 = alias getelementptr({i32, i32}, {i32, i32}* @structvar, i32 0, i32 0) +@elem1 = alias getelementptr({i32, i32}, {i32, i32}* @structvar, i32 0, i32 1) + define i32 @test() { entry: %tmp = load i32, i32* @foo1