Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1336,6 +1336,7 @@ OutStreamer->SwitchSection(TLOF.getDataSection()); const DataLayout &DL = M.getDataLayout(); + EmitAlignment(Log2_32(DL.getPointerSize())); for (const auto &Stub : Stubs) { OutStreamer->EmitLabel(Stub.first); OutStreamer->EmitSymbolValue(Stub.second.getPointer(), Index: test/Object/X86/align-stub.ll =================================================================== --- /dev/null +++ test/Object/X86/align-stub.ll @@ -0,0 +1,85 @@ +; RUN: llc %s -mtriple=x86_64-unknown-unknown -relocation-model=pic -o - \ +; RUN: | FileCheck %s + +; Check that the stub symbol in .data section is aligned at 8 bytes. +; https://bugs.llvm.org/show_bug.cgi?id=36885 +; CHECK: .data{{[[:space:]]}} .p2align 3 +; CHECK-NEXT: .L_ZTI3bar.DW.stub: + + +%class.bar = type { i8 } + +$_ZTS3bar = comdat any + +$_ZTI3bar = comdat any + +@str = dso_local global [3 x i8] c"..\00", align 1 +@_ZTVN10__cxxabiv117__class_type_infoE = external global i8* +@_ZTS3bar = linkonce_odr dso_local constant [5 x i8] c"3bar\00", comdat +@_ZTI3bar = linkonce_odr dso_local constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @_ZTS3bar, i32 0, i32 0) }, comdat + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @_Z3foov() #0 { +entry: + ret i32 0 +} + +; Function Attrs: noinline norecurse optnone uwtable +define dso_local i32 @main() #1 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %retval = alloca i32, align 4 + %exn.slot = alloca i8* + %ehselector.slot = alloca i32 + %e = alloca %class.bar*, align 8 + store i32 0, i32* %retval, align 4 + %call = invoke i32 @_Z3foov() + to label %invoke.cont unwind label %lpad + +invoke.cont: ; preds = %entry + store i32 %call, i32* %retval, align 4 + br label %try.cont + +lpad: ; preds = %entry + %0 = landingpad { i8*, i32 } + catch i8* bitcast ({ i8*, i8* }* @_ZTI3bar to i8*) + %1 = extractvalue { i8*, i32 } %0, 0 + store i8* %1, i8** %exn.slot, align 8 + %2 = extractvalue { i8*, i32 } %0, 1 + store i32 %2, i32* %ehselector.slot, align 4 + br label %catch.dispatch + +catch.dispatch: ; preds = %lpad + %sel = load i32, i32* %ehselector.slot, align 4 + %3 = call i32 @llvm.eh.typeid.for(i8* bitcast ({ i8*, i8* }* @_ZTI3bar to i8*)) #3 + %matches = icmp eq i32 %sel, %3 + br i1 %matches, label %catch, label %eh.resume + +catch: ; preds = %catch.dispatch + %exn = load i8*, i8** %exn.slot, align 8 + %4 = call i8* @__cxa_begin_catch(i8* %exn) #3 + %exn.byref = bitcast i8* %4 to %class.bar* + store %class.bar* %exn.byref, %class.bar** %e, align 8 + store i32 1, i32* %retval, align 4 + call void @__cxa_end_catch() + br label %try.cont + +try.cont: ; preds = %invoke.cont, %catch + %5 = load i32, i32* %retval, align 4 + ret i32 %5 + +eh.resume: ; preds = %catch.dispatch + %exn1 = load i8*, i8** %exn.slot, align 8 + %sel2 = load i32, i32* %ehselector.slot, align 4 + %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn1, 0 + %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel2, 1 + resume { i8*, i32 } %lpad.val3 +} + +declare i32 @__gxx_personality_v0(...) + +; Function Attrs: nounwind readnone +declare i32 @llvm.eh.typeid.for(i8*) #2 + +declare i8* @__cxa_begin_catch(i8*) + +declare void @__cxa_end_catch()