# liburing-lto liburing + LTO ## Requirements: 1. clang version 16 2. lld version 16 3. rustc with llvm version 16 ``` rustc --version --verbose ... LLVM version: 16.0.x ``` 4. libclang(see [bindgen](https://rust-lang.github.io/rust-bindgen/requirements.html)) ## Usage: .cargo/config.toml: ``` [build] rustflags = [ "-Clinker-plugin-lto", "-Clinker=clang", "-Clink-arg=-fuse-ld=lld", ] ``` Cargo.toml: ``` [dependencies] liburing-lto = { version = "*" , features = ["lto"] } ``` ## Links: [Crates.io](https://crates.io/crates/liburing-lto) [Documentation](https://docs.rs/liburing-lto) [Repository](https://github.com/zzwxh/liburing-lto) ## How to know LTO has been enabled: You can download the files from [Github Actions](https://github.com/zzwxh/liburing-lto/actions)' Artifacts ### Source: ```rust #[no_mangle] fn liburing_lto_test_nop() { unsafe { let mut ring = zeroed(); assert!(io_uring_queue_init(1, &mut ring, 0) >= 0); let sqe = io_uring_get_sqe(&mut ring); assert!(!sqe.is_null()); io_uring_prep_nop(sqe); io_uring_sqe_set_data64(sqe, MAGIC_NUMBER); assert!(io_uring_submit(&mut ring) == 1); let mut cqe = null_mut(); assert!(io_uring_wait_cqe(&mut ring, &mut cqe) >= 0); assert!(io_uring_cqe_get_data64(cqe) == MAGIC_NUMBER); io_uring_cqe_seen(&mut ring, cqe); io_uring_queue_exit(&mut ring); } } ``` ### LTO enabled: ``` 00000000000c8dd0 : c8dd0: 53 push %rbx c8dd1: 48 81 ec 70 01 00 00 sub $0x170,%rsp c8dd8: 0f 57 c0 xorps %xmm0,%xmm0 c8ddb: 0f 29 84 24 d0 00 00 movaps %xmm0,0xd0(%rsp) c8de2: 00 c8de3: 0f 29 84 24 c0 00 00 movaps %xmm0,0xc0(%rsp) c8dea: 00 c8deb: 0f 29 84 24 b0 00 00 movaps %xmm0,0xb0(%rsp) c8df2: 00 c8df3: 0f 29 84 24 a0 00 00 movaps %xmm0,0xa0(%rsp) c8dfa: 00 c8dfb: 0f 29 84 24 90 00 00 movaps %xmm0,0x90(%rsp) c8e02: 00 c8e03: 0f 29 84 24 80 00 00 movaps %xmm0,0x80(%rsp) c8e0a: 00 c8e0b: 0f 29 44 24 70 movaps %xmm0,0x70(%rsp) c8e10: 0f 29 44 24 60 movaps %xmm0,0x60(%rsp) c8e15: 0f 29 44 24 50 movaps %xmm0,0x50(%rsp) c8e1a: 0f 29 44 24 40 movaps %xmm0,0x40(%rsp) c8e1f: 0f 29 44 24 30 movaps %xmm0,0x30(%rsp) c8e24: 0f 29 44 24 20 movaps %xmm0,0x20(%rsp) c8e29: 0f 29 44 24 10 movaps %xmm0,0x10(%rsp) c8e2e: 48 c7 84 24 e0 00 00 movq $0x0,0xe0(%rsp) c8e35: 00 00 00 00 00 c8e3a: 0f 29 84 24 50 01 00 movaps %xmm0,0x150(%rsp) c8e41: 00 c8e42: 0f 29 84 24 40 01 00 movaps %xmm0,0x140(%rsp) c8e49: 00 c8e4a: 0f 29 84 24 30 01 00 movaps %xmm0,0x130(%rsp) c8e51: 00 c8e52: 0f 29 84 24 20 01 00 movaps %xmm0,0x120(%rsp) c8e59: 00 c8e5a: 0f 29 84 24 10 01 00 movaps %xmm0,0x110(%rsp) c8e61: 00 c8e62: 0f 29 84 24 00 01 00 movaps %xmm0,0x100(%rsp) c8e69: 00 c8e6a: 0f 29 84 24 f0 00 00 movaps %xmm0,0xf0(%rsp) c8e71: 00 c8e72: 48 c7 84 24 60 01 00 movq $0x0,0x160(%rsp) c8e79: 00 00 00 00 00 c8e7e: 48 8d 74 24 10 lea 0x10(%rsp),%rsi c8e83: 48 8d 94 24 f0 00 00 lea 0xf0(%rsp),%rdx c8e8a: 00 c8e8b: bf 01 00 00 00 mov $0x1,%edi c8e90: 31 c9 xor %ecx,%ecx c8e92: 45 31 c0 xor %r8d,%r8d c8e95: e8 56 05 00 00 call c93f0 <__io_uring_queue_init_params.llvm.1924210940549624210> c8e9a: 85 c0 test %eax,%eax c8e9c: 0f 88 89 02 00 00 js c912b c8ea2: 8b 54 24 54 mov 0x54(%rsp),%edx c8ea6: ff c2 inc %edx c8ea8: 8b 8c 24 d0 00 00 00 mov 0xd0(%rsp),%ecx c8eaf: 48 8b 44 24 10 mov 0x10(%rsp),%rax c8eb4: f6 c1 02 test $0x2,%cl c8eb7: 8b 00 mov (%rax),%eax c8eb9: 89 d6 mov %edx,%esi c8ebb: 29 c6 sub %eax,%esi c8ebd: 3b 74 24 6c cmp 0x6c(%rsp),%esi c8ec1: 0f 87 32 02 00 00 ja c90f9 c8ec7: 48 8b 44 24 48 mov 0x48(%rsp),%rax c8ecc: 8b 7c 24 54 mov 0x54(%rsp),%edi c8ed0: 8b 74 24 68 mov 0x68(%rsp),%esi c8ed4: 89 54 24 54 mov %edx,0x54(%rsp) c8ed8: 48 85 c0 test %rax,%rax c8edb: 0f 84 18 02 00 00 je c90f9 c8ee1: c1 e9 0a shr $0xa,%ecx c8ee4: 83 e1 01 and $0x1,%ecx c8ee7: 48 bb 42 00 c7 9f 0a movabs $0x10a9fc70042,%rbx c8eee: 01 00 00 c8ef1: 21 fe and %edi,%esi c8ef3: d3 e6 shl %cl,%esi c8ef5: 48 c1 e6 06 shl $0x6,%rsi c8ef9: 48 b9 00 00 00 00 ff movabs $0xffffffff00000000,%rcx c8f00: ff ff ff c8f03: 48 89 0c 30 mov %rcx,(%rax,%rsi,1) c8f07: 0f 57 c0 xorps %xmm0,%xmm0 c8f0a: 0f 11 44 30 28 movups %xmm0,0x28(%rax,%rsi,1) c8f0f: 48 c7 44 30 38 00 00 movq $0x0,0x38(%rax,%rsi,1) c8f16: 00 00 c8f18: 0f 11 44 30 08 movups %xmm0,0x8(%rax,%rsi,1) c8f1d: 48 c7 44 30 18 00 00 movq $0x0,0x18(%rax,%rsi,1) c8f24: 00 00 c8f26: 48 89 5c 30 20 mov %rbx,0x20(%rax,%rsi,1) c8f2b: 8b 74 24 54 mov 0x54(%rsp),%esi c8f2f: 39 74 24 50 cmp %esi,0x50(%rsp) c8f33: 74 13 je c8f48 c8f35: 89 74 24 50 mov %esi,0x50(%rsp) c8f39: f6 84 24 d0 00 00 00 testb $0x2,0xd0(%rsp) c8f40: 02 c8f41: 48 8b 44 24 18 mov 0x18(%rsp),%rax c8f46: 89 30 mov %esi,(%rax) c8f48: 48 8b 44 24 10 mov 0x10(%rsp),%rax c8f4d: 2b 30 sub (%rax),%esi c8f4f: 8b 94 24 d0 00 00 00 mov 0xd0(%rsp),%edx c8f56: f6 c2 01 test $0x1,%dl c8f59: 75 20 jne c8f7b c8f5b: 48 8b 44 24 30 mov 0x30(%rsp),%rax c8f60: 8b 08 mov (%rax),%ecx c8f62: f6 c1 06 test $0x6,%cl c8f65: 0f 95 c0 setne %al c8f68: 85 f6 test %esi,%esi c8f6a: 75 17 jne c8f83 c8f6c: f6 c1 06 test $0x6,%cl c8f6f: 0f 84 9d 01 00 00 je c9112 c8f75: 31 c9 xor %ecx,%ecx c8f77: b0 01 mov $0x1,%al c8f79: eb 27 jmp c8fa2 c8f7b: 31 c9 xor %ecx,%ecx c8f7d: b0 01 mov $0x1,%al c8f7f: 85 f6 test %esi,%esi c8f81: 74 1f je c8fa2 c8f83: 31 c9 xor %ecx,%ecx c8f85: f6 c2 02 test $0x2,%dl c8f88: 74 18 je c8fa2 c8f8a: 0f ae f0 mfence c8f8d: 48 8b 4c 24 30 mov 0x30(%rsp),%rcx c8f92: 8b 09 mov (%rcx),%ecx c8f94: 89 ca mov %ecx,%edx c8f96: 08 c2 or %al,%dl c8f98: f6 c2 01 test $0x1,%dl c8f9b: 74 39 je c8fd6 c8f9d: 83 e1 01 and $0x1,%ecx c8fa0: 01 c9 add %ecx,%ecx c8fa2: 0f b6 c0 movzbl %al,%eax c8fa5: 09 c8 or %ecx,%eax c8fa7: 8b bc 24 dc 00 00 00 mov 0xdc(%rsp),%edi c8fae: 44 8b 94 24 e0 00 00 mov 0xe0(%rsp),%r10d c8fb5: 00 c8fb6: 41 c1 e2 04 shl $0x4,%r10d c8fba: 41 83 e2 10 and $0x10,%r10d c8fbe: 41 09 c2 or %eax,%r10d c8fc1: 41 b9 08 00 00 00 mov $0x8,%r9d c8fc7: b8 aa 01 00 00 mov $0x1aa,%eax c8fcc: 31 d2 xor %edx,%edx c8fce: 45 31 c0 xor %r8d,%r8d c8fd1: 0f 05 syscall c8fd3: 48 89 c6 mov %rax,%rsi c8fd6: 83 fe 01 cmp $0x1,%esi c8fd9: 0f 85 33 01 00 00 jne c9112 c8fdf: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp) c8fe6: 00 00 c8fe8: 8b 84 24 c0 00 00 00 mov 0xc0(%rsp),%eax c8fef: 8b 8c 24 d0 00 00 00 mov 0xd0(%rsp),%ecx c8ff6: c1 e9 0b shr $0xb,%ecx c8ff9: 83 e1 01 and $0x1,%ecx c8ffc: 0f 1f 40 00 nopl 0x0(%rax) c9000: 48 8b 94 24 80 00 00 mov 0x80(%rsp),%rdx c9007: 00 c9008: 8b 3a mov (%rdx),%edi c900a: 48 8b 54 24 78 mov 0x78(%rsp),%rdx c900f: 8b 32 mov (%rdx),%esi c9011: 39 f7 cmp %esi,%edi c9013: 74 3c je c9051 c9015: 48 8b bc 24 a8 00 00 mov 0xa8(%rsp),%rdi c901c: 00 c901d: 41 89 f0 mov %esi,%r8d c9020: 41 21 c0 and %eax,%r8d c9023: 41 d3 e0 shl %cl,%r8d c9026: 49 c1 e0 04 shl $0x4,%r8 c902a: 4e 8d 0c 07 lea (%rdi,%r8,1),%r9 c902e: f6 84 24 d9 00 00 00 testb $0x1,0xd9(%rsp) c9035: 01 c9036: 75 24 jne c905c c9038: 4d 8b 11 mov (%r9),%r10 c903b: 49 83 fa ff cmp $0xffffffffffffffff,%r10 c903f: 0f 85 91 00 00 00 jne c90d6 c9045: ff c6 inc %esi c9047: 42 83 7c 07 08 00 cmpl $0x0,0x8(%rdi,%r8,1) c904d: 89 32 mov %esi,(%rdx) c904f: 79 af jns c9000 c9051: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp) c9058: 00 00 c905a: eb 0a jmp c9066 c905c: 4c 89 4c 24 08 mov %r9,0x8(%rsp) c9061: 48 85 ff test %rdi,%rdi c9064: 75 4a jne c90b0 c9066: 0f 28 05 e3 f0 f4 ff movaps -0xb0f1d(%rip),%xmm0 # 18150 c906d: 0f 29 84 24 f0 00 00 movaps %xmm0,0xf0(%rsp) c9074: 00 c9075: c7 84 24 00 01 00 00 movl $0x0,0x100(%rsp) c907c: 00 00 00 00 c9080: 48 c7 84 24 08 01 00 movq $0x0,0x108(%rsp) c9087: 00 00 00 00 00 c908c: 48 8d 7c 24 10 lea 0x10(%rsp),%rdi c9091: 48 8d 74 24 08 lea 0x8(%rsp),%rsi c9096: 48 8d 94 24 f0 00 00 lea 0xf0(%rsp),%rdx c909d: 00 c909e: e8 8d 09 00 00 call c9a30 <_io_uring_get_cqe.llvm.9294417469058513706> c90a3: 85 c0 test %eax,%eax c90a5: 0f 88 99 00 00 00 js c9144 c90ab: 4c 8b 4c 24 08 mov 0x8(%rsp),%r9 c90b0: 4d 8b 11 mov (%r9),%r10 c90b3: 49 39 da cmp %rbx,%r10 c90b6: 75 28 jne c90e0 c90b8: 48 8b 44 24 78 mov 0x78(%rsp),%rax c90bd: 8b 08 mov (%rax),%ecx c90bf: ff c1 inc %ecx c90c1: 89 08 mov %ecx,(%rax) c90c3: 48 8d 7c 24 10 lea 0x10(%rsp),%rdi c90c8: e8 9c 08 00 00 call c9969 c90cd: 48 81 c4 70 01 00 00 add $0x170,%rsp c90d4: 5b pop %rbx c90d5: c3 ret c90d6: 4c 89 4c 24 08 mov %r9,0x8(%rsp) c90db: 49 39 da cmp %rbx,%r10 c90de: 74 d8 je c90b8 c90e0: 48 8d 3d d5 d5 f5 ff lea -0xa2a2b(%rip),%rdi # 266bc c90e7: 48 8d 15 aa cb 00 00 lea 0xcbaa(%rip),%rdx # d5c98 c90ee: be 3e 00 00 00 mov $0x3e,%esi c90f3: 67 e8 27 88 ff ff addr32 call c1920 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> c90f9: 48 8d 3d 78 12 f5 ff lea -0xaed88(%rip),%rdi # 1a378 c9100: 48 8d 15 49 cb 00 00 lea 0xcb49(%rip),%rdx # d5c50 c9107: be 20 00 00 00 mov $0x20,%esi c910c: 67 e8 0e 88 ff ff addr32 call c1920 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> c9112: 48 8d 3d 35 d5 f5 ff lea -0xa2acb(%rip),%rdi # 2664e c9119: 48 8d 15 48 cb 00 00 lea 0xcb48(%rip),%rdx # d5c68 c9120: be 31 00 00 00 mov $0x31,%esi c9125: 67 e8 f5 87 ff ff addr32 call c1920 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> c912b: 48 8d 3d d7 d4 f5 ff lea -0xa2b29(%rip),%rdi # 26609 c9132: 48 8d 15 ff ca 00 00 lea 0xcaff(%rip),%rdx # d5c38 c9139: be 3b 00 00 00 mov $0x3b,%esi c913e: 67 e8 dc 87 ff ff addr32 call c1920 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> c9144: 48 8d 3d 34 d5 f5 ff lea -0xa2acc(%rip),%rdi # 2667f c914b: 48 8d 15 2e cb 00 00 lea 0xcb2e(%rip),%rdx # d5c80 c9152: be 3d 00 00 00 mov $0x3d,%esi c9157: 67 e8 c3 87 ff ff addr32 call c1920 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> ``` ### LTO disabled: ``` 00000000000cd860 : cd860: 41 56 push %r14 cd862: 53 push %rbx cd863: 48 81 ec e8 00 00 00 sub $0xe8,%rsp cd86a: 0f 57 c0 xorps %xmm0,%xmm0 cd86d: 0f 29 84 24 d0 00 00 movaps %xmm0,0xd0(%rsp) cd874: 00 cd875: 0f 29 84 24 c0 00 00 movaps %xmm0,0xc0(%rsp) cd87c: 00 cd87d: 0f 29 84 24 b0 00 00 movaps %xmm0,0xb0(%rsp) cd884: 00 cd885: 0f 29 84 24 a0 00 00 movaps %xmm0,0xa0(%rsp) cd88c: 00 cd88d: 0f 29 84 24 90 00 00 movaps %xmm0,0x90(%rsp) cd894: 00 cd895: 0f 29 84 24 80 00 00 movaps %xmm0,0x80(%rsp) cd89c: 00 cd89d: 0f 29 44 24 70 movaps %xmm0,0x70(%rsp) cd8a2: 0f 29 44 24 60 movaps %xmm0,0x60(%rsp) cd8a7: 0f 29 44 24 50 movaps %xmm0,0x50(%rsp) cd8ac: 0f 29 44 24 40 movaps %xmm0,0x40(%rsp) cd8b1: 0f 29 44 24 30 movaps %xmm0,0x30(%rsp) cd8b6: 0f 29 44 24 20 movaps %xmm0,0x20(%rsp) cd8bb: 0f 29 44 24 10 movaps %xmm0,0x10(%rsp) cd8c0: 48 c7 84 24 e0 00 00 movq $0x0,0xe0(%rsp) cd8c7: 00 00 00 00 00 cd8cc: 48 8d 74 24 10 lea 0x10(%rsp),%rsi cd8d1: bf 01 00 00 00 mov $0x1,%edi cd8d6: 31 d2 xor %edx,%edx cd8d8: 67 e8 69 e3 f6 ff addr32 call 3bc47 cd8de: 85 c0 test %eax,%eax cd8e0: 0f 88 a6 00 00 00 js cd98c cd8e6: 48 8d 7c 24 10 lea 0x10(%rsp),%rdi cd8eb: 67 e8 0f f1 f6 ff addr32 call 3ca00 cd8f1: 48 85 c0 test %rax,%rax cd8f4: 0f 84 ab 00 00 00 je cd9a5 cd8fa: 49 89 c6 mov %rax,%r14 cd8fd: 48 bb 42 00 c7 9f 0a movabs $0x10a9fc70042,%rbx cd904: 01 00 00 cd907: 48 89 c7 mov %rax,%rdi cd90a: 67 e8 80 ff f6 ff addr32 call 3d890 cd910: 4c 89 f7 mov %r14,%rdi cd913: 48 89 de mov %rbx,%rsi cd916: 67 e8 e4 fb f6 ff addr32 call 3d500 cd91c: 48 8d 7c 24 10 lea 0x10(%rsp),%rdi cd921: 67 e8 19 ef f6 ff addr32 call 3c840 cd927: 83 f8 01 cmp $0x1,%eax cd92a: 0f 85 8e 00 00 00 jne cd9be cd930: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp) cd937: 00 00 cd939: 48 8d 7c 24 10 lea 0x10(%rsp),%rdi cd93e: 48 8d 74 24 08 lea 0x8(%rsp),%rsi cd943: 67 e8 c7 0e f7 ff addr32 call 3e810 cd949: 85 c0 test %eax,%eax cd94b: 0f 88 86 00 00 00 js cd9d7 cd951: 48 8b 7c 24 08 mov 0x8(%rsp),%rdi cd956: 67 e8 b4 fb f6 ff addr32 call 3d510 cd95c: 48 39 d8 cmp %rbx,%rax cd95f: 0f 85 8b 00 00 00 jne cd9f0 cd965: 48 8b 74 24 08 mov 0x8(%rsp),%rsi cd96a: 48 8d 5c 24 10 lea 0x10(%rsp),%rbx cd96f: 48 89 df mov %rbx,%rdi cd972: 67 e8 58 fb f6 ff addr32 call 3d4d0 cd978: 48 89 df mov %rbx,%rdi cd97b: 67 e8 0f e3 f6 ff addr32 call 3bc90 cd981: 48 81 c4 e8 00 00 00 add $0xe8,%rsp cd988: 5b pop %rbx cd989: 41 5e pop %r14 cd98b: c3 ret cd98c: 48 8d 3d 16 31 f5 ff lea -0xaceea(%rip),%rdi # 20aa9 cd993: 48 8d 15 5e c0 00 00 lea 0xc05e(%rip),%rdx # d99f8 cd99a: be 3b 00 00 00 mov $0x3b,%esi cd99f: 67 e8 0b 8a ff ff addr32 call c63b0 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> cd9a5: 48 8d 3d 6c 6e f4 ff lea -0xb9194(%rip),%rdi # 14818 cd9ac: 48 8d 15 5d c0 00 00 lea 0xc05d(%rip),%rdx # d9a10 cd9b3: be 20 00 00 00 mov $0x20,%esi cd9b8: 67 e8 f2 89 ff ff addr32 call c63b0 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> cd9be: 48 8d 3d 29 31 f5 ff lea -0xaced7(%rip),%rdi # 20aee cd9c5: 48 8d 15 5c c0 00 00 lea 0xc05c(%rip),%rdx # d9a28 cd9cc: be 31 00 00 00 mov $0x31,%esi cd9d1: 67 e8 d9 89 ff ff addr32 call c63b0 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> cd9d7: 48 8d 3d 41 31 f5 ff lea -0xacebf(%rip),%rdi # 20b1f cd9de: 48 8d 15 5b c0 00 00 lea 0xc05b(%rip),%rdx # d9a40 cd9e5: be 3d 00 00 00 mov $0x3d,%esi cd9ea: 67 e8 c0 89 ff ff addr32 call c63b0 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> cd9f0: 48 8d 3d 65 31 f5 ff lea -0xace9b(%rip),%rdi # 20b5c cd9f7: 48 8d 15 5a c0 00 00 lea 0xc05a(%rip),%rdx # d9a58 cd9fe: be 3e 00 00 00 mov $0x3e,%esi cda03: 67 e8 a7 89 ff ff addr32 call c63b0 <_ZN4core9panicking5panic17h65157a6ac7f1357aE> ```