diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -566,6 +566,10 @@ return false; assert(allowAutoPadding() && "incorrect initialization!"); + // We only pad in text section. + if (!OS.getCurrentSectionOnly()->getKind().isText()) + return false; + // To be Done: Currently don't deal with Bundle cases. if (OS.getAssembler().isBundlingEnabled()) return false; diff --git a/llvm/test/MC/X86/align-branch-section-size.s b/llvm/test/MC/X86/align-branch-section-size.s --- a/llvm/test/MC/X86/align-branch-section-size.s +++ b/llvm/test/MC/X86/align-branch-section-size.s @@ -5,16 +5,16 @@ # CHECK: Name: text1 # CHECK: AddressAlignment: 32 - .section text1 + .section text1, "ax" foo: ret # CHECK: Name: text2 # CHECK: AddressAlignment: 1 - .section text2 + .section text2, "ax" nop # CHECK: Name: text3 # CHECK: AddressAlignment: 1 - .section text3 + .section text3, "ax" jmp foo diff --git a/llvm/test/MC/X86/align-branch-section-size.s b/llvm/test/MC/X86/align-branch-section-type.s copy from llvm/test/MC/X86/align-branch-section-size.s copy to llvm/test/MC/X86/align-branch-section-type.s --- a/llvm/test/MC/X86/align-branch-section-size.s +++ b/llvm/test/MC/X86/align-branch-section-type.s @@ -1,20 +1,18 @@ # RUN: llvm-mc -filetype=obj -triple x86_64 --x86-align-branch-boundary=32 --x86-align-branch=ret %s | llvm-readobj -S | FileCheck %s - # Check the aligment of section that contains instructions to be aligned - # is correctly set. + # Check we only pad in a text section - # CHECK: Name: text1 + # CHECK: Name: text # CHECK: AddressAlignment: 32 - .section text1 -foo: + .section text, "ax" ret - # CHECK: Name: text2 + # CHECK: Name: excluded # CHECK: AddressAlignment: 1 - .section text2 - nop + .section excluded, "e" + ret - # CHECK: Name: text3 + # CHECK: Name: tls # CHECK: AddressAlignment: 1 - .section text3 - jmp foo + .section tls, "awT" + ret