Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -979,7 +979,7 @@ OutStreamer->PushSection(); OutStreamer->SwitchSection(StackSizeSection); - const MCSymbol *FunctionSymbol = getSymbol(&MF.getFunction()); + const MCSymbol *FunctionSymbol = getFunctionBegin(); uint64_t StackSize = FrameInfo.getStackSize(); OutStreamer->EmitSymbolValue(FunctionSymbol, TM.getProgramPointerSize()); OutStreamer->EmitULEB128IntValue(StackSize); @@ -1507,7 +1507,8 @@ CurrentFnBegin = nullptr; CurExceptionSym = nullptr; bool NeedsLocalForSize = MAI->needsLocalForSize(); - if (needFuncLabelsForEHOrDebugInfo(MF, MMI) || NeedsLocalForSize) { + if (needFuncLabelsForEHOrDebugInfo(MF, MMI) || NeedsLocalForSize || + MF.getTarget().Options.EmitStackSizeSection) { CurrentFnBegin = createTempSymbol("func_begin"); if (NeedsLocalForSize) CurrentFnSymForSize = CurrentFnBegin; Index: test/CodeGen/ARM/stack-size-section.ll =================================================================== --- test/CodeGen/ARM/stack-size-section.ll +++ test/CodeGen/ARM/stack-size-section.ll @@ -1,8 +1,9 @@ ; RUN: llc < %s -mtriple=armv7-linux -stack-size-section | FileCheck %s ; CHECK-LABEL: func1: +; CHECK-NEXT: .Lfunc_begin0: ; CHECK: .section .stack_sizes,"",%progbits -; CHECK-NEXT: .long func1 +; CHECK-NEXT: .long .Lfunc_begin0 ; CHECK-NEXT: .byte 8 define void @func1(i32, i32) #0 { alloca i32, align 4 @@ -11,8 +12,9 @@ } ; CHECK-LABEL: func2: +; CHECK-NEXT: .Lfunc_begin1: ; CHECK: .section .stack_sizes,"",%progbits -; CHECK-NEXT: .long func2 +; CHECK-NEXT: .long .Lfunc_begin1 ; CHECK-NEXT: .byte 16 define void @func2() #0 { alloca i32, align 4 Index: test/CodeGen/SystemZ/stack-size-section.ll =================================================================== --- test/CodeGen/SystemZ/stack-size-section.ll +++ test/CodeGen/SystemZ/stack-size-section.ll @@ -1,16 +1,18 @@ ; RUN: llc < %s -mtriple=s390x-linux-gnu -stack-size-section | FileCheck %s ; CHECK-LABEL: func1: +; CHECK-NEXT: .Lfunc_begin0: ; CHECK: .section .stack_sizes,"",@progbits -; CHECK-NEXT: .quad func1 +; CHECK-NEXT: .quad .Lfunc_begin0 ; CHECK-NEXT: .byte 0 define void @func1(i32, i32) #0 { ret void } ; CHECK-LABEL: func2: +; CHECK-NEXT: .Lfunc_begin1: ; CHECK: .section .stack_sizes,"",@progbits -; CHECK-NEXT: .quad func2 +; CHECK-NEXT: .quad .Lfunc_begin1 ; CHECK-NEXT: .ascii "\250\001" define void @func2(i32, i32) #0 { alloca i32, align 4 @@ -19,8 +21,9 @@ } ; CHECK-LABEL: func3: +; CHECK-NEXT: .Lfunc_begin2: ; CHECK: .section .stack_sizes,"",@progbits -; CHECK-NEXT: .quad func3 +; CHECK-NEXT: .quad .Lfunc_begin2 ; CHECK-NEXT: .ascii "\250\001" define void @func3() #0 { alloca i32, align 4 Index: test/CodeGen/X86/stack-size-section.ll =================================================================== --- test/CodeGen/X86/stack-size-section.ll +++ test/CodeGen/X86/stack-size-section.ll @@ -1,8 +1,9 @@ ; RUN: llc < %s -mtriple=x86_64-linux -stack-size-section | FileCheck %s ; CHECK-LABEL: func1: +; CHECK-NEXT: .Lfunc_begin0: ; CHECK: .section .stack_sizes,"",@progbits -; CHECK-NEXT: .quad func1 +; CHECK-NEXT: .quad .Lfunc_begin0 ; CHECK-NEXT: .byte 8 define void @func1(i32, i32) #0 { alloca i32, align 4 @@ -11,8 +12,9 @@ } ; CHECK-LABEL: func2: +; CHECK-NEXT: .Lfunc_begin1: ; CHECK: .section .stack_sizes,"",@progbits -; CHECK-NEXT: .quad func2 +; CHECK-NEXT: .quad .Lfunc_begin1 ; CHECK-NEXT: .byte 24 define void @func2() #0 { alloca i32, align 4