Skip to main content

userspace/file/format/elf/section/header/
special.rs

1extern crate alloc;
2
3pub enum SpecialName {
4    Fixed(&'static str),
5    RelPrefix,  // apenas o prefixo ".rel"
6    RelaPrefix, // apenas o prefixo ".rela"
7}
8
9impl SpecialName {
10    /// Gera o nome completo combinando com o alvo fornecido
11    pub fn generate(&self, target: &str) -> alloc::string::String {
12        match self {
13            SpecialName::Fixed(s) => (*s).into(),
14            SpecialName::RelPrefix => [".rel", target].concat().into(),
15            SpecialName::RelaPrefix => [".rela", target].concat().into(),
16        }
17    }
18}
19
20pub struct Special {
21    pub name: SpecialName,
22    pub types: &'static [super::Type],
23    pub flags: &'static [super::Flag],
24}
25
26#[rustfmt::skip]
27pub const SPECIALS: &'static [Special] = &[
28    Special { name: SpecialName::Fixed(".bss"),           types : &[super::Type::Nobits],       flags : &[super::Flag::Alloc, super::Flag::Write]},
29    Special { name: SpecialName::Fixed(".comment"),       types : &[super::Type::Progbits],     flags : &[] },
30    Special { name: SpecialName::Fixed(".data"),          types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Write] },
31    Special { name: SpecialName::Fixed(".data1"),         types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Write] },
32    Special { name: SpecialName::Fixed(".debug"),         types : &[super::Type::Progbits],     flags : &[] },
33    Special { name: SpecialName::Fixed(".dynamic"),       types : &[super::Type::Dynamic],      flags : &[] }, //super::Flag::Below
34    Special { name: SpecialName::Fixed(".dynstr"),        types : &[super::Type::Strtab],       flags : &[super::Flag::Alloc] },
35    Special { name: SpecialName::Fixed(".dynsym"),        types : &[super::Type::Dynsym],       flags : &[super::Flag::Alloc] },
36    Special { name: SpecialName::Fixed(".fini"),          types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Execinstr] },
37    Special { name: SpecialName::Fixed(".fini_array"),    types : &[super::Type::FiniArray],    flags : &[super::Flag::Alloc, super::Flag::Write] },
38    Special { name: SpecialName::Fixed(".got"),           types : &[super::Type::Progbits],     flags : &[] }, //super::Flag::Below
39    Special { name: SpecialName::Fixed(".hash"),          types : &[super::Type::Hash],         flags : &[super::Flag::Alloc] },
40    Special { name: SpecialName::Fixed(".init"),          types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Execinstr] },
41    Special { name: SpecialName::Fixed(".init_array"),    types : &[super::Type::InitArray],    flags : &[super::Flag::Alloc, super::Flag::Write] },
42    Special { name: SpecialName::Fixed(".interp"),        types : &[super::Type::Progbits],     flags : &[] }, //super::Flag::Below
43    Special { name: SpecialName::Fixed(".line"),          types : &[super::Type::Progbits],     flags : &[] },
44    Special { name: SpecialName::Fixed(".note"),          types : &[super::Type::Note],         flags : &[] },
45    Special { name: SpecialName::Fixed(".plt"),           types : &[super::Type::Progbits],     flags : &[] }, //super::Flag::Below
46    Special { name: SpecialName::Fixed(".preinit_array"), types : &[super::Type::PreinitArray], flags : &[super::Flag::Alloc, super::Flag::Write] },
47    Special { name: SpecialName::RelPrefix,               types : &[super::Type::Rel],          flags : &[] }, //super::Flag::Below
48    Special { name: SpecialName::RelaPrefix,              types : &[super::Type::Rela],         flags : &[] }, //super::Flag::Below
49    Special { name: SpecialName::Fixed(".relr.dyn"),      types : &[super::Type::Relr],         flags : &[super::Flag::Alloc] },
50    Special { name: SpecialName::Fixed(".rodata"),        types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc] },
51    Special { name: SpecialName::Fixed(".rodata1"),       types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc] },
52    Special { name: SpecialName::Fixed(".shstrtab"),      types : &[super::Type::Strtab],       flags : &[] },
53    Special { name: SpecialName::Fixed(".strtab"),        types : &[super::Type::Strtab],       flags : &[] }, //super::Flag::Below
54    Special { name: SpecialName::Fixed(".symtab"),        types : &[super::Type::Symtab],       flags : &[] }, //super::Flag::Below
55    Special { name: SpecialName::Fixed(".symtab_shndx"),  types : &[super::Type::SymtabShndx],  flags : &[] }, //super::Flag::Below
56    Special { name: SpecialName::Fixed(".tbss"),          types : &[super::Type::Nobits],       flags : &[super::Flag::Alloc, super::Flag::Write, super::Flag::Tls] },
57    Special { name: SpecialName::Fixed(".tdata"),         types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Write, super::Flag::Tls] },
58    Special { name: SpecialName::Fixed(".tdata1"),        types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Write, super::Flag::Tls] },
59    Special { name: SpecialName::Fixed(".text"),          types : &[super::Type::Progbits],     flags : &[super::Flag::Alloc, super::Flag::Execinstr] },
60];
61
62// pub fn get_special(header: &super::Header64, shstrtab: &[u8]) -> Option<&'static Special> {
63//     let sh_name = header_name(header, shstrtab);
64
65//     let Some(sh_type) = header.r#type() else {
66//         return None;
67//     };
68
69//     let Some(sh_flags) = header.flags() else {
70//         return None;
71//     };
72
73//     for special in SPECIALS {
74//         if !match &special.name {
75//             SpecialName::Fixed(s) => s == &sh_name,
76//             SpecialName::RelPrefix => sh_name.starts_with(".rel"),
77//             SpecialName::RelaPrefix => sh_name.starts_with(".rela"),
78//         } {
79//             continue;
80//         }
81
82//         for r#type in special.types.iter() {
83//             if !(sh_type && r#type) {
84//                 continue;
85//             };
86//         }
87
88//         for flag in special.flags.iter() {
89//             if !(sh_flags && *flag) {
90//                 continue;
91//             };
92//         }
93
94//         return Some(special);
95//     }
96//     None
97// }
98
99// .sdata
100// .tdesc
101// .sbss
102// .lit4
103// .lit8
104// .reginfo
105// .gptab
106// .liblist
107// .conflict