/src/test/assembly/static-relocation-model.rs

https://gitlab.com/rust-lang/rust · Rust · 85 lines · 41 code · 14 blank · 30 comment · 2 complexity · 5b4336bee2ee17d29e7b1db126f95cce MD5 · raw file

  1. // revisions: x64 A64 ppc64le
  2. // assembly-output: emit-asm
  3. // [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=static
  4. // [x64] needs-llvm-components: x86
  5. // [A64] compile-flags: --target aarch64-unknown-linux-gnu -Crelocation-model=static
  6. // [A64] needs-llvm-components: aarch64
  7. // [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static
  8. // [ppc64le] needs-llvm-components: powerpc
  9. #![feature(no_core, lang_items)]
  10. #![no_core]
  11. #![crate_type="rlib"]
  12. #[lang="sized"]
  13. trait Sized {}
  14. #[lang="copy"]
  15. trait Copy {}
  16. #[lang="sync"]
  17. trait Sync {}
  18. #[lang = "drop_in_place"]
  19. fn drop_in_place<T>(_: *mut T) {}
  20. impl Copy for u8 {}
  21. impl Sync for u8 {}
  22. #[no_mangle]
  23. pub static PIERIS: u8 = 42;
  24. extern "C" {
  25. static EXOCHORDA: *mut u8;
  26. fn chaenomeles();
  27. }
  28. // CHECK-LABEL: banana:
  29. // x64: movb chaenomeles{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
  30. // A64: adrp [[REG:[a-z0-9]+]], chaenomeles
  31. // A64-NEXT: ldrb {{[a-z0-9]+}}, {{\[}}[[REG]], :lo12:chaenomeles]
  32. #[no_mangle]
  33. pub fn banana() -> u8 {
  34. unsafe {
  35. *(chaenomeles as *mut u8)
  36. }
  37. }
  38. // CHECK-LABEL: peach:
  39. // x64: movb banana{{(\(%[a-z0-9]+\))?}}, %{{[a-z0-9]+}}
  40. // A64: adrp [[REG2:[a-z0-9]+]], banana
  41. // A64-NEXT: ldrb {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:banana]
  42. #[no_mangle]
  43. pub fn peach() -> u8 {
  44. unsafe {
  45. *(banana as *mut u8)
  46. }
  47. }
  48. // CHECK-LABEL: mango:
  49. // x64: movq EXOCHORDA{{(\(%[a-z0-9]+\))?}}, %[[REG:[a-z0-9]+]]
  50. // x64-NEXT: movb (%[[REG]]), %{{[a-z0-9]+}}
  51. // A64: adrp [[REG2:[a-z0-9]+]], EXOCHORDA
  52. // A64-NEXT: ldr {{[a-z0-9]+}}, {{\[}}[[REG2]], :lo12:EXOCHORDA]
  53. #[no_mangle]
  54. pub fn mango() -> u8 {
  55. unsafe {
  56. *EXOCHORDA
  57. }
  58. }
  59. // CHECK-LABEL: orange:
  60. // x64: mov{{l|absq}} $PIERIS, %{{[a-z0-9]+}}
  61. // A64: adrp [[REG2:[a-z0-9]+]], PIERIS
  62. // A64-NEXT: add {{[a-z0-9]+}}, [[REG2]], :lo12:PIERIS
  63. #[no_mangle]
  64. pub fn orange() -> &'static u8 {
  65. &PIERIS
  66. }
  67. // For ppc64 we need to make sure to generate TOC entries even with the static relocation model
  68. // ppc64le: .tc chaenomeles[TC],chaenomeles
  69. // ppc64le: .tc banana[TC],banana
  70. // ppc64le: .tc EXOCHORDA[TC],EXOCHORDA
  71. // ppc64le: .tc PIERIS[TC],PIERIS