about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorCharisee <chiw@google.com>2023-05-05 18:32:20 +0000
committerCharisee <chiw@google.com>2023-05-05 18:32:20 +0000
commit68a5bb4de153565d93e084904154439777ad5c31 (patch)
treeaa05ae9255cb8ee24f85bf544478dbc454bbfcc6 /compiler/rustc_codegen_ssa/src
parentcb4f8153d8285ac2bf2145c569c09014f3ba317d (diff)
Add GNU Property Note
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/metadata.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs
index baf674cf9eb..d4515a794ee 100644
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -98,6 +98,7 @@ fn add_gnu_property_note(
     file: &mut write::Object<'static>,
     architecture: Architecture,
     binary_format: BinaryFormat,
+    endianness: Endianness,
 ) {
     // check bti protection
     if binary_format != BinaryFormat::Elf
@@ -115,12 +116,12 @@ fn add_gnu_property_note(
     let n_namsz: u32 = 4; // Size of the n_name field
     let n_descsz: u32 = 16; // Size of the n_desc field
     let n_type: u32 = NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor
-    let values = [n_namsz, n_descsz, n_type];
-    values.map(|v| data.extend_from_slice(&(v.to_le_bytes())));
-    data.push(b'G'); // Owner of the program property note
-    data.push(b'N');
-    data.push(b'U');
-    data.push(0);
+    let header_values = [n_namsz, n_descsz, n_type];
+    match endianness {
+        Endianness::Little => header_values.map(|v| data.extend_from_slice(&(v.to_le_bytes()))),
+        Endianness::Big => header_values.map(|v| data.extend_from_slice(&(v.to_be_bytes()))),
+    };
+    data.extend_from_slice(b"GNU\0"); // Owner of the program property note
     let pr_type: u32 = match architecture {
         Architecture::X86_64 => 0xc0000002,
         Architecture::Aarch64 => 0xc0000000,
@@ -128,10 +129,13 @@ fn add_gnu_property_note(
     };
     let pr_datasz: u32 = 4; //size of the pr_data field
     let pr_data: u32 = 3; //program property descriptor
-    let pr_padding: u32 = 3;
-    let values = [pr_type, pr_datasz, pr_data, pr_padding];
-    values.map(|v| data.extend_from_slice(&(v.to_le_bytes())));
-    file.append_section_data(section, &data, 4);
+    let pr_padding: u32 = 0;
+    let property_values = [pr_type, pr_datasz, pr_data, pr_padding];
+    match endianness {
+        Endianness::Little => property_values.map(|v| data.extend_from_slice(&(v.to_le_bytes()))),
+        Endianness::Big => property_values.map(|v| data.extend_from_slice(&(v.to_be_bytes()))),
+    };
+    file.append_section_data(section, &data, 8);
 }
 
 pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {
@@ -246,7 +250,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
         _ => elf::ELFOSABI_NONE,
     };
     let abi_version = 0;
-    add_gnu_property_note(&mut file, architecture, binary_format);
+    add_gnu_property_note(&mut file, architecture, binary_format, endianness);
     file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
     Some(file)
 }