Index: lib/Target/X86/X86MCInstLower.cpp =================================================================== --- lib/Target/X86/X86MCInstLower.cpp +++ lib/Target/X86/X86MCInstLower.cpp @@ -1039,7 +1039,7 @@ // We want to emit the following pattern: // // .Lxray_sled_N: - // .palign 2, ... + // .p2align 1, ... // jmp .tmpN // # 9 bytes worth of noops // .tmpN @@ -1052,7 +1052,7 @@ // auto CurSled = OutContext.createTempSymbol("xray_sled_", true); OutStreamer->EmitLabel(CurSled); - OutStreamer->EmitCodeAlignment(4); + OutStreamer->EmitCodeAlignment(2); auto Target = OutContext.createTempSymbol(); // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as @@ -1075,12 +1075,14 @@ // We should emit the RET followed by sleds. // // .Lxray_sled_N: + // .p2align 1, ... // ret # or equivalent instruction // # 10 bytes worth of noops // // This just makes sure that the alignment for the next instruction is 2. auto CurSled = OutContext.createTempSymbol("xray_sled_", true); OutStreamer->EmitLabel(CurSled); + OutStreamer->EmitCodeAlignment(2); unsigned OpCode = MI.getOperand(0).getImm(); MCInst Ret; Ret.setOpcode(OpCode); Index: test/CodeGen/X86/xray-attribute-instrumentation.ll =================================================================== --- test/CodeGen/X86/xray-attribute-instrumentation.ll +++ test/CodeGen/X86/xray-attribute-instrumentation.ll @@ -2,12 +2,13 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" { ; CHECK-LABEL: Lxray_sled_0: -; CHECK-NEXT: .p2align 2, 0x90 +; CHECK-NEXT: .p2align 1, 0x90 ; CHECK-NEXT: .ascii "\353\t" ; CHECK-NEXT: nopw 512(%rax,%rax) ; CHECK-LABEL: Ltmp0: ret i32 0 ; CHECK-LABEL: Lxray_sled_1: +; CHECK-NEXT: .p2align 1, 0x90 ; CHECK-NEXT: retq ; CHECK-NEXT: nopw %cs:512(%rax,%rax) }