From 4173b4c645d7d8663209b42bc9287b4f3d65bb59 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Thu, 18 Dec 2025 04:34:15 +0800
Subject: [PATCH 10/10] Drop tiny codemodel

---
 compiler/rustc_codegen_llvm/src/back/write.rs    |  1 -
 compiler/rustc_codegen_llvm/src/lib.rs           |  2 +-
 compiler/rustc_codegen_llvm/src/llvm/ffi.rs      |  1 -
 compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 15 ++++++---------
 compiler/rustc_target/src/spec/mod.rs            |  3 ---
 src/doc/rustc/src/codegen-options/index.md       |  1 -
 6 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs
index dac7ae71ed2..516b53ea40f 100644
--- a/compiler/rustc_codegen_llvm/src/back/write.rs
+++ b/compiler/rustc_codegen_llvm/src/back/write.rs
@@ -139,7 +139,6 @@ fn to_llvm_relocation_model(relocation_model: RelocModel) -> llvm::RelocModel {
 
 pub(crate) fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeModel {
     match code_model {
-        Some(CodeModel::Tiny) => llvm::CodeModel::Tiny,
         Some(CodeModel::Small) => llvm::CodeModel::Small,
         Some(CodeModel::Kernel) => llvm::CodeModel::Kernel,
         Some(CodeModel::Medium) => llvm::CodeModel::Medium,
diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs
index 776cb2ee99b..e0e0c9c4285 100644
--- a/compiler/rustc_codegen_llvm/src/lib.rs
+++ b/compiler/rustc_codegen_llvm/src/lib.rs
@@ -220,7 +220,7 @@ fn print(&self, req: PrintRequest, sess: &Session) {
             }
             PrintRequest::CodeModels => {
                 println!("Available code models:");
-                for name in &["tiny", "small", "kernel", "medium", "large"] {
+                for name in &["small", "kernel", "medium", "large"] {
                     println!("    {}", name);
                 }
                 println!();
diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
index 7456f183426..46a639dc502 100644
--- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
@@ -458,7 +458,6 @@ pub enum RelocModel {
 #[derive(Copy, Clone)]
 #[repr(C)]
 pub enum CodeModel {
-    Tiny,
     Small,
     Kernel,
     Medium,
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
index 9e3e9e35ee4..9df106c53c6 100644
--- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
@@ -305,7 +305,6 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
 }
 
 enum class LLVMRustCodeModel {
-  Tiny,
   Small,
   Kernel,
   Medium,
@@ -315,12 +314,6 @@ enum class LLVMRustCodeModel {
 
 static Optional<CodeModel::Model> fromRust(LLVMRustCodeModel Model) {
   switch (Model) {
-  case LLVMRustCodeModel::Tiny:
-#if LLVM_VERSION_GE(9, 0)
-    return CodeModel::Tiny;
-#else
-    return CodeModel::Small;
-#endif
   case LLVMRustCodeModel::Small:
     return CodeModel::Small;
   case LLVMRustCodeModel::Kernel:
@@ -332,7 +325,7 @@ static Optional<CodeModel::Model> fromRust(LLVMRustCodeModel Model) {
   case LLVMRustCodeModel::None:
     return None;
   default:
-    report_fatal_error("Bad CodeModel.");
+    return None;
   }
 }
 
@@ -1362,11 +1355,15 @@ extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
 
 extern "C" void LLVMRustSetModuleCodeModel(LLVMModuleRef M,
                                            LLVMRustCodeModel Model) {
+#if LLVM_VERSION_GE(9, 0)
   auto CM = fromRust(Model);
   if (!CM.hasValue())
     return;
-#if LLVM_VERSION_GE(9, 0)
   unwrap(M)->setCodeModel(*CM);
+#else
+  // No-op
+  (void)M;
+  (void)Model;
 #endif
 }
 
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index 786c5b8e169..5cacc1d02f3 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -327,7 +327,6 @@ fn to_json(&self) -> Json {
 
 #[derive(Clone, Copy, PartialEq, Hash, Debug)]
 pub enum CodeModel {
-    Tiny,
     Small,
     Kernel,
     Medium,
@@ -339,7 +338,6 @@ impl FromStr for CodeModel {
 
     fn from_str(s: &str) -> Result<CodeModel, ()> {
         Ok(match s {
-            "tiny" => CodeModel::Tiny,
             "small" => CodeModel::Small,
             "kernel" => CodeModel::Kernel,
             "medium" => CodeModel::Medium,
@@ -352,7 +350,6 @@ fn from_str(s: &str) -> Result<CodeModel, ()> {
 impl ToJson for CodeModel {
     fn to_json(&self) -> Json {
         match *self {
-            CodeModel::Tiny => "tiny",
             CodeModel::Small => "small",
             CodeModel::Kernel => "kernel",
             CodeModel::Medium => "medium",
diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md
index 05384117ac1..d6774322611 100644
--- a/src/doc/rustc/src/codegen-options/index.md
+++ b/src/doc/rustc/src/codegen-options/index.md
@@ -21,7 +21,6 @@ specification.
 
 Supported values for this option are:
 
-- `tiny` - Tiny code model.
 - `small` - Small code model. This is the default model for majority of supported targets.
 - `kernel` - Kernel code model.
 - `medium` - Medium code model.


--- a/vendor/rustc-ap-rustc_target/src/spec/mod.rs	2021-07-26 23:20:39.000000000 +0800
+++ b/vendor/rustc-ap-rustc_target/src/spec/mod.rs	2025-12-18 03:53:27.000000000 +0800
@@ -324,7 +324,6 @@
 
 #[derive(Clone, Copy, PartialEq, Hash, Debug)]
 pub enum CodeModel {
-    Tiny,
     Small,
     Kernel,
     Medium,
@@ -336,7 +335,6 @@
 
     fn from_str(s: &str) -> Result<CodeModel, ()> {
         Ok(match s {
-            "tiny" => CodeModel::Tiny,
             "small" => CodeModel::Small,
             "kernel" => CodeModel::Kernel,
             "medium" => CodeModel::Medium,
@@ -349,7 +347,6 @@
 impl ToJson for CodeModel {
     fn to_json(&self) -> Json {
         match *self {
-            CodeModel::Tiny => "tiny",
             CodeModel::Small => "small",
             CodeModel::Kernel => "kernel",
             CodeModel::Medium => "medium",
