Could you share the small reproducible example? I've tried to just put this code in fn main() { unsafe { ... } } and got linker error, not rustc error, so there's definitely something else going on here.
I don't think that code is correct either. That code enters in 32bit mode but exits in 64bit mode. The compiler has no clue about this and will either emit 32bit code or 64bit code depending on the target. I think you will need to use two separate crates, one for 32bit and one for 64bit where the 32bit one contains this asm block except with a call of a function in the 64bit crate at the end which will never return. Or you could use global asm depending on how it enters the 32bit code.